Search code examples
asp.net-corerestful-authentication

ASP Core 2.0 app.UseJwtBearerAuthentication fails


I have developed a web application using dot net core 1.1. It was working fine till I've updated to asp core 2.0. Then when trying to use the application, it reports this error:

InvalidOperationException: No authenticationScheme was specified, and there was no DefaultChallengeScheme found.

The authentication config of JwtBearerAuthentication, in the Configure method of Startup.cs was previously like bellow:

app.UseJwtBearerAuthentication(new JwtBearerOptions
            {
                AutomaticAuthenticate = true,
                AutomaticChallenge = true,
                TokenValidationParameters = tokenValidationParameters
            });

After facing this error I have updated that to this one:

app.UseJwtBearerAuthentication(new JwtBearerOptions
        {
            AutomaticAuthenticate = true,
            AutomaticChallenge = true,
            TokenValidationParameters = tokenValidationParameters,
            AuthenticationScheme = JwtBearerDefaults.AuthenticationScheme
        });

But still the error message is alive. Am I looking wrong place for the error or I have have to add additional configurations for the authentication system to work?


Solution

  • I've just followed this article and everything goes perfect.

    Migrating Authentication and Identity to ASP.NET Core 2.0

    Hope it helps other.

    TG.