2017-06-26 42 views

回答

3

使用Microsoft Graph REST很容易創建Azure AD用戶。這裏是供您參考的代碼示例:

POST https://graph.microsoft.com/v1.0/users 
Authorization: Bearer {token} 
Content-type: application/json 

{ 
    "accountEnabled": true, 
    "displayName": "displayName-value", 
    "mailNickname": "mailNickname-value", 
    "userPrincipalName": "[email protected]", 
    "passwordProfile" : { 
    "forceChangePasswordNextSignIn": true, 
    "password": "password-value" 
    } 
} 

它還提供了使用C#從here相應的庫。關於微軟圖表的更多細節,你可以參考以下鏈接:

Overview of Microsoft Graph

Get access tokens to call Microsoft Graph

Create User

+0

我正在開發一個web應用程序,並在後端使用dotnet核心webapi。我有一個UsersController並希望使用該控制器上的端點來獲取有關AzureAD中的用戶的信息。端點是'/ api/users?id = {id}'我如何將請求重定向到'https:// graph.microsoft.com/v1.0/users'?授權中的令牌:持證人{令牌}當前登錄用戶的令牌?或者它是我的應用程序更普遍的標誌?我的網絡應用程序也在Azure中託管。我需要添加Microsoft Graph嗎? – kanpeki

+0

如果您只想獲取當前用戶登錄的特定用戶信息,則可以獲取用戶的委託令牌。你是什​​麼意思重定向請求?要獲取當前用戶的用戶信息,可以參考[active-directory-dotnet-graphapi-web](https://github.com/Azure-Samples/active-directory-dotnet-graphapi-web)。 –

0

使用C#和圖形API庫薛飛提到的,你可以寫這樣的代碼:

User newUser = new User 
{ 
    Id = user.Id, 
    BusinessPhones = someUser.BusinessPhones, 
    DisplayName = someUser.DisplayName, 
    GivenName = someUser.GivenName, 
    JobTitle = someUser.JobTitle, 
    Mail = someUser.Mail, 
    MobilePhone = someUser.MobilePhone, 
    OfficeLocation = someUser.OfficeLocation, 
    PreferredLanguage = someUser.PreferredLanguage, 
    Surname = someUser.Surname, 
    UserPrincipalName = someUser.UserPrincipalName 
}; 
User createdUser = await graphClient.Users.Request().AddAsync(newUser); 

用戶是Graph包提供的類。 graphClient對象是一個提供連接和認證信息的GraphServiceClient對象。

另外,還有一組支持的用戶信息。您可以在對用戶文檔中的Create User示例的回覆中看到它們。文檔中列出了用戶的其他屬性,但這些「屬於」SharePoint,Office 365等應用程序,並且在沒有該應用程序的許可證的情況下不可用。

請注意,文檔是稀疏的,所以有時需要試驗和錯誤才能正常工作。

我一直在使用Graph Snippets example來獲得這方面的經驗。它有很多使用示例。另一個很好的資源是圖形瀏覽器,它可以讓你實時進行實驗。

如果您遇到問題,我會被告知Azure和Graph開發人員對SO進行監控,並對問題做出快速響應。這是我迄今的經驗。

祝你好運!