azure-active-directory - 如何使用 Azure AD 范围和 oidc-client.js 检索用户信息?
问题描述
在将 azure 广告范围与 oidc-client.js 一起使用时,我很困惑如何获取访问令牌和用户信息详细信息。
我在门户中针对我的应用程序具有以下范围...
然后我将我的用户管理器设置设置如下....
var settings: UserManagerSettings = {
authority: `https://login.microsoftonline.com/${tenantId}`,
client_id: clientId,
redirect_uri: "http://localhost:3000/authcallback",
post_logout_redirect_uri: "http://localhost:3000/authcallback",
response_type: "token id_token",
scope: `api://${clientId}/access_user_data openid`,
popup_redirect_uri: "http://localhost:3000/authcallback",
silent_redirect_uri: "http://localhost:3000/authcallback",
automaticSilentRenew: true,
loadUserInfo: true,
metadata: {
userinfo_endpoint: "https://graph.microsoft.com/oidc/userinfo",
authorization_endpoint: `https://login.microsoftonline.com/${tenantId}/oauth2/v2.0/authorize`,
issuer: `https://login.microsoftonline.com/${tenantId}/v2.0`,
jwks_uri: `https://login.microsoftonline.com/${tenantId}/discovery/v2.0/keys`
}
};
当我使用登录时,signinRedirect
我会access_token
返回到我的回调,但是https://graph.microsoft.com/oidc/userinfo
在执行getUser()
.
oidc-client.min.js:1 GET https://graph.microsoft.com/oidc/userinfo 401 (Unauthorized)
访问令牌似乎确实适用于需要api://${clientId}/access_user_data
范围的我的 api。
此处的发现文档列出了以下可用范围
"scopes_supported": [
"openid",
"profile",
"email",
"offline_access"
]
我认为这会起作用,因为我也包括openid
范围。请注意,如果我只有这样的openid
范围scope: "openid"
,getUser()
则可以工作,但是它没有调用我的 api 所需的范围。
我在这里做错了什么?
谢谢,
解决方案
在一些研究尝试将 loadUserInfo 设置为 false 解决了我的问题后遇到了同样的问题,请尝试相同的方法
推荐阅读
- python - 在 Windows 10 上安装 jupyter notebook 时出错
- mysql - 带有内部连接的 MYSql 查询返回重复的结果
- java - 多线程 - 在基于回合的游戏中不唤醒其他线程。爪哇
- amazon-web-services - AWS ElasticBeans 与 Eureka 和 Zuul ,如何限制对服务的访问?
- svn - SVN 在 UE4 中自动锁定 .umap 文件
- c# - 在 Vuforia 平面查找器检测表面时显示文本/图像
- javascript - 我需要创建一个无限循环
- python - 为什么第一个字节打印为 (b'c\x..) 而不是 (b'x63\x..)?
- java - How can i make my springboot app websocket app get connected via a "ws://" url while using stomp
- c# - 自动重试连接