How to set multiple audiences in Asp.Net Core 2.0 “AddJwtBearer” middleware?

前端 未结 1 1982
猫巷女王i
猫巷女王i 2021-02-03 22:28

I have an Asp.Net Core 2.0 WebApi which is authenticating against AAD:

            services.AddAuthentication(options => { options.DefaultScheme = JwtBearerDe         


        
相关标签:
1条回答
  • 2021-02-03 22:36

    I think I ran into the same problem as you. To make it work I moved audience from options and into the TokenValidationParameters, which accepts multiple entries. Check the code below:

    .AddJwtBearer(options =>
    {
        options.Authority = "https://login.windows.net/trades.no";
        options.TokenValidationParameters = new Microsoft.IdentityModel.Tokens.TokenValidationParameters
        {
            ValidateIssuer = true,
            ValidAudiences = new List<string> 
            {
                "AUDIENCE1",
                "AUDIENCE2" 
            }
        };
    
    0 讨论(0)
提交回复
热议问题