sdk以编程方式在Azure

sdk以编程方式在Azure

本文介绍了如何使用Microsoft.Azure.ActiveDirectory.GraphClient sdk以编程方式在Azure AD中邀请用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图邀请Azure B2B Active目录中的用户.我找不到使用Client SDK的方法.

I am trying to invite a user in Azure B2B Active directory. I am not able to find a way to do that using Client SDK.

有没有办法做到这一点?

Is there a possible way to do that?

非常感谢您的帮助. :)

Thanks for your help in advance. :)

推荐答案

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

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

But we could do that withMicrosoft.Graph. And Azure official document also recommend that you use Microsoft Graph instead of Azure AD Graph API.

我也为此做了一个演示.我可以正常工作.

I also do a demo for it. I works correctly on my side.

在此之前,我在Azure目录中创建Web应用程序.将必需的邀请来宾用户添加到组织中对Microsoft Graph的权限

Before that I create the Web application in the Azure directory. Add required Invite guest users to the organization permission for Microsoft Graph

演示代码:

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;

这篇关于如何使用Microsoft.Azure.ActiveDirectory.GraphClient sdk以编程方式在Azure AD中邀请用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-29 13:34