1
votes

We are using azure b2b for inviting the external users to access our applications in the Tenant. For inviting
For new users, we are sending the b2b invite(using c# Code with customized mail format), upon acceptance users are able to access the application.

For bulk user without sending email to user, there is an option in the azure, i.e to download the excel template and filling the details in the excel with column [sendEmail] values True or False

enter image description here

enter image description here

Now I want to add the user to the azure ad without sending the email using C# code. Can anyone suggest to achieve the requirement?

1

1 Answers

2
votes

You could use the Graph in order to create B2B users without invitation.

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

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

{
  "invitedUserEmailAddress": "[email protected]",
  "inviteRedirectUrl": "https://sample.com",
  "sendInvitationMessage": false,
 }

You could probably experiment the same action and see whether it meets your requirement in the graph explorer : https://developer.microsoft.com/en-us/graph/graph-explorer

Having said that, Now you can use the GRAPH C# SDK in order to achieve your requirement using the above request

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

To add a External user without the email using GraphClient using C# would be like below :

public static void CreateB2BUser()
    {
    try
      {

        var invitation = new Invitation 
        { 
        SendInvitationMessage = false,
        InvitedUserEmailAddress = "[email protected]",
        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 can help you to get a quickstart with the authentication and creation of the GraphClient.