我知道有Azure门户可以管理组、用户等。
是否有编程方式来实现这一点(可以使用Web API或C#的SDK)?
先行致谢。
我知道有Azure门户可以管理组、用户等。
是否有编程方式来实现这一点(可以使用Web API或C#的SDK)?
先行致谢。
使用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": "upn-value@tenant-value.onmicrosoft.com",
"passwordProfile" : {
"forceChangePasswordNextSignIn": true,
"password": "password-value"
}
}
此外,它还提供了相应的C#库,可以从这里获取。有关Microsoft Graph的更多详细信息,请参阅下面的链接:
使用 C# 和 Fei Xue 提到的 Graph 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);
User是Graph包提供的一个类。graphClient对象是GraphServiceClient对象,它提供连接和身份验证信息。
此外,还支持一组核心的用户信息。您可以在用户文档中创建用户示例的响应中查看它们。User文档中列出了其他属性,但这些属性“属于”SharePoint、Office 365等应用程序,没有该应用程序的许可证则无法使用。
请注意,文档很少,因此有时需要进行试验和错误才能使某些内容正常工作。
我一直在使用Graph Snippets示例来获得经验。它有很多用法示例。另一个很棒的资源是Graph浏览器,它可以让您实时尝试各种操作。
如果您遇到问题,我被告知Azure和Graph开发人员会监视SO并迅速回答问题。这是我的经历。
祝你好运!
/api/users?id={id}
。如何将请求重定向到https://graph.microsoft.com/v1.0/users
?Authorization: Bearer {token}中的令牌是当前登录用户的令牌吗?还是它是我的应用程序的更通用令牌?我的Web应用程序也托管在Azure中。我需要将Microsoft Graph添加到其中吗? - kanpeki