概述
我们有一个 Azure AD 安全 API 作为 Web 应用程序存在于 Azure 中。我们需要能够:
问题
问题是,当我们从 Azure AD 请求令牌时,令牌声明中未设置范围,导致 API 拒绝令牌。
此请求返回带有以下声明的访问令牌:
{
"aud": "<our api client id>",
"iss": "https://login.microsoftonline.com/<tenantId>/v2.0",
"iat": 1644421512,
"nbf": 1644421512,
"exp": 1644425412,
"aio": "<value>",
"azp": "<scheduled job client id>",
"azpacr": "1",
"oid": "<guid>",
"rh": "<value>",
"sub": "<guid>",
"tid": "<guid>",
"uti": "<value>",
"ver": "2.0"
}
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,scp即使我们将(范围)包含在请求中,令牌声明中也不包含它。
如果我们使用此令牌向 API 发出请求,我们会收到以下错误:
System.UnauthorizedAccessException: IDW10201: Neither scope or roles claim was found in the bearer token. …Run Code Online (Sandbox Code Playgroud)