gpt4 book ai didi

azure - 如何使用 Microsoft.Azure.ActiveDirectory.GraphClient sdk 以编程方式邀请 Azure AD 中的用户

转载 作者:行者123 更新时间:2023-12-02 23:46:40 25 4
gpt4 key购买 nike

我正在尝试邀请 Azure B2B Active Directory 中的用户。我无法找到使用 Client SDK 执行此操作的方法。

有可行的方法吗?

感谢您提前提供的帮助。 :)

最佳答案

Is there a possible way to do that?

我找不到邀请 Microsoft.Azure.ActiveDirectory.GraphClient 用户的方法.

但我们可以这样做 Microsoft.Graph 。并且Azure官方文档还建议您使用Microsoft Graph而不是Azure AD Graph API .

We strongly recommend that you use Microsoft Graph instead of Azure AD Graph API to access Azure Active Directory resources. https://learn.microsoft.com/en-us/azure/active-directory/develop/active-directory-graph-api

我还为它做了一个演示。我这边工作正常。

在此之前,我在 Azure 目录中创建 Web 应用程序。添加 Microsoft Graph 所需的邀请 guest 用户加入组织权限

enter image description here

演示代码:

string authority = "https://login.microsoftonline.com/{0}";
string graphResourceId = "https://graph.microsoft.com";
string tenantId = "tenant id";
string clientId = "client Id";
string secret = "sercet key";
authority = String.Format(authority, tenantId);
AuthenticationContext authContext = new AuthenticationContext(authority);
var accessToken = authContext.AcquireTokenAsync(graphResourceId, new ClientCredential(clientId, secret)).Result.AccessToken;
var graphserviceClient = new GraphServiceClient(
new DelegateAuthenticationProvider(
requestMessage =>
{
requestMessage.Headers.Authorization = new AuthenticationHeaderValue("bearer", accessToken);

return Task.FromResult(0);
}));
var dic = new Dictionary<string, object> {{"@odata.type", "microsoft.graph.invitedUserMessageInfo"}};

Invitation invitation = new Invitation
{
InvitedUserEmailAddress = "email address",
InvitedUserMessageInfo = new InvitedUserMessageInfo{AdditionalData = dic },
InvitedUserDisplayName = "xxx",
SendInvitationMessage = false,
InviteRedirectUrl = "xxxxx"

};
var result = graphserviceClient.Invitations.Request().AddAsync(invitation).Result;

enter image description here

关于azure - 如何使用 Microsoft.Azure.ActiveDirectory.GraphClient sdk 以编程方式邀请 Azure AD 中的用户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48093480/

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