【发布时间】:2021-10-23 18:50:43
【问题描述】:
我在尝试从已注册的 API 访问信息时收到此错误(Bearer error="invalid_token", error_description="The Audience 'xxxx-xxxx-xxxx-xxxx' is invalid"})。受众是 Azure ADB2C 中注册 API 的 clientId。我检查了访问令牌,它也与令牌的 aud 密钥具有相同的值。
我在托管 API 的应用中的启动配置如下:
services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
.AddMicrosoftIdentityWebApi(Configuration.GetSection("AzureAd"));
调用 API 的网络应用在启动配置中有如下设置
services.AddAuthentication(AzureADDefaults.AuthenticationScheme);
services.AddMicrosoftIdentityWebAppAuthentication(Configuration, "AzureAd")
.EnableTokenAcquisitionToCallDownstreamApi(ScopeConstants.SCOPES)
.AddDistributedTokenCaches();
【问题讨论】:
-
@JasSuri-MSFT 提供的链接中的过程不起作用。我正在处理的业务案例确实是 B2C,但当前不支持或不包含在不记名令牌中的应用角色的限制意味着我不能使用用户流逻辑(即 SignUpSignInPolicyId)。标准 AzureAd 支持应用程序角色,但我被困在这个问题上。范围值在已共享的 Web 应用配置中表示为 ScopeConstants.SCOPES。即 public static List
SCOPES = new List () { ReadWrite,Read };
标签: scope azure-ad-b2c target-audience