Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
506 views
in Technique[技术] by (71.8m points)

msal.js - I can't get accessToken via requireTokenSilent @azure/msal-browser

I'm recently trying to get accessToken from AzureADB2C with "acquireTokenSilent Flow". I'm using @azure/msal-browser and my app is React. So, now my code is like this.

    const getTokenRedirect = async (account, apiConfig) => {
        publicClient.acquireTokenSilent({
            scopes: apiConfig.scopes,
            account: account,
            authority: apiConfig.authority,
        }).then(tokenResponse => {
            console.log(tokenResponse);
            setAccessToken(tokenResponse.accessToken);
        }).catch(async (error) => {
            console.log(error);
        });

    }

Then this code response refresh token, not accessToken. I have no idea why acquireTokenSilent didn't response accessToken. I did get idToken from ADB2C. And another sample (msal.js vanilla Sample) got accessToken. So I think B2C setting is correct. My code has some problems.

Does anybody know solution for like this.

question from:https://stackoverflow.com/questions/65641421/i-cant-get-accesstoken-via-requiretokensilent-azure-msal-browser

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

This is caused by the version of msal-browser, and the accessToken cannot be returned in versions after 2.1.0.

It is a known issue of the B2C service currently tracked here, and Microsoft should fix it in the future.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...