Graph Me api azure AD 中的 MemberOf

发布于 2025-01-16 01:05:35 字数 1698 浏览 1 评论 0原文

我正在尝试使用 azure graph api 获取用户所属用户的成员组,但它没有在 api 中返回memberof。我使用 auth0 进行身份验证。

这是我正在使用的java脚本代码。

function(accessToken, ctx, cb) {
const jwt = require('[email protected]');
console.log('azure - retrieve user profile');
// Retrieve the profile from Azure
request.get(
'https://graph.microsoft.com/v1.0/me?$select=id,mail,givenName,surname,userPrincipalName,otherMails,department,memberOf', {
  headers: {
    'Authorization': 'Bearer ' + accessToken,
  },
  json: true
},
function(e, r, profile) {
  if (e) {
    console.log('azure - error while retrieving user profile:');
    console.log(e);
    return cb(e)
  }
  if (r.statusCode !== 200) {
    console.log('azure - error while retrieving user profile: ' + r.statusCode);
    return cb(new Error('StatusCode: ' + r.statusCode));
  }
  console.log('azure - retrieved user profile.');
  // Get the tenant id from the access token
  let decodedToken = jwt.decode(accessToken);
  let auth0Profile = {
    user_id: profile.id,
    given_name: profile.givenName,
    family_name: profile.surname,
    email: profile.mail || profile.otherMails[0] || profile.userPrincipalName,
    email_verified: true,
    name: profile.givenName + ' ' + profile.surname,
    tenant_id: decodedToken.tid,
    identification_value: decodedToken.tid,
    user_principal_name: profile.userPrincipalName,
    user_department: profile.department,
    user_member: profile.memberOf
   };
  cb(null, auth0Profile);
  }
  );
  }

我在 Auth0 中为 api 调用添加了范围 (User.Read Directory.Read.All)。 有人可以告诉我为什么我没有获得memberOf 吗?

I am trying to get the member groups of the user to whom user belongs using azure graph api but it is not returning memberof in the api. I am using auth0 for the authentication.

Here is the java script code which I am using.

function(accessToken, ctx, cb) {
const jwt = require('[email protected]');
console.log('azure - retrieve user profile');
// Retrieve the profile from Azure
request.get(
'https://graph.microsoft.com/v1.0/me?$select=id,mail,givenName,surname,userPrincipalName,otherMails,department,memberOf', {
  headers: {
    'Authorization': 'Bearer ' + accessToken,
  },
  json: true
},
function(e, r, profile) {
  if (e) {
    console.log('azure - error while retrieving user profile:');
    console.log(e);
    return cb(e)
  }
  if (r.statusCode !== 200) {
    console.log('azure - error while retrieving user profile: ' + r.statusCode);
    return cb(new Error('StatusCode: ' + r.statusCode));
  }
  console.log('azure - retrieved user profile.');
  // Get the tenant id from the access token
  let decodedToken = jwt.decode(accessToken);
  let auth0Profile = {
    user_id: profile.id,
    given_name: profile.givenName,
    family_name: profile.surname,
    email: profile.mail || profile.otherMails[0] || profile.userPrincipalName,
    email_verified: true,
    name: profile.givenName + ' ' + profile.surname,
    tenant_id: decodedToken.tid,
    identification_value: decodedToken.tid,
    user_principal_name: profile.userPrincipalName,
    user_department: profile.department,
    user_member: profile.memberOf
   };
  cb(null, auth0Profile);
  }
  );
  }

I have added scope (User.Read Directory.Read.All) in Auth0 for the api call.
Can some one let me know why I am not getting memberOf?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

尽揽少女心 2025-01-23 01:05:35

如果您想要获取用户的成员组以及多个属性,则查询将不会返回预期结果。

我尝试在 Microsoft Graph Explorer 中检查相同的查询。

'https://graph.microsoft.com/v1.0/me?$select=id,mail,givenName,surname,userPrincipalName,otherMails,department,memberOf'

甚至
为此,除了 memberOf 之外,所有对象均显示:

在此处输入图像描述

要获取 memberOf,您必须单独查询,如下所示:

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

在此处输入图像描述

因此,对于解决方法,您可以利用上面的查询通过单独给出它而不查询其他属性。

另请确保在此 Microsoft Doc

如果有帮助,请查找以下链接: Ref1, 参考2

If you want to get member groups of the user, along with multiple attributes, the query will not return the expected results.

I tried checking the same query in Microsoft Graph Explorer.

'https://graph.microsoft.com/v1.0/me?$select=id,mail,givenName,surname,userPrincipalName,otherMails,department,memberOf'

Even
for that, except memberOf, all objects displayed:

enter image description here

For getting memberOf, you have to query separately like below:

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

enter image description here

So, for the workaround, you can make use of the above query by giving it separately without querying with other attributes.

Also please make sure to add GroupMember.Read.All permissions in the scope as mentioned in this Microsoft Doc.

Please find below links if they are helpful: Ref1, Ref2

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文