【发布时间】:2021-11-14 00:29:21
【问题描述】:
我有一个 ASP Net Core API,我想在其中调用 Graph API。我这样配置身份验证:
services.AddMicrosoftIdentityWebApiAuthentication(Configuration, configSectionName: Constants.AzureAdB2C)
.EnableTokenAcquisitionToCallDownstreamApi(options => Configuration.Bind(Constants.AzureAdB2C, options))
.AddMicrosoftGraph(Configuration.GetSection("GraphAPI"))
.AddInMemoryTokenCaches();
我的appsettings.json 文件具有以下属性:
{
"AzureAdB2C": {
"Instance": "https://tenantName.b2clogin.com/",
"Domain": "tenantName.onmicrosoft.com",
"TenantId": "tenantId",
"ClientId": "appId",
"ClientSecret": "appSecret",
"SignUpSignInPolicyId": "B2C_1_SignUpSignIn",
"ResetPasswordPolicyId": "B2C_1_PasswordReset"
},
"GraphAPI": {
"BaseUrl": "https://graph.microsoft.com/v1.0",
"Scopes": "User.Read Directory.ReadWrite.All"
}
}
我的b2c app 被授予这些Graph 范围的权限。
我创建了一个端点:
[HttpGet]
[Route("me")]
public Task<User> Me()
{
return this.graphServiceClient.Me.Request().GetAsync();
}
这是我得到这个错误的地方:
ErrorCode: unsupported_grant_type
Microsoft.Identity.Client.MsalServiceException: AADB2C90086: The supplied grant_type [urn:ietf:params:oauth:grant-type:jwt-bearer] is not supported.
为什么我的 API 不能调用 GraphAPI?我看到的所有样本都使用了services.AddMicrosoftIdentityWebAppAuthentication...。会不会是这个原因?
【问题讨论】:
标签: azure-active-directory asp.net-core-webapi azure-ad-b2c azure-ad-graph-api