DEV Community 👩‍💻👨‍💻

Cover image for Create Invite on Azure B2C with Graph API

Posted on

Create Invite on Azure B2C with Graph API

Photo by Diana Polekhina on Unsplash

While reading this great post from Damien Bod, i had the idea to do the same for inviting users in Azure B2C.

Configure Permissions in Azure

Following the doc, we require the following:

  • permission User.Invite.All (permission type : Application) and grant Admin Consent

Image description

Get from your application:

  • your tenant ID
  • your Application ID
  • a Secret Value


Once you have configured the permission, you can use the following code (with you IDs / Secret):

    string[] scopes = new string[1] { ""};
    var tenantId = "<YOUR_TENANT_ID>";

    // Values from app registration
    var clientId = "<YOUR_APPLICATION_ID>";
    var clientSecret = "<YOUR_SECRET>";

    var options = new TokenCredentialOptions
        AuthorityHost = AzureAuthorityHosts.AzurePublicCloud,   

    var clientSecretCredential = new ClientSecretCredential(
        tenantId, clientId, clientSecret, options);

    var _graphServiceClient = new GraphServiceClient(clientSecretCredential, scopes);

    var invitation = new Invitation()
        InvitedUserEmailAddress= "<EMAIL>",
        InviteRedirectUrl ="<YOUR_APPLICATION_URL>",
        SendInvitationMessage = false,

Enter fullscreen mode Exit fullscreen mode

using the following NuGet packages :

Hope this helps !

Top comments (0)

🌚 Browsing with dark mode makes you a better developer.

It's a scientific fact.