From c3ba4b637a32514b5727726e2f85ad6779d1e184 Mon Sep 17 00:00:00 2001 From: maliming Date: Mon, 18 Jan 2021 15:26:33 +0800 Subject: [PATCH 1/2] Save the client id for Authorization Code Grant. Resolve #7274 --- .../IdentityServerSupportedLoginModel.cs | 5 ++-- .../IdentityServerSupportedLogoutModel.cs | 23 +++++++++++++------ 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/modules/account/src/Volo.Abp.Account.Web.IdentityServer/Pages/Account/IdentityServerSupportedLoginModel.cs b/modules/account/src/Volo.Abp.Account.Web.IdentityServer/Pages/Account/IdentityServerSupportedLoginModel.cs index 3d7381d2c3..4dab1f9761 100644 --- a/modules/account/src/Volo.Abp.Account.Web.IdentityServer/Pages/Account/IdentityServerSupportedLoginModel.cs +++ b/modules/account/src/Volo.Abp.Account.Web.IdentityServer/Pages/Account/IdentityServerSupportedLoginModel.cs @@ -103,9 +103,9 @@ namespace Volo.Abp.Account.Web.Pages.Account public override async Task OnPostAsync(string action) { + var context = await Interaction.GetAuthorizationContextAsync(ReturnUrl); if (action == "Cancel") { - var context = await Interaction.GetAuthorizationContextAsync(ReturnUrl); if (context == null) { return Redirect("~/"); @@ -142,7 +142,8 @@ namespace Volo.Abp.Account.Web.Pages.Account { Identity = IdentitySecurityLogIdentityConsts.Identity, Action = result.ToIdentitySecurityLogAction(), - UserName = LoginInput.UserNameOrEmailAddress + UserName = LoginInput.UserNameOrEmailAddress, + ClientId = context?.Client?.ClientId }); if (result.RequiresTwoFactor) diff --git a/modules/account/src/Volo.Abp.Account.Web.IdentityServer/Pages/Account/IdentityServerSupportedLogoutModel.cs b/modules/account/src/Volo.Abp.Account.Web.IdentityServer/Pages/Account/IdentityServerSupportedLogoutModel.cs index 26ee0d4c34..0045353b49 100644 --- a/modules/account/src/Volo.Abp.Account.Web.IdentityServer/Pages/Account/IdentityServerSupportedLogoutModel.cs +++ b/modules/account/src/Volo.Abp.Account.Web.IdentityServer/Pages/Account/IdentityServerSupportedLogoutModel.cs @@ -20,12 +20,6 @@ namespace Volo.Abp.Account.Web.Pages.Account public async override Task OnGetAsync() { - await IdentitySecurityLogManager.SaveAsync(new IdentitySecurityLogContext() - { - Identity = IdentitySecurityLogIdentityConsts.Identity, - Action = IdentitySecurityLogActionConsts.Logout - }); - await SignInManager.SignOutAsync(); var logoutId = Request.Query["logoutId"].ToString(); @@ -33,11 +27,14 @@ namespace Volo.Abp.Account.Web.Pages.Account if (!string.IsNullOrEmpty(logoutId)) { var logoutContext = await Interaction.GetLogoutContextAsync(logoutId); + + await SaveSecurityLogAsync(logoutContext?.ClientId); + await SignInManager.SignOutAsync(); HttpContext.User = new ClaimsPrincipal(new ClaimsIdentity()); - LoggedOutModel vm = new LoggedOutModel() + var vm = new LoggedOutModel() { PostLogoutRedirectUri = logoutContext?.PostLogoutRedirectUri, ClientName = logoutContext?.ClientName, @@ -49,6 +46,8 @@ namespace Volo.Abp.Account.Web.Pages.Account return RedirectToPage("./LoggedOut", vm); } + await SaveSecurityLogAsync(); + if (ReturnUrl != null) { return LocalRedirect(ReturnUrl); @@ -58,5 +57,15 @@ namespace Volo.Abp.Account.Web.Pages.Account $"IdentityServerSupportedLogoutModel couldn't find postLogoutUri... Redirecting to:/Account/Login.."); return RedirectToPage("/Account/Login"); } + + protected virtual async Task SaveSecurityLogAsync(string clientId = null) + { + await IdentitySecurityLogManager.SaveAsync(new IdentitySecurityLogContext() + { + Identity = IdentitySecurityLogIdentityConsts.Identity, + Action = IdentitySecurityLogActionConsts.Logout, + ClientId = clientId + }); + } } } From 9f7e6d9b4483ba9758cf79c7600856afe9546b17 Mon Sep 17 00:00:00 2001 From: maliming Date: Mon, 18 Jan 2021 15:35:32 +0800 Subject: [PATCH 2/2] Save when CurrentUser.IsAuthenticated --- .../Account/IdentityServerSupportedLogoutModel.cs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/modules/account/src/Volo.Abp.Account.Web.IdentityServer/Pages/Account/IdentityServerSupportedLogoutModel.cs b/modules/account/src/Volo.Abp.Account.Web.IdentityServer/Pages/Account/IdentityServerSupportedLogoutModel.cs index 0045353b49..94860e80c1 100644 --- a/modules/account/src/Volo.Abp.Account.Web.IdentityServer/Pages/Account/IdentityServerSupportedLogoutModel.cs +++ b/modules/account/src/Volo.Abp.Account.Web.IdentityServer/Pages/Account/IdentityServerSupportedLogoutModel.cs @@ -60,12 +60,15 @@ namespace Volo.Abp.Account.Web.Pages.Account protected virtual async Task SaveSecurityLogAsync(string clientId = null) { - await IdentitySecurityLogManager.SaveAsync(new IdentitySecurityLogContext() + if (CurrentUser.IsAuthenticated) { - Identity = IdentitySecurityLogIdentityConsts.Identity, - Action = IdentitySecurityLogActionConsts.Logout, - ClientId = clientId - }); + await IdentitySecurityLogManager.SaveAsync(new IdentitySecurityLogContext() + { + Identity = IdentitySecurityLogIdentityConsts.Identity, + Action = IdentitySecurityLogActionConsts.Logout, + ClientId = clientId + }); + } } } }