我正在使用此代码从Java SDK在Azure Active Directory中创建用户.我已经安装了所有必需的包和库.

User user = new User();
user.accountEnabled = true;
user.displayName = "Kevin";
user.mailNickname = "kevin";
user.userPrincipalName = "kevin234@domain.onmicrosoft.com";
PasswordProfile passwordProfile = new PasswordProfile();
passwordProfile.forceChangePasswordNextSignIn = true;
passwordProfile.password = "***********";
user.passwordProfile = passwordProfile;

graphClient.users()
    .buildRequest()
    .post(user);

我可以创建普通用户,但如何创建来宾用户.我在上面的代码中包含了user.userType='guest'

user.userPrincipalName = "kevin234@hotmail.com";
user.userType='guest'; // I added this that outputs Invalid Request error

graphClient.users()
   .buildRequest()
   .post(user);

使用Graph API Query有什么简单的方法可以做到这一点吗?有人能建议我在代码中进行哪些更改才能实现我的场景吗?

提亚

推荐答案

100

要创建访客用户,您可以使用以下查询:

POST https://graph.microsoft.com/v1.0/invitations
Content-type: application/json

{
  "invitedUserEmailAddress": "kevin234@hotmail.com",
  "inviteRedirectUrl": "https://yourwebsite.com"
}

Response:

enter image description here

当我判断门户时,guest user成功创建,如下所示:

enter image description here

您可以在您的查询响应旁边找到Java中的100,如下所示:

enter image description here

Code Sample in Java:

GraphServiceClient graphClient = GraphServiceClient.builder().authenticationProvider( authProvider ).buildClient();

Invitation invitation = new Invitation();
invitation.invitedUserEmailAddress = "kevin234@hotmail.com";
invitation.inviteRedirectUrl = "https://yourwebsite.com";

graphClient.invitations()
.buildRequest()
.post(invitation);

Credits:Create invitation - Microsoft Docs

Java相关问答推荐

将偶数元素移动到数组的前面,同时保持相对顺序

如何在Docker容器中使用wireock—Webhooks阻止请求?

填写文本字段后锁定PDF

AlarmManager没有在正确的时间发送alert

Java List with all combinations of 8 booleans

当我已经安装了其他版本的Java时,如何在Mac OSX 14.3.1上安装Java 6?

SpringBoot+Java 17@Valid未验证POJO

无法使用ApacheSpark依赖项构建JavaFX应用程序

JOOQ中的子查询使用的是默认方言,而不是配置的方言

Javadoc在方法摘要中省略方法

使用PDFBox从PDF中删除图像

Java中将文本拆分为数字或十进制数字和字符串

声明带有泛型的函数以用作查找映射中的值

Domino Designer 14中的保存代理添加了重影库

如果按钮符合某些期望,如何修改它的文本?

为什么使用lo索引来解决二进制搜索问题不同于使用hi索引?

整数->;双取消框,但双->;int不';t开箱.为什么?

当我将鼠标悬停在javafxTextArea上时,如何更改鼠标光标?

使用DynamoDB增强客户端时未更新属性

为什么 Random() 的行为不符合预期?