【问题标题】:How to get Azure ActiveDirectory token for .Net Core Web Api Default Template?如何获取 .Net Core Web Api 默认模板的 Azure ActiveDirectory 令牌?
【发布时间】:2020-03-06 00:59:47
【问题描述】:

我已经使用 Visual Studio 2019 为 .net core web api 创建了默认模板。我选择使用默认的向导身份验证:

services.AddAuthentication(AzureADDefaults.BearerAuthenticationScheme)
                .AddAzureADBearer(options => Configuration.Bind("AzureAd", options));
            services.AddControllers();

我尝试使用 Postman 生成令牌(它给了我一个令牌,但返回未经授权的)。

我缺少哪些步骤?

在这一步,我要做的就是通过邮递员呼叫授权控制器。

【问题讨论】:

    标签: c# azure azure-active-directory asp-net-core-spa-services


    【解决方案1】:

    查看您使用 Postman 生成的令牌(使用 https://jwt.ms 或类似名称),看看它的受众(aud 声明)是否与 appSettings.json 的 AzureAD 部分中的内容完全相同(可能称为ApplicationId 那里)。可能还有其他声明未通过验证(尤其是发行人)并导致未经授权的退货,但我认为您的邮递员使用与您的 API 相同的目录。受众是最常见的错误原因。

    【讨论】:

      猜你喜欢
      • 2020-01-17
      • 2020-06-28
      • 2017-08-20
      • 1970-01-01
      • 1970-01-01
      • 2019-03-14
      • 2018-02-17
      • 2023-04-04
      • 1970-01-01
      相关资源
      最近更新 更多