将B2B外部用户添加到Azure AD,而无需发送邀请电子邮件C#

时间:2020-08-03 08:54:11

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

我们正在使用azure b2b邀请外部用户访问租户中的应用程序。邀请
对于新用户,我们将在接受用户访问应用程序后发送b2b邀请(使用带有自定义邮件格式的c#代码)。

对于不向用户发送电子邮件的批量用户,天蓝色中有一个选项,即下载excel模板并使用[ sendEmail ]列值填充excel中的详细信息

enter image description here

enter image description here

现在,我想在不使用C#代码发送电子邮件的情况下将用户添加到天蓝色的广告中。有人可以建议达到要求吗?

1 个答案:

答案 0 :(得分:2)

您可以使用Graph来创建B2B用户,而无需邀请。

参考:https://docs.microsoft.com/en-us/graph/api/resources/invitation?view=graph-rest-1.0

POST https://graph.microsoft.com/v1.0/invitations

{
  "invitedUserEmailAddress": "guestuser@sampledomain.com",
  "inviteRedirectUrl": "https://sample.com",
  "sendInvitationMessage": false,
 }

您可能可以尝试相同的操作,然后在图形浏览器中查看它是否满足您的要求: https://developer.microsoft.com/en-us/graph/graph-explorer

话虽如此,现在您可以使用GRAPH C#SDK来满足上述要求

参考:https://docs.microsoft.com/en-us/graph/sdks/sdks-overview

要使用C#使用GraphClient添加不带电子邮件的外部用户,如下所示:

public static void CreateB2BUser()
    {
    try
      {

        var invitation = new Invitation 
        { 
        SendInvitationMessage = false,
        InvitedUserEmailAddress = "user@sample.com",
        InvitedUserType = "Member",
        InviteRedirectUrl = "https://sampledomain.com",
        InvitedUserDisplayName = "Sample User",
        };
                 
      graphClient.Invitations.Request().AddAsync(invitation);
      }
     catch (ServiceException ex)
      {
                        Console.WriteLine($"Error Creating User : {ex.Message}")
      }
    }

This article可以帮助您快速进行GraphClient的身份验证和创建。