使用图形 API 在 Azure AD 中创建来宾用户Microsoft



我尝试使用图形API创建一个来宾用户Microsoft。我使用了该物业UserType

user.UserType =  "Guest";

但回应显示Invalid User principal Name.

我可以在门户中创建相同的用户。

要将外部用户添加到组织,我们需要使用邀请 REST 而不是直接创建用户。以下是 REST 和代码示例(Microsoft图形 SDK)供您参考:

POST https://graph.microsoft.com/v1.0/invitations
Content-type: application/json
Content-length: 551
{
  "invitedUserEmailAddress": "yyy@test.com",
  "inviteRedirectUrl": "https://myapp.com"
}

代码示例:

string accessToken = "";
var graphserviceClient = new GraphServiceClient(
new DelegateAuthenticationProvider(
       (requestMessage) =>
      {
          requestMessage.Headers.Authorization = new AuthenticationHeaderValue("bearer", accessToken);
          return Task.FromResult(0);
 }));
Invitation invitation = new Invitation();
invitation.SendInvitationMessage = true;
invitation.InvitedUserEmailAddress = "xxxx@hotmail.com";
invitation.InviteRedirectUrl = "http://localhost";
var result= graphserviceClient.Invitations.Request().AddAsync(invitation).Result;

最新更新