Azure AD B2C token issue while calling Microsoft Graph API using Azure AD B2C token with grant type ROPC

Sateesh Kumar Sharma 21 Reputation points
2021-12-13T14:27:12.563+00:00

Hi Team ,

We are planning to automate Application registration and creating credentials and managing the APIs using REST API Call.
First automated call we have considered to invoke MS Graph API - https://graph.microsoft.com/v1.0/applications to register the Application on Azure AD B2C tenant .

Step 1- I have created Azure AAD B2C tenant.
Step 2- created User flow (Sign in using resource owner password credentials (ROPC)
Step 3-created policy(Local IDP)
step4- Register the Application, get the client id .
step 5- Generate the Access token using endpoint :
https://abc.b2clogin.com/cde.onmicrosoft.com/B2C_1\_ABC/oauth2/v2.0/token
grant_type: password
scope : openid ************ offline_access
username: *********
password: *****************
response_type: token

Response 200 OK with access token .

Now When I am trying to call - https://graph.microsoft.com/v1.0/applications
with access token which I received in last call getting error with 401 Unauthenticated :
"error": {
"code": "InvalidAuthenticationToken",
"message": "Invalid x5t claim.",
Can you please look into this and let me know what should I do now to call /applications endpoint and how we can manage MS Graph API from Azure AD B2C tenant .

Your help will be much appreciated :)

Sateesh Sharma

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
10,592 questions
Microsoft Entra External ID
Microsoft Entra External ID
A modern identity solution for securing access to customer, citizen and partner-facing apps and services. It is the converged platform of Azure AD External Identities B2B and B2C. Replaces Azure Active Directory External Identities.
2,639 questions
Microsoft Entra ID
Microsoft Entra ID
A Microsoft Entra identity service that provides identity management and access control capabilities. Replaces Azure Active Directory.
19,473 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. AmanpreetSingh-MSFT 56,306 Reputation points
    2021-12-15T05:40:45.613+00:00

    Hi @Sateesh Kumar Sharma • Thank you for reaching out.

    As of now, B2C applications do not support graph operations. This means if you register an app in the B2C tenant using the option highlighted below, you won't be able to perform any graph operations using that app.

    157699-image.png

    Reason: In your case, you need these Permissions to register applications but if you go to the API permissions blade of your application, you won't see these permissions and only openID and offline_access are the available permissions, as shown below:

    157689-image.png

    Currently, you can use the standard Azure AD functionality of B2C tenant for this purpose.

    1. Register the application using any of the first two options (single tenant or multitenant app)
    2. In the application, grant admin consent to these Permissions
    3. Acquire access token using below parameters, and use the token as bearer token to register the applications via graph api. POST https://login.microsoftonline.com/your_tenant.onmicrosoft.com/oauth2/v2.0/token client_id:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
      grant_type:password
      scope:https://graph.microsoft.com/.default
      username:username@your_tenant.onmicrosoft.com
      password:********

    -----------------------------------------------------------------------------------------------------------

    Please "Accept the answer" if the information helped you. This will help us and others in the community as well.