Aspnetcore.docs: no authentication scheme is specified when default is not specified

Created on 14 Nov 2019  Â·  7Comments  Â·  Source: dotnet/AspNetCore.Docs

doc says we can have parameterless AddAuthentication() but for me it's running to no default specified error.

InvalidOperationException: No authenticationScheme was specified, and there was no DefaultAuthenticateScheme found. The default schemes can be set using either AddAuthentication(string defaultScheme) or AddAuthentication(Action<AuthenticationOptions> configureOptions).

Document Details

⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

Security-PU Source - Docs.ms doc-enhancement

Most helpful comment

If you don't specify a default authentication scheme, you cannot have an [Authorize] attribute that doesn't specfiy a scheme.

All 7 comments

The first sample is parameterless

public void ConfigureServices(IServiceCollection services)
{
    // Code omitted for brevity

    services.AddAuthentication()
        .AddCookie(options => {
            options.LoginPath = "/Account/Unauthorized/";
            options.AccessDeniedPath = "/Account/Forbidden/";
        })
        .AddJwtBearer(options => {
            options.Audience = "http://localhost:5001/";
            options.Authority = "http://localhost:5000/";
        });

Specifying the default scheme results in the HttpContext.User property being set to that identity. If that behavior isn't desired, disable it by invoking the parameterless form of AddAuthentication.

when it is left parameters I am running into this error I have mentioned in the question

InvalidOperationException: No authenticationScheme was specified, and there was no DefaultAuthenticateScheme found. The default schemes can be set using either AddAuthentication(string defaultScheme) or AddAuthentication(Action<AuthenticationOptions> configureOptions).

do you have a working sample that I can run to verify it?

I'm also having this problem. Any Ideas?

Moved to Master issue for: Authorize with a specific scheme #16190

If you don't specify a default authentication scheme, you cannot have an [Authorize] attribute that doesn't specfiy a scheme.

Thanks for contacting us. We believe that the question you've raised have been answered. If you still feel a need to continue the discussion, feel free to reopen it and add your comments.

Was this page helpful?
0 / 5 - 0 ratings