【发布时间】:2020-09-03 03:30:46
【问题描述】:
所以我使用 ASP Net Core 构建了一个应用程序。 这是我的代码
services.AddAuthentication(AzureADDefaults.JwtBearerAuthenticationScheme)
.AddAzureADBearer(options => Configuration.Bind("AzureAd", options));
services.Configure<JwtBearerOptions>(AzureADDefaults.JwtBearerAuthenticationScheme, options =>
{
// This is a Microsoft identity platform web API.
options.Authority += "/v2.0";
// The web API accepts as audiences both the Client ID (options.Audience) and api://{ClientID}.
options.TokenValidationParameters.ValidAudiences = new[]
{
options.Audience,
$"api://{options.Audience}"
};
});
当我使用用户密码验证时,此设置工作正常。但是由于某些情况,我只能将 client_credentials 用于我的其他应用程序。我正在使用它来获取令牌 我成功获得了令牌,但是当我使用令牌时,它让我未经授权
【问题讨论】:
-
请将“范围”改为:api://{ClientID}/.default
-
嗨@CarlZhao,我在更改范围时收到此错误 AADSTS500011:在名为 {{tenantId}} 的租户中找不到名为 api://{clientId} 的资源主体。我应该在这里添加什么?
-
嗨,请查看我的更新答案。
标签: c# asp.net-core active-directory azure-active-directory