如何使用 java spring boot 应用程序将使用 emailId 的用户添加到 azure 广告组

问题描述 投票:0回答:1

我们需要通过 java spring boot 应用程序使用用户电子邮件将成员添加到 azureAdGroup,我们正在使用 microsoft graph api 休息调用将成员添加到 azureAdGroup

尝试通过 java spring boot 应用程序使用成员电子邮件将成员添加到 azureAdGroup,我们使用以下代码使用图形 API 添加成员

DirectoryObject directoryObject = new DirectoryObject();
directoryObject.id = "[email protected]"; // members emailId

graphClient.groups(adGroupId).members().references()
   .buildRequest()
   .post(directoryObject);

但是我们收到以下错误

CoreHttpProvider[sendRequestInternal] - 404Graph服务异常错误代码:Request_BadRequest CoreHttpProvider[sendRequestInternal] - 404错误消息:无效的对象标识符“[电子邮件受保护]”。 CoreHttpProvider[sendRequestInternal] - 404 CoreHttpProvider[sendRequestInternal] - 404POST https://graph.microsoft.com/v1.0/groups/sgdbhjd-sndeh3h3-dasdnj3k3-dwb23/members/$ref CoreHttpProvider[sendRequestInternal] - 404SdkVersion:graph-java/v5.0.0 CoreHttpProvider[sendRequestInternal] - 404SdkVersion:graph-java/v5.0.0

任何人都可以帮助如何通过 java spring boot 应用程序中的 microsoft graphApi 使用成员电子邮件将成员添加到 azureAdGroup

任何人都可以帮助如何通过 java spring boot 应用程序中的 microsoft graphApi 使用用户电子邮件将成员添加到 azureAdGroup

java spring-boot microsoft-graph-api azure-ad-graph-api microsoft-graph-sdks
1个回答
0
投票

注意:根据此MsDoc,要将用户添加到组中,您需要传递

directoryObject
的ID而不是用户的UPN。

对于 sample,我使用 Graph Explorer APIs 将用户添加到组中:

传递用户的UPN并得到错误:

POST https://graph.microsoft.com/v1.0/groups/{group-id}/members/$ref
Content-type: application/json

{
  "@odata.id": "https://graph.microsoft.com/v1.0/directoryObjects/UPN"
}

enter image description here

要解决错误,请传递用户的

ObjectID
而不是 UPN:

通过

ObjectID
后,用户成功添加到群组:

enter image description here

enter image description here

通过传递用户的

ObjectID
而不是 UPN 来修改代码:

DirectoryObject directoryObject = new DirectoryObject();
directoryObject.id = "ObjectID"; // members ObjectID

graphClient.groups(adGroupId).members().references()
   .buildRequest()
   .post(directoryObject);
© www.soinside.com 2019 - 2024. All rights reserved.