访问令牌提供不同的 AUD?

Access Token giving different AUD?

我正在尝试通过 OAuth 在 Azure 中使用 API Management 进行身份验证。我已经把那部分设置好了。

我在获得 ID 令牌和访问令牌 (response_type=id_token+token) 的地方发生了 OAuth2 隐式登录流程。当我在返回的访问令牌中检查 aud 时,我得到默认的图形 API aud (00000003-0000-0000-c000-000000000000) 而不是我的客户端 ID,我需要使用它来进行身份验证API 管理片。

这需要留在 OAuth 后面,因为它是一个内部应用程序,我不想在 public 上放过它。我正在使用隐式流,因为该网页是托管在 Blob 上的 SPA。

正如 junnas 所说,如果您想获取您的 clientId 的 aud,您需要为您的应用添加有效范围。

转到您在 Azure 广告中注册的应用的 Expose a scope,然后 Add a scope

并在 url 中添加范围,如下所示:

https://login.microsoftonline.com/xxxx/oauth2/v2.0/authorize?
client_id=xxxxx
&response_type=id_token+token
&redirect_uri=https://localhost:123
&scope=openid api://xxxxxxxxxxxxxxxxxxxxxx-a3aab90df9fc/webread
&response_mode=fragment
&state=12345
&nonce=678910

然后解码access token,你会得到aud中的client id: