2017-10-05 109 views
0

我嘗試使用Microsoft Graph API創建訪客用戶。我用財產UserType使用Microsoft Graph API在Azure AD中創建訪客用戶

user.UserType = "Guest"; 

但是迴應顯示Invalid User principal Name

我可以在門戶中創建相同的用戶。

+0

沒有足夠的位置去。你如何認證?你在用什麼SDK?你爲'userPrincipalName'使用了什麼? –

回答

1

要將外部用戶添加到組織中,我們需要使用邀請REST,而不是直接創建用戶。這是給你參考的REST和示例代碼(微軟圖表SDK):

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

{ 
    "invitedUserEmailAddress": "[email protected]", 
    "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 = "[email protected]"; 
invitation.InviteRedirectUrl = "http://localhost"; 
var result= graphserviceClient.Invitations.Request().AddAsync(invitation).Result; 
相關問題