DuendeSoftware / Support

Support for Duende Software products
21 stars 0 forks source link

Razor Pages Logout user in OnGet() causes Form Post HTTP 400 #1339

Closed MikeOtown closed 3 months ago

MikeOtown commented 3 months ago

Which version of Duende IdentityServer are you using? 7.0.5

Which version of .NET are you using? 8

Describe the bug

On a MFA Code entry page, I am logging out the user so if they navigate away they will not be logged in.

 public async Task<IActionResult> OnGet()
 {
     var user = HttpContext.User.Identity as ClaimsIdentity;
     if (user == null)
     {
         return Page();
     }

     var claim = user.Claims.FirstOrDefault(c => c.Type == "name");
     if (claim == null)
     {
         return Page();
     }
     string userName = claim.Value;

     if (String.IsNullOrWhiteSpace(userName))
     {
         return Page();
     }

     UserName = userName;

     // Log them out in case they navigate away           

     await _signInManager.SignOutAsync();

     // raise the logout event
     await _events.RaiseAsync(new UserLogoutSuccessEvent(user.GetSubjectId(), userName));

     return Page();

 }

But then when they POST the FORM I get HTTP 400.

See attached HAR file. chromewebdata.har.txt

RolandGuijt commented 3 months ago

Unfortunately this question doesn't have a direct relationship with any of the Duende products. Please ask this question in the ASP.NET Core and ASP.NET Core Identity issue trackers. Having said that: to see an example on how MFA is done, scaffold out the corresponding pages in ASP.NET Core Identity and study the code of these.