邀请用户为会员

时间:2018-05-07 08:30:25

标签: c# azure azure-active-directory azure-ad-b2b

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

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

2 个答案:

答案 0 :(得分: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;

测试结果:

enter image description here

从Azure门户网站检查:

enter image description here

<强>更新

从Azure门户添加权限

enter image description here

使用https://jwt.io/

检查访问令牌权限

enter image description here

<强> UPDATE2:

添加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>

答案 1 :(得分:1)

汤姆的第二个答案。

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

解决方案:

PowerShell的

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"}
Microsoft Graph API

npm install ./src/app/draggable --save