How to invite users programmatically on Azure AD B2C on my Single Page Application?

Clarence Koh 0 Reputation points
2023-04-28T15:17:06.4366667+00:00

I've seen a couple of questions being asked about this but the answers have not been helpful for me.

I have set up a working sign in flow using custom policies in Azure AD B2C for my Single Page Application (written in React JS). A user can only explore the different pages in my application (i.e. routes are protected by checking if the user has signed in already in Azure AD B2C).
Here's my current flow:

  1. When the user enters the link to my website, I immediately direct them to the sign in flow in Azure AD B2C (i.e. loginRediect is called.)
  2. Upon successful login, user is redirected back to my application. There is a payload with the following keys that I can retrieve when the user is re-directed to my application. Here are the keys in the payload, authorityuniqueIdtenantIdscopesidTokenClaimsaccount , etc. (I can include more keys if it helps to answer my query). This is retrieved via a callback called on the msalInstance
  3. Now from within my application, I would like to allow users to invite other users by providing their email address, so that they can use my application as well.

What I have tried to do is to retrieve an accessToken to call the Microsoft Graph API for inviting users (https://learn.microsoft.com/en-us/graph/api/invitation-post?view=graph-rest-1.0), (I allowed User.Invite.All in my registered app for my Single Page Application in the API Permissions tab.) But when I run acquireTokenSilent to try to request the accessToken to call the Microsoft Graph API, I get an <empty string> as my accessToken. So there's no way I can even attempt to call the Invitation API.

How then can I invite new users to use my application?

Microsoft Security Microsoft Graph
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Antonio 250 Reputation points Microsoft External Staff
    2023-05-05T21:56:14.0566667+00:00

    Hi Clarence Koh,

    Thanks for posting on Q&A forum. As pre documentation for Supported Azure Active Directory features in Azure AD B2C (See below).

    For external invites in B2C you can use user flows and custom policies to manage user

    Inviting External Identities guests You can invite guest users and configure External Identities features such as federation and sign-in with Facebook and Google accounts. You can invite only a Microsoft account or an Azure AD user as a guest to your Azure AD tenant for accessing applications or managing tenants. For consumer accounts, you use Azure AD B2C user flows and custom policies to manage users and sign-up or sign-in with external identity providers, such as Google or Facebook.

    Please see this great example on GitHub of how to implement user invite flow in Azure B2C for a sample console app (.Net core) demonstrating how to send sign-up email invitation.

    SignUp with email invitation

    --please don't forget to upvote and Accept as answer if the reply is helpful--


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.