Re-challenge authenticated users in ASP.NET Core

前端 未结 2 1677
不思量自难忘°
不思量自难忘° 2021-02-15 21:55

I\'m running into some issues with the authentication pipeline in ASP.NET Core. My scenario is that I want to issue a challenge to a user who is already authenticated using Open

相关标签:
2条回答
  • 2021-02-15 22:42

    I found a hint and the solution here: https://github.com/aspnet/Security/issues/912. ChallengeBehavior.Unauthorized is the "key".

    This post gives the current (november 2016 - ASPNet 1.0.1) workaround: https://joonasw.net/view/azure-ad-b2c-with-aspnet-core

    You'll need a new ActionResult to be able to call the AuthauticationManager.ChallengeAsync with the ChallengeBehavior.Unauthorized behavior.

    Once the issue https://github.com/aspnet/Mvc/issues/5187 will be sucessfully closed, this should be integrated.

    I tested it and it worked perfectly well (my goal was simply to extend Google scopes on a per user basis).

    0 讨论(0)
  • 2021-02-15 22:47
    Try to sign out:
    
    public void RefreshSession()
    {
          HttpContext.Authentication.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme);
          HttpContext.Authentication.SignOutAsync(OpenIdConnectDefaults.AuthenticationScheme);
          HttpContext.Authentication.ChallengeAsync(OpenIdConnectDefaults.AuthenticationScheme, new AuthenticationProperties { RedirectUri = "/" });
    }
    
    0 讨论(0)
提交回复
热议问题