gpt4 book ai didi

azure - 使用 https ://graph. microsoft.com 和 ActiveDirectoryClient 将用户添加到 Azure Active Directory

转载 作者:行者123 更新时间:2023-12-03 02:50:24 24 4
gpt4 key购买 nike

我正在尝试将用户添加到我的 Azure 租户的 Active Directory。

我正在使用 Microsoft Graph API。通过 Graph Explorer 暴露的同一个 here .

问题是,无论我传递什么 serviceRoot URI,我都会遇到异常。

我在 GetTokenForApplication 方法中成功获取了 token :

ActiveDirectoryClient activeDirectoryClient = new ActiveDirectoryClient(serviceRoot,
async () => await GetTokenForApplication());

但是,当我打电话时:

await activeDirectoryClient.Users.AddUserAsync(aadUser);

它抛出这个异常:

 "{\r\n
\"error\": {\r\n
\"code\": \"BadRequest\",\r\n
\"message\": \"Query parameter api-version not allowed\",\r\n
\"innerError\": {\r\n
\"request-id\": \"57327a85-8320-4363-b5f9-aeacdf782861\",\r\n
\"date\": \"2019-05-30T21:59:55\"\r\n
}\r\n
}\r\n
}"

这是我正在使用的 serviceRoot URI:“https://graph.microsoft.com/v1.0

我应该在 serviceRoot 中传递什么 URI?

ActiveDirectoryClientMicrosoft Graph 兼容吗?我之所以这么问,是因为我看到使用 ActiveDirectoryClient 的示例使用的是 Azure AD Graph API

这个blog post显示旧版 Azure AD Graph API 和新版 Microsoft Graph API 之间的差异。顺便说一句:微软建议我们使用 Microsoft Graph API,因为所有新的开发都将集中在它上面。

最佳答案

我认为您正在尝试使用较新的 Microsoft Graph API (https://graph.microsoft.com),但使用旧版 Azure AD Graph API 的客户端库 (https://graph.windows.net)

您可以在此处阅读详细比较 - Microsoft Graph or the Azure AD Graph

以下是 nuget 包和类的详细信息:

Microsoft Graph API

  • Microsoft.Graph nuget 包 - 与 Microsoft Graph API 配合使用并使用 GraphServiceClient 类。

Azure AD 图形 API

  • Microsoft.Azure.ActiveDirectory.GraphClient nuget 包 - 用于与 Azure AD Graph API 配合使用并使用 ActiveDirectoryClient 类。

Microsoft Graph API 客户端代码

微软文档 - Create User - SDK Sample Code

GraphServiceClient graphClient = new GraphServiceClient( authProvider );

var user = new User
{
AccountEnabled = true,
DisplayName = "displayName-value",
MailNickname = "mailNickname-value",
UserPrincipalName = "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="364346581b40575a4353764253585758421b40575a43531859585b5f554459455950421855595b" rel="noreferrer noopener nofollow">[email protected]</a>",
PasswordProfile = new PasswordProfile
{
ForceChangePasswordNextSignIn = true,
Password = "password-value"
}
};

await graphClient.Users
.Request()
.AddAsync(user);

关于azure - 使用 https ://graph. microsoft.com 和 ActiveDirectoryClient 将用户添加到 Azure Active Directory,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56386328/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com