Search code examples
c#authenticationasp.net-core.net-coreidentityserver4

ASP.NET Core 2 AuthenticationSchemes


There are several authentication schemes but I can't find any documentation on them. How do they differ?

options.DefaultScheme
options.DefaultChallengeScheme
options.DefaultForbidScheme
options.DefaultAuthenticateScheme
options.DefaultSignInScheme
options.DefaultSignOutScheme

Solution

  • From here

    • DefaultScheme: if specified, all the other defaults will fallback to this value
    • DefaultAuthenticateScheme: if specified, AuthenticateAsync() will use this scheme, and also the AuthenticationMiddleware added by UseAuthentication() will use this scheme to set context.User automatically. (Corresponds to AutomaticAuthentication)
    • DefaultChallengeScheme if specified, ChallengeAsync() will use this scheme, [Authorize] with policies that don't specify schemes will also use this
    • DefaultSignInScheme is used by SignInAsync() and also by all of the remote auth schemes like Google/Facebook/OIDC/OAuth, typically this would be set to a cookie.
    • DefaultSignOutScheme is used by SignOutAsync() falls back to DefaultSignInScheme
    • DefaultForbidScheme is used by ForbidAsync(), falls back to DefaultChallengeScheme

    So, you specify, which authentication scheme, is used in corresponding methods in IAuthenticationService