Skip to content

Commit

Permalink
Merge pull request #7297 from abpframework/maliming/security-logs-cli…
Browse files Browse the repository at this point in the history
…etnid

Save the client id for Authorization Code Grant.
  • Loading branch information
realLiangshiwei committed Jan 18, 2021
2 parents 9d10542 + 9f7e6d9 commit 1771d34
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@ public override async Task<IActionResult> OnGetAsync()

public override async Task<IActionResult> OnPostAsync(string action)
{
var context = await Interaction.GetAuthorizationContextAsync(ReturnUrl);
if (action == "Cancel")
{
var context = await Interaction.GetAuthorizationContextAsync(ReturnUrl);
if (context == null)
{
return Redirect("~/");
Expand Down Expand Up @@ -142,7 +142,8 @@ await IdentitySecurityLogManager.SaveAsync(new IdentitySecurityLogContext()
{
Identity = IdentitySecurityLogIdentityConsts.Identity,
Action = result.ToIdentitySecurityLogAction(),
UserName = LoginInput.UserNameOrEmailAddress
UserName = LoginInput.UserNameOrEmailAddress,
ClientId = context?.Client?.ClientId
});

if (result.RequiresTwoFactor)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,21 @@ public IdentityServerSupportedLogoutModel(IIdentityServerInteractionService inte

public async override Task<IActionResult> OnGetAsync()
{
await IdentitySecurityLogManager.SaveAsync(new IdentitySecurityLogContext()
{
Identity = IdentitySecurityLogIdentityConsts.Identity,
Action = IdentitySecurityLogActionConsts.Logout
});

await SignInManager.SignOutAsync();

var logoutId = Request.Query["logoutId"].ToString();

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,
Expand All @@ -49,6 +46,8 @@ await IdentitySecurityLogManager.SaveAsync(new IdentitySecurityLogContext()
return RedirectToPage("./LoggedOut", vm);
}

await SaveSecurityLogAsync();

if (ReturnUrl != null)
{
return LocalRedirect(ReturnUrl);
Expand All @@ -58,5 +57,18 @@ await IdentitySecurityLogManager.SaveAsync(new IdentitySecurityLogContext()
$"IdentityServerSupportedLogoutModel couldn't find postLogoutUri... Redirecting to:/Account/Login..");
return RedirectToPage("/Account/Login");
}

protected virtual async Task SaveSecurityLogAsync(string clientId = null)
{
if (CurrentUser.IsAuthenticated)
{
await IdentitySecurityLogManager.SaveAsync(new IdentitySecurityLogContext()
{
Identity = IdentitySecurityLogIdentityConsts.Identity,
Action = IdentitySecurityLogActionConsts.Logout,
ClientId = clientId
});
}
}
}
}

0 comments on commit 1771d34

Please sign in to comment.