Microsoft Identity OIDC:受众“00000002-0000-0000-c000-000000000000”无效

时间:2021-03-10 09:24:27

标签: .net-core microsoft-graph-api asp.net-apicontroller microsoft-identity-web

相信我,我尝试了所有可能的选项,阅读了所有关于 stack-overflow 的帖子,没有任何效果。

我正在使用带有 oauth2 的 swagger UI。我点击执行,总是得到相同的响应。

带有 401 的错误消息:www-authenticate: Bearer error="invalid_token"error_description="观众 '00000002-0000-0000-c000-000000000000' 无效"

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" }
                        }
                    }
                 }
              });
         });
      }

请帮我解决这个问题。

我可以使用身份验证流程成功登录到swagger;令牌生成。

当我将该令牌粘贴到 https://jwt.io 中时,

它向我显示 aud 的值为 '00000002-0000-0000-c000-000000000000'。

请帮我解决这个问题。我在 azure 广告方面做错了什么,或者后端 api 方面缺少什么。

0 个答案:

没有答案
相关问题