Upgrading Asp.Net Core 2.2 to 3.1 using Microsoft.Identity.Web - No authentication handler is registered for the scheme 'AzureADJwtBearer'

0

I'm in the process of updating an Asp.Net Core 2.2 application to 3.1.

We use Microsoft.Identity.Web to handle Azure AD authentication. I changed our security configuration as as follow:

ConfigureSerivces

services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
    .AddMicrosoftIdentityWebApi(configuration)
    .EnableTokenAcquisitionToCallDownstreamApi()
    .AddInMemoryTokenCaches();

services.AddAuthentication()
    .AddScheme<ApiKeyAuthenticationSchemeOptions, ApiKeyAuthenticationHandler
    (AuthenticationSchemes.ApiKey, null);

And Configure

app.UseRouting();
app.UseAuthentication();
app.UseAuthorization();
app.UseMiddleware<LogUsernameMiddleware>();
app.UseEndpoints(p =>
{
    p.MapControllers();
});

But is throwing the following exception

System.InvalidOperationException
  HResult=0x80131509
  Message=No authentication handler is registered for the scheme 'AzureADJwtBearer'. The registered schemes are: Bearer, ApiKey. Did you forget to call AddAuthentication().Add[SomeAuthHandler]("AzureADJwtBearer",...)?
  Source=Microsoft.AspNetCore.Authentication.Core
  StackTrace:
   at Microsoft.AspNetCore.Authentication.AuthenticationService.<AuthenticateAsync>d__13.MoveNext() in /_/src/Http/Authentication.Core/src/AuthenticationService.cs:line 67

Not sure what part is not registering the authentication/authorization settings.

Thank you,

asp.net-core
.net-core
msal
asked on Stack Overflow Nov 13, 2020 by Fernando • edited Nov 14, 2020 by Fernando

1 Answer

0

Problem was in our code, We were using a class with const string to return either ApiKey, AzureADJwtBearer or All as AuthenticationSchemes for controllers but AzureADJwtBearer as been replaced with just Bearer.

Thank you,

answered on Stack Overflow Nov 14, 2020 by Fernando

User contributions licensed under CC BY-SA 3.0