Reputation: 5689
I am trying to get an access token using MSAL and React using Azure B2C. I have configured B2C applications with permissions, scope, and setup a user flow, and I am able to login and get an id_token
, but the AuthenticationResult
never contains an access_token
and is never set on subsequent requests.
After logging in, here is code to get an access_token:
export async function getAccessToken(){
const account = msalInstance.getActiveAccount();
const accessTokenRequest = {
scopes: ["https://<my api uri>/api.full_access"],
account: account,
}
var response = await msalInstance.acquireTokenSilent({
accessTokenRequest,
account: account
});
return response;
}
@azure/msal-browser = ^3.0.1 @azure/msal-react = 2.0.1
Upvotes: 0
Views: 1099
Reputation: 818
You need to now call initialize since version 2 if doing this outside of react.
I.e.
const msalInstance = new PublicClientApplication(msalConfig)
await msalInstance.initialize()
Upvotes: 0