Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V13 RC: Fix regression for external login providers #15334

Merged
merged 5 commits into from
Dec 1, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 26 additions & 18 deletions src/Umbraco.Web.BackOffice/Controllers/BackOfficeController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Microsoft.Extensions.Primitives;
using Umbraco.Cms.Core;
using Umbraco.Cms.Core.Cache;
using Umbraco.Cms.Core.Configuration.Grid;
using Umbraco.Cms.Core.Configuration.Models;
using Umbraco.Cms.Core.Hosting;
using Umbraco.Cms.Core.Manifest;
using Umbraco.Cms.Core.Models;
using Umbraco.Cms.Core.Security;
using Umbraco.Cms.Core.Serialization;
using Umbraco.Cms.Core.Services;
Expand Down Expand Up @@ -145,7 +145,6 @@ public async Task<IActionResult> Default()

return await RenderDefaultOrProcessExternalLoginAsync(
result,
() => defaultView,
() => defaultView);
}

Expand All @@ -172,7 +171,6 @@ public async Task<IActionResult> Login()

return await RenderDefaultOrProcessExternalLoginAsync(
result,
() => View(viewPath),
() => View(viewPath));
}

Expand Down Expand Up @@ -460,11 +458,9 @@ public async Task<IActionResult> ExternalLinkLoginCallback()
/// <returns></returns>
private async Task<IActionResult> RenderDefaultOrProcessExternalLoginAsync(
AuthenticateResult authenticateResult,
Func<IActionResult> defaultResponse,
Func<IActionResult> externalSignInResponse)
Func<IActionResult> defaultResponse)
{
ArgumentNullException.ThrowIfNull(defaultResponse);
ArgumentNullException.ThrowIfNull(externalSignInResponse);

ViewData.SetUmbracoPath(_globalSettings.GetUmbracoMvcArea(_hostingEnvironment));

Expand All @@ -481,23 +477,35 @@ private async Task<IActionResult> RenderDefaultOrProcessExternalLoginAsync(
// First check if there's external login info, if there's not proceed as normal
ExternalLoginInfo? loginInfo = await _signInManager.GetExternalLoginInfoAsync();

if (loginInfo == null || loginInfo.Principal == null)
if (loginInfo != null)
{
// if the user is not logged in, check if there's any auto login redirects specified
if (!authenticateResult.Succeeded)
{
var oauthRedirectAuthProvider = _externalLogins.GetAutoLoginProvider();
if (!oauthRedirectAuthProvider.IsNullOrWhiteSpace())
{
return ExternalLogin(oauthRedirectAuthProvider!);
}
}
// we're just logging in with an external source, not linking accounts
return await ExternalSignInAsync(loginInfo, defaultResponse);
}

// If we are authenticated then we can just render the default view
if (authenticateResult.Succeeded)
{
return defaultResponse();
}

// we're just logging in with an external source, not linking accounts
return await ExternalSignInAsync(loginInfo, externalSignInResponse);
// If the user is not logged in, check if there's any auto login redirects specified
var oauthRedirectAuthProvider = _externalLogins.GetAutoLoginProvider();

// If there's no auto login provider specified, then we'll render the default view
if (oauthRedirectAuthProvider.IsNullOrWhiteSpace())
{
return defaultResponse();
}

// If the ?logout=true query string is not specified, then we'll redirect to the external login provider
// which will then redirect back to the ExternalLoginCallback action
if (Request.Query.TryGetValue("logout", out StringValues logout) == false || logout != "true")
{
return ExternalLogin(oauthRedirectAuthProvider);
}

return defaultResponse();
}

private async Task<IActionResult> ExternalSignInAsync(ExternalLoginInfo loginInfo, Func<IActionResult> response)
Expand Down