【问题标题】:User profile enrichment in AZUREADAZUREAD 中的用户配置文件丰富
【发布时间】:2021-12-27 18:25:29
【问题描述】:

我有一个关于丰富用户个人资料的问题。 如何使用我的 office356 平台中提供的额外信息(例如 id 号码、个人电话和任何其他可用信息)来丰富用户配置文件?

我有一个 Angular SPA,用户必须在其中登录并随后执行一些操作,但我确实需要获取前面提到的信息才能这样做。

我有如下所示的代码。我搜索了 Azure 的文档,但一无所获。

const GRAPH_ENDPOINT = 'https://graph.microsoft.com/v1.0/me';

  getProfile() {
    this.http.get(GRAPH_ENDPOINT)
      .subscribe(profile => {
        this.profile = profile;
        console.log(profile)
      });
  }

  getProfilePhoto() {
    this.http.get(GRAPH_ENDPOINT+'/photo/$value').subscribe(
      photo => { 
        this.photo = photo; 
        console.log(this.photo);
    });
  }

有什么帮助或提示可以帮助这位可怜的程序员吗?

谢谢!

【问题讨论】:

    标签: azure azure-active-directory


    【解决方案1】:

    如果我没有低估错误,请检查此是否可以查询 id 或手机号码等类似代码:

    因为 'https://graph.microsoft.com/v1.0/me 提供了完整的个人资料详细信息,就像提供的代码一样

    const GRAPH_ENDPOINT = 'https://graph.microsoft.com/v1.0/me';
    
      getProfile() {
        this.http.get(GRAPH_ENDPOINT)
          .subscribe(profile => {
            this.profile = profile;
            console.log(profile)
          });
      }
    

    在 microsoft graph api 中相同:

    这样我们就可以查询id、手机号等详细信息 通过使用选择查询过滤 更多查询参数见参考资料:Get a user-Microsoft Graph v1.0 | Microsoft Docs -REFERENCEUse query parameters

    所以要在图中使用https://graph.microsoft.com/v1.0/me?$select=mobilePhone 获取手机号码,同样可以修改代码,如下所示 示例:

     getMobileNumber() {
        this.http.get(GRAPH_ENDPOINT+'?$select=mobilePhone ').subscribe(
          mobilePhone => { 
            this. mobilePhone = mobilePhone; 
            console.log( this. mobilePhone);
        });
      }
    

    就像从图表中一样

    所以要在图形 https://graph.microsoft.com/v1.0/me?$select=id 中获取 id,请修改使用此请求的代码。

    例子:

    getId(){
    this.http.get(GRAPH_ENDPOINT+'?$select=id ').subscribe(
          Id=> { 
            this. Id= Id; 
            console.log( this. Id);
    
    });
    }
    

    你也可以使用图形客户端

    参考资料:

    1. Build Angular single-page apps with Microsoft Graph - Microsoft Graph | Microsoft Docs
    2. azure - Obtaining Profile Photo from MS Graph API to Angular app - Stack Overflow 来自 >> So reference
    3. create-requests-typescript

    【讨论】:

    • 我稍后会检查它,并告诉你进展如何。希望能帮助到你。谢谢!
    猜你喜欢
    • 2021-07-09
    • 2012-09-12
    • 2011-09-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-12
    • 2011-07-27
    相关资源
    最近更新 更多