Skip to content Skip to sidebar Skip to footer

Authentication Failed: Com.microsoft.identity.client.exception.msalclientexception: Missing Required Tokens Of Type: {0}

Implemented Azure B2C login. Suddenly app getting this error. unable to find where the issue is. can anyone help we are using below source: https://github.com/Azure-Samples/ms-iden

Solution 1:

I reproduced your issue and resolved it successfully.

It is because you didn't do the admin consent for the API permission on Azure portal.

Please see this line in the official sample code.

publicstaticList<String> getScopes() {
        returnArrays.asList(
                "https://fabrikamb2c.onmicrosoft.com/helloapi/demo.read");
    }

This sample sets the scope as https://fabrikamb2c.onmicrosoft.com/helloapi/demo.read so that it can acquire an access token for this API.

Firstly, you should add an app registration which represents your web API and expose the API by following Quickstart: Configure an application to expose a web API.

Secondly, you need to add the API permission in your client app registration (its client id is configured in auth_config_b2c.json file) by following Quickstart: Configure a client application to access a web API.

Now the most important thing is doing the admin consent in Azure portal:

enter image description here

You can click on the permission in Azure portal to see it.

enter image description here

Modify the scope in code to your own scope/permission.

publicstaticList<String> getScopes() {
        returnArrays.asList(
                "https://allentest001.onmicrosoft.com/api/demo.read");
    }

With all the settings configured, we can acquire the access token after signing in.

enter image description here

Post a Comment for "Authentication Failed: Com.microsoft.identity.client.exception.msalclientexception: Missing Required Tokens Of Type: {0}"