ASP Net Core API 对图的下游调用 API W/AADB2C
ASP Net Core API downstream call to Graph API W/ AADB2C
我有一个 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...
。会不会是这个原因?
不支持B2C代流:https://docs.microsoft.com/en-us/azure/active-directory-b2c/access-tokens.
Web API chains (On-Behalf-Of) is not supported by Azure AD B2C.
您需要使用应用程序权限获取令牌,因为您的应用程序具有客户端凭据流。
有一些关于此的文档:https://docs.microsoft.com/en-us/azure/active-directory-b2c/microsoft-graph-get-started?tabs=app-reg-ga#register-management-application。
该文档为此创建了一个单独的应用程序注册,但我认为您可以将应用程序权限添加到现有注册中。
我有一个 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...
。会不会是这个原因?
不支持B2C代流:https://docs.microsoft.com/en-us/azure/active-directory-b2c/access-tokens.
Web API chains (On-Behalf-Of) is not supported by Azure AD B2C.
您需要使用应用程序权限获取令牌,因为您的应用程序具有客户端凭据流。 有一些关于此的文档:https://docs.microsoft.com/en-us/azure/active-directory-b2c/microsoft-graph-get-started?tabs=app-reg-ga#register-management-application。 该文档为此创建了一个单独的应用程序注册,但我认为您可以将应用程序权限添加到现有注册中。