'Microsoft Identity OIDC: The audience '00000002-0000-0000-c000-000000000000' is invalid

Trust me I tried each possible option, read all posts on stack-overflow, nothing work.

I'm using swagger UI with oauth2. whem I'm clicking on execute, always getting same response.

Error message with 401: www-authenticate: Bearer error="invalid_token"error_description="The audience '00000002-0000-0000-c000-000000000000' is invalid"

public void ConfigureServices(IServiceCollection services)
{
    services.AddAuthentication(BeararAuth)
        .AddMicrosoftIdentityWebApi(Configuration)
        .EnableTokenAcquisitionToCallDownstreamApi()
        .AddInMemoryTokenCaches();

    services.AddSwaggerGen(c =>
    {
            c.OperationFilter<AuthorizeCheckOperationFilter>(Configuration["AzureAd:ClientId"]);
            c.SwaggerDoc("v1", new OpenApiInfo { Title = "WebApplication4", Version = "v1" });
            c.AddSecurityDefinition("oauth2", new OpenApiSecurityScheme
            {
                In = ParameterLocation.Header,
                Type = SecuritySchemeType.OAuth2,
                Flows = new OpenApiOAuthFlows
                {
                    AuthorizationCode = new OpenApiOAuthFlow
                    {
                        AuthorizationUrl = new Uri("https://login.microsoftonline.com/common/oauth2/authorize"),
                        TokenUrl = new Uri("https://login.microsoftonline.com/common/oauth2/token"),
                        Scopes = new Dictionary<string, string>
                        {
                          {"User.Read", "User Read scope"},
                          {"access_as_user", "access APIs as user" },
                          { $"api://{Configuration["AzureAd:ClientId"]}/access_as_user", "Application API Permissions" }
                        }
                    }
                 }
              });
         });
      }

Please help me on this.

I can successfully logged in to swagger using authentication flow; token is generated.

when I paste that token in https://jwt.io,

it shows me aud with value '00000002-0000-0000-c000-000000000000'.

Please help me to figure out this issue. is there anything wrong I'm doing at azure ad side or there is something is missing at backend api side.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source