From 8bcd415822b31d9617e41c185a4712ffeb9ce4b5 Mon Sep 17 00:00:00 2001 From: maliming Date: Tue, 9 Mar 2021 18:00:14 +0800 Subject: [PATCH 1/2] Set RedirectUri property of AuthenticationProperties. --- .../ChallengeAccountController.cs | 24 +++++-------------- 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Authentication/ChallengeAccountController.cs b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Authentication/ChallengeAccountController.cs index d01bac2e81..0283a22046 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Authentication/ChallengeAccountController.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Authentication/ChallengeAccountController.cs @@ -23,20 +23,8 @@ namespace Volo.Abp.AspNetCore.Mvc.Authentication { return RedirectSafely(returnUrl, returnUrlHash); } - else - { - return Challenge( - new AuthenticationProperties - { - Parameters = - { - {"returnUrl", returnUrl}, - {"returnUrlHash", returnUrlHash} - } - }, - ChallengeAuthenticationSchemas - ); - } + + return Challenge(new AuthenticationProperties {RedirectUri = returnUrl}, ChallengeAuthenticationSchemas); } [HttpGet] @@ -44,20 +32,20 @@ namespace Volo.Abp.AspNetCore.Mvc.Authentication { await HttpContext.SignOutAsync(); - if (HttpContext.User.Identity.AuthenticationType == AuthenticationType) + if (HttpContext.User.Identity?.AuthenticationType == AuthenticationType) { return RedirectSafely(returnUrl, returnUrlHash); } - return new SignOutResult(ChallengeAuthenticationSchemas); + return SignOut(new AuthenticationProperties {RedirectUri = returnUrl}, ChallengeAuthenticationSchemas); } [HttpGet] public async Task FrontChannelLogout(string sid) { - if (User.Identity.IsAuthenticated) + if (User.Identity != null && User.Identity.IsAuthenticated) { - var currentSid = User.FindFirst("sid").Value ?? string.Empty; + var currentSid = User.FindFirst("sid")?.Value ?? string.Empty; if (string.Equals(currentSid, sid, StringComparison.Ordinal)) { await Logout(); From 204e449eaa41b783a310cad4e16be67c3bc84b2a Mon Sep 17 00:00:00 2001 From: maliming Date: Wed, 10 Mar 2021 09:21:23 +0800 Subject: [PATCH 2/2] Add returnUrlHash to returnUrl. --- .../Volo/Abp/AspNetCore/Mvc/AbpController.cs | 6 +++--- .../Mvc/Authentication/ChallengeAccountController.cs | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpController.cs b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpController.cs index 85822414cf..dee3b3c492 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpController.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpController.cs @@ -108,12 +108,12 @@ namespace Volo.Abp.AspNetCore.Mvc return localizer; } - protected RedirectResult RedirectSafely(string returnUrl, string returnUrlHash = null) + protected virtual RedirectResult RedirectSafely(string returnUrl, string returnUrlHash = null) { return Redirect(GetRedirectUrl(returnUrl, returnUrlHash)); } - private string GetRedirectUrl(string returnUrl, string returnUrlHash = null) + protected virtual string GetRedirectUrl(string returnUrl, string returnUrlHash = null) { returnUrl = NormalizeReturnUrl(returnUrl); @@ -125,7 +125,7 @@ namespace Volo.Abp.AspNetCore.Mvc return returnUrl; } - private string NormalizeReturnUrl(string returnUrl) + protected virtual string NormalizeReturnUrl(string returnUrl) { if (returnUrl.IsNullOrEmpty()) { diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Authentication/ChallengeAccountController.cs b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Authentication/ChallengeAccountController.cs index 0283a22046..944b9ef0ee 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Authentication/ChallengeAccountController.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Authentication/ChallengeAccountController.cs @@ -24,7 +24,7 @@ namespace Volo.Abp.AspNetCore.Mvc.Authentication return RedirectSafely(returnUrl, returnUrlHash); } - return Challenge(new AuthenticationProperties {RedirectUri = returnUrl}, ChallengeAuthenticationSchemas); + return Challenge(new AuthenticationProperties {RedirectUri = GetRedirectUrl(returnUrl, returnUrlHash)}, ChallengeAuthenticationSchemas); } [HttpGet] @@ -37,7 +37,7 @@ namespace Volo.Abp.AspNetCore.Mvc.Authentication return RedirectSafely(returnUrl, returnUrlHash); } - return SignOut(new AuthenticationProperties {RedirectUri = returnUrl}, ChallengeAuthenticationSchemas); + return SignOut(new AuthenticationProperties {RedirectUri = GetRedirectUrl(returnUrl, returnUrlHash)}, ChallengeAuthenticationSchemas); } [HttpGet]