access token through msal

Iheb jendoubi 40 Reputation points
2023-10-13T11:47:01.5333333+00:00
export const b2cPolicies = {
    names: {
        signUpSignIn: 'B2C_1_susi1',
        forgotPassword: 'B2C_1_reset',
        editProfile: 'B2C_1_edit_profile',
        
    },
    authorities: {
        signUpSignIn: {
            authority: 'https://*****.b2clogin.com/******.onmicrosoft.com/b2c_1_susi1',
        },
        forgotPassword: {
            authority: 'https://*****.b2clogin.com/*****.onmicrosoft.com/B2C_1_reset',
        },
        editProfile: {
            authority: 'https://*****.b2clogin.com/*****.onmicrosoft.com/b2c_1_edit_profile',
        },
    
    },
    authorityDomain: '*****.b2clogin.com',
};
export const msalConfig = {
    auth: {
        clientId: '***********', // This is the ONLY mandatory field that you need to supply.
        authority: b2cPolicies.authorities.signUpSignIn.authority, // Choose SUSI as your default authority.
        knownAuthorities: [b2cPolicies.authorityDomain], // Mark your B2C tenant's domain as trusted.
        redirectUri: '/', 
        postLogoutRedirectUri: '/home', 
        navigateToLoginRequestUrl: false , 
    },
    cache: {
        cacheLocation: 'sessionStorage', // Configures cache location. "sessionStorage" is more secure, but "localStorage" gives you SSO between tabs.
        storeAuthStateInCookie: false, // Set this to "true" if you are having issues on IE11 or Edge
    },
}
export const protectedResources = {
    apiSpeech: {
        endpoint: 'http://localhost:8080/api/speech',
        scopes: {
            read: ['https://******.onmicrosoft.com/**********/Speech.Read'],
            write: ['https://xgolorg.onmicrosoft.com/********/Speech.ReadWrite'],
            
        },
    },
};

this is my auth config file . 
this is my index.js :
const msalInstance = new PublicClientApplication(msalConfig);

<React.StrictMode> 
   <BrowserRouter>
   <PersistGate persistor={persistor}>      
  <App instance={msalInstance} />       
 </PersistGate>            
  </Provider>   
 </BrowserRouter>     
the problem that i am facing here is normally in event.payload i found my access token and the scopes , but in my case access token is empty ad scopes is an empty array 
Microsoft Entra ID
Microsoft Entra ID
A Microsoft Entra identity service that provides identity management and access control capabilities. Replaces Azure Active Directory.
22,540 questions
{count} votes

1 answer

Sort by: Most helpful
  1. 2023-10-29T06:46:13.16+00:00

    Hello @Iheb jendoubi , for how to request and acquire an Azure AD B2C access token using MSAL take a look to Acquiring an Access Token. The protectedResources element is reminicent of the protectedResourceMap property found in the MSAL Angular library, however the latter element is not available for MSAL React.

    Let us know if you need additional assistance. If the answer was helpful, please accept it and rate it so that others facing a similar issue can easily find a solution.

    0 comments No comments

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.