Azure AD 我的个人资料

标签 azure single-sign-on audience

我收到错误“访问 token 验证失败。受众无效。” 对于应用程序,将 api 权限设置为offline_access、openid、profile、User.Read。 用户启动身份验证,转到 MS 身份验证站点,询问登录名、密码和等级。

交换代码以访问 token 后,我很好地收到了

{'token_type': 'Bearer', 'scope': 'offline_access openid profile User.Read', 'expires_in': '3906', 'ext_expires_in': '3906', 'expires_on': '1653988700', 'not_before': '1653984493', 'resource': 'my_azure_client_id', ....}

然后我尝试使用此访问 token 获取当前用户的配置文件。 结果我收到错误“访问 token 验证失败。受众无效。”

帮助豌 bean )

更新 配置的权限 enter image description here

最佳答案

出现该错误的原因是您的 token 有错误的受众

请检查您使用什么 token 来调用Graph API

我尝试在我的环境中重现相同的内容。 如果您使用 ID Token 而不是 Access Token,您可能会收到如下错误:

enter image description here

要了解您提供的是访问 token 还是ID token ,请在JSON Web Tokens - jwt.io中对其进行解码.

对于access tokenaud 声明将为 "https://graph.microsoft.com""00000003-0000-0000-c000- 000000000000"

对于id tokenaud 声明将为 “your_app_client_id”

仔细选择访问 token aud“https://graph.microsoft.com”调用 Microsoft Graph API 时:

enter image description here

获取profile for current user ,您可以使用以下查询:

GET https://graph.microsoft.com/v1.0/me

我使用访问 token 成功获取了配置文件,如下所示:

enter image description here

在生成访问 token 时将范围替换为 https://graph.microsoft.com/.default 以避免混淆。

引用:

oauth 2.0 - Microsoft Graph API: Access token validation failure. Invalid audience - Stack Overflow

更新:

为了获取授权代码,请通过更改范围来发出请求,如下所示:

https://login.microsoftonline.com/your_tenant_id/oauth2/v2.0/authorize?
client_id=your_client_id
&response_type=code
&redirect_uri=xxxxxx
&response_mode=query
&scope=https://graph.microsoft.com/.default
&state=12345

关于Azure AD 我的个人资料,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72444516/

相关文章:

java - 使用 Active Directory 在 Java 平台中进行单点登录 (SSO)

c# - MVC 上的 IdentityServer : What is Audience refering in AddJwtBearer

android - Firebase:仪表板/受众可能的错误?

azure - 如何在 Azure 中的新数据库上运行数据库迁移?

Azure 图形存储帐户 blob 容器

java - 如何在 Java 中解码从 Azure 获取的 SAML token ?

python - 如何通过 Restful 服务调用进行单点登录 (SSO)

facebook - 此应用已被货币化 : The app you're attempting to add is already being monetized by a business in Facebook audience network?

firebase - Azure DevOps 将 iOS 应用程序部署到 Firebase 应用程序分发

azure - Azure VM 的多个公共(public) IP