azure-active-directory – Microsoft Azure AD图API:如何检索用户的电子邮件地
|
我能够访问用户的accessToken,并且正在使用Authorization:Bearer< token>来调用GET https://graph.microsoft.com/v1.0/me.头. 但是,在响应正文中,我得到的是这样的: {
"@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users","value": [
{
"givenName": "Foo","surname": "Bar","displayName": "Foo Bar","id": "b41efha115adcca29","userPrincipalName": "email.address@outlook.com","businessPhones": [],"jobTitle": null,"mail": null,"mobilePhone": null,"officeLocation": null,"preferredLanguage": null
}
]
}
mail属性为null,此响应正文中的userPrincipalName恰好是用户的电子邮件地址.但是,这是来自微软的docs:
在启动用户的登录请求时,我们正在请求“user.read”和“email”范围.我们使用MSAL.js库来获取访问令牌,我们的代码读取如下内容: login (): ng.IPromise<IMicrosoftOAuthResponse> {
const prom = this.userAgentApplication.loginPopup(["user.read","email"])
.then((idToken) => {
return this.userAgentApplication.acquireTokenSilent(["user.read","email"]);
})
.then((accessToken) => {
// at this point,we have the accessToken and make a call to the graph api
});
return this.$q.when(prom);
}
如何在此处获取用户的实际电子邮件地址? mail属性设置为以下两种方式之一:>它已在内部部署AD上设置,然后使用AD Connect同步到Azure AD 如果用户没有O365邮箱/许可证,您还可以通过userPrincipalName,displayName等搜索用户.$filter支持OR运算符. 希望这可以帮助, (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
