我正在尝试邀请Azure B2B Active目录中的用户。我无法使用Client SDK找到一种方法。
有可能这样做吗?
提前感谢您的帮助。 :)
答案 0 :(得分:0)
有可能这样做吗?
我无法找到邀请Microsoft.Azure.ActiveDirectory.GraphClient用户的方法。
但我们可以做到这一点 Microsoft.Graph。 Azure官方文档还建议您使用Microsoft Graph而不是Azure AD Graph API。
我们强烈建议您使用Microsoft Graph而不是Azure AD Graph API来访问Azure Active Directory资源。 https://docs.microsoft.com/en-us/azure/active-directory/develop/active-directory-graph-api
我也为它做了一个演示。我的工作正常。
在此之前,我在Azure目录中创建Web应用程序。向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;