加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Windows > 正文

azure-active-directory – Microsoft Azure AD图API:如何检索

发布时间:2020-12-13 21:27:06 所属栏目:Windows 来源:网络整理
导读:我能够访问用户的accessToken,并且正在使用Authorization:Bearer token来调用GET https://graph.microsoft.com/v1.0/me.头. 但是,在响应正文中,我得到的是这样的: { "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users","value": [ { "
我能够访问用户的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:

Although the UPN and email share the same format,the value of the UPN for a user might or might not be the same as the email address of the user.

在启动用户的登录请求时,我们正在请求“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
>已为云用户分配了Office 365许可证(和邮箱),此时为此许可用户设置了邮件属性.

如果用户没有O365邮箱/许可证,您还可以通过userPrincipalName,displayName等搜索用户.$filter支持OR运算符.

希望这可以帮助,

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读