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

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

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

对于不向用户发送电子邮件的批量用户,azure 中有一个选项,即下载 Excel 模板并使用 [sendEmail] 列值填写 Excel 中的详细信息True 错误

enter image description here

enter image description here

现在我想将用户添加到 azure 广告中,而不使用 C# 代码发送电子邮件。谁能建议实现要求?

最佳答案

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

引用:https://learn.microsoft.com/en-us/graph/api/resources/invitation?view=graph-rest-1.0

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

{
  "invitedUserEmailAddress": "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="c0a7b5a5b3b4b5b3a5b280b3a1adb0aca5a4afada1a9aeeea3afad" rel="noreferrer noopener nofollow">[email protected]</a>",
  "inviteRedirectUrl": "https://sample.com",
  "sendInvitationMessage": false,
 }

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

话虽如此,现在您可以使用 GRAPH C# SDK 来通过上述请求来实现您的要求

引用号:https://learn.microsoft.com/en-us/graph/sdks/sdks-overview

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

public static void CreateB2BUser()
    {
    try
      {

        var invitation = new Invitation 
        { 
        SendInvitationMessage = false,
        InvitedUserEmailAddress = "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="0a7f796f784a796b677a666f24696567" rel="noreferrer noopener nofollow">[email protected]</a>",
        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 的身份验证和创建。

关于c# - 将 B2B 外部用户添加到 Azure AD,而不发送邀请电子邮件 C#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63226434/

相关文章:

azure - @azure/identitycredentials.getToken ('openid' )在配置了环境变量的情况下返回 null 而不是 DefaultAzureCredential() 的 token ?

azure - Terraform Azure AD Web 应用程序不会将客户端 ID 和密码传递到 Key Vault

Azure部署: Error while creating webjob schedule (400 Bad Request)

azure - 您可以确定 Azure 刷新 token 的到期日期吗

c# - 在 .NET Core 中连接到 Oracle 数据库时出现 Kerberos 错误

c# - 如何使用 LINQ 从两个列表中有效地选择某些项目

c# - 在c#中反序列化protobuf

python - 如何在 Azure 中检索客户端 ID 和 secret 以用于创建和销毁虚拟机?

.net - 如何通过 .net 上的多重身份验证使 OAuth2 适用于 Azure Active Directory?

c# - 从 C# 中的字符串解析 PointF?