英文:
AzureAD GraphAPI: How to get Group-Name
问题
我尝试使用MS Graph API for Java获取用户的组成员关系。
我的用户是7个组的成员。但我只获取到了组ID(类似UUID),而displayName始终为空。
有没有办法获取组的名称?
User usr = gsc.users(MYUSERID).buildRequest().get();
System.out.println("User: " + usr.displayName);
DirectoryObjectCollectionWithReferencesPage doc = gsc.users(MYUSERID).memberOf().buildRequest().get();
java.util.List<DirectoryObject> lst = doc.getCurrentPage();
for (int i = 0; i < lst.size(); i++) {
if (lst.get(i) instanceof Group) {
Group gp = (Group) lst.get(i);
System.out.println("Member: " + gp + " / " + gp.id + " / " + gp.displayName);
}
}
输出是:
User: MyTestUser
Member: com.microsoft.graph.models.Group@c514b123 / 83091123-c2ea-4883-8a2b-faab7de7433 / null
...
编辑
这也只返回null。
for (int i = 0; i < lst.size(); i++) {
System.out.println(((Group)doc.getCurrentPage().get(i)).displayName);
}
编辑
改成memberOfAsGroup
仍然返回displayName为null。
GroupCollectionPage doc = gsc.users(this.azureuserid).memberOfAsGroup().buildRequest().get();
java.util.List<Group> lst = doc.getCurrentPage();
for (int i = 0; i < lst.size(); i++) {
Group gp = lst.get(i);
System.out.println(i + " Member: " + gp + " / " + gp.id + " / " + gp.displayName + " " + gp.description);
}
希望这些能帮助您解决问题。
英文:
I try to get the group-memberships of a user via MS Graph API for Java.
My user is member in 7 groups. But I only get the group ID (sort of UUID) but displayName is always null.
Any idea how to get the name of the group??
User usr = gsc.users (MYUSERID).buildRequest ().get ();
System.out.println ("User: " + usr.displayName);
DirectoryObjectCollectionWithReferencesPage doc = gsc.users (MYUSERID).memberOf ().buildRequest ().get ();
java.util.List <DirectoryObject> lst = doc.getCurrentPage();
for (int i = 0; i < lst.size (); i ++)
{
if (lst.get (i) instanceof Group)
{
Group gp = (Group) lst.get (i);
System.out.println ("Member: " + gp + " / " + gp.id + " / " + gp.displayName);
}
}
Output is
User: MyTestUser
Member: com.microsoft.graph.models.Group@c514b123 / 83091123-c2ea-4883-8a2b-faab7de7433 / null
...
EDIT
This also only delivers null.
for (int i = 0; i < lst.size (); i ++)
{
System.out.println (((Group)doc.getCurrentPage().get(i)).displayName);
}
EDIT
Changed to memberOfAsGroup - still null for displayName.
GroupCollectionPage doc = gsc.users (this.azureuserid).memberOfAsGroup ().buildRequest ().get ();
java.util.List <Group> lst = doc.getCurrentPage ();
for (int i = 0; i < lst.size (); i ++)
{
Group gp = lst.get (i);
System.out.println(i + " Member: " + gp + " / " + gp.id + " / " + gp.displayName + " " + gp.description);
}
答案1
得分: 0
现在正在运作。在Azure中注册的应用程序需要Groups.ReadAll权限(应用程序权限,而不是委托权限!)。
令人惊讶的是,需要的不是分配的权限,而仅仅是对它的管理员同意 - 即使权限被移除。
不知道这是一个错误还是特性。
英文:
Is working now. Registered app in Azure needs permission for Groups.ReadAll (Application, not Delegate!).
Surprisingly not the assigned permission is needed but only the admin-consent to it - even if the persmission is removed.
Do not know if this is a bug or feature.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论