2

我正在尝试使用一些新功能更新我现有的应用程序。应用程序使用 Azure B2B API 并邀请用户作为来宾。它运作良好,但它会导致一些在其租户中标记为已掌握的电子邮件出现问题。

有没有办法邀请用户类型=会员的用户?

4

2 回答 2

2

有没有办法邀请用户类型=会员的用户?

是的,我们可以使用Microsoft.Graph做到这一点。默认类型是Guest,我们可以用下面的代码来改变它。我使用 Microsoft.Graph 权限对其进行测试:Directory.ReadWrite.All

 string authority = "https://login.microsoftonline.com/{0}";
 string graphResourceId = "https://graph.microsoft.com";
 string tenantId = "xxxxxx";
 string clientId = "xxxxxx";
 string secret = "xxxxxx";
 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",
                InvitedUserMessageInfo = new InvitedUserMessageInfo { AdditionalData = dic },
                InvitedUserDisplayName = "tomsun-member",
                SendInvitationMessage = false,
                InviteRedirectUrl = "http://localhost",
                InvitedUserType = "Member" //Change the Invited User Type 
            };
            var result = graphserviceClient.Invitations.Request().AddAsync(invitation).Result;

测试结果:

在此处输入图像描述

从 Azure 门户检查它:

在此处输入图像描述

更新:

从 Azure 门户添加权限

在此处输入图像描述

使用https://jwt.io/检查访问令牌权限

在此处输入图像描述

更新2:

添加 packages.config 文件。

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="Microsoft.Graph" version="1.9.0" targetFramework="net471" />
  <package id="Microsoft.Graph.Core" version="1.9.0" targetFramework="net471" />
  <package id="Microsoft.IdentityModel.Clients.ActiveDirectory" version="3.19.4" targetFramework="net471" />
  <package id="Newtonsoft.Json" version="11.0.2" targetFramework="net471" />
  <package id="System.IO" version="4.3.0" targetFramework="net471" />
  <package id="System.Net.Http" version="4.3.3" targetFramework="net471" />
  <package id="System.Runtime" version="4.3.0" targetFramework="net471" />
  <package id="System.Security.Cryptography.Algorithms" version="4.3.1" targetFramework="net471" />
  <package id="System.Security.Cryptography.Encoding" version="4.3.0" targetFramework="net471" />
  <package id="System.Security.Cryptography.Primitives" version="4.3.0" targetFramework="net471" />
  <package id="System.Security.Cryptography.X509Certificates" version="4.3.2" targetFramework="net471" />
</packages>
于 2018-05-07T10:00:05.917 回答
1

只是对汤姆的第二个答案。

是的,您可以邀请用户成为您租户的成员。但除非必要,否则我不建议您这样做。

解决方案:

通过 PowerShell

New-AzureADMSInvitation -InvitedUserEmailAddress "test@contoso.com" -InviteRedirectUrl https://myapps.microsoft.com -InvitedUserDisplayName 'TestUser' -InvitedUserMessageInfo $messageInfo -InvitedUserType member -SendInvitationMessage $true

通过 Microsoft 图形 API

POST https://graph.microsoft.com/beta/invitations

Content-Type: application/json

Content-Length: 161

{"invitedUserEmailAddress":"test@contoso.com","sendInvitationMessage":true,"inviteRedirectUrl":"http://myapps.onmicrosoft.com","invitedUserType":"member"}
于 2018-05-07T10:01:17.030 回答