cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
arishidalgo
Regular Visitor

Parameters to pass get access token using acquireTokenSilent (MSAL.js)

Hi Guys, 

 

Newbie here for both Power BI and Javascript. Based on my code below, it seems it gives me an 'access' code but when I use it as a bearer token to get the embed token it throws an 403 forbidden error when I try/simulate it via Postman. However, if I get the access token via Postman I can use the returned access token and use that to get the embed token. 

 

Programatically:

// Add here scopes for access token to be used 
        const tokenRequest = {
            scopes: ["openid", "user.read"]
        };

        const myMSALObj = new Msal.UserAgentApplication(msalConfig, function (errorDes, token, error, tokenType, instance) {
            // this callback is called after loginRedirect OR acquireTokenRedirect. It's not used with loginPopup,  acquireTokenPopup.
            if (error) {
                console.log(error + ": " + errorDes);
            }
            else
                console.log("Token type = " + tokenType);

        });

        debugger;
        myMSALObj.loginPopup(loginRequest)
            .then((loginResponse) => {
                //Login Success callback code here
                debugger;
                console.log("id_token acquired at: " + new Date().toString());
                console.log(loginResponse);
                myMSALObj.acquireTokenSilent(tokenRequest).then(function (accessTokenResponse) {
                    // Acquire token silent success
                    // Call API with token
                    debugger;
                    let accessToken = accessTokenResponse.accessToken;

Postman (see attachment)Postman.PNG

 

0 REPLIES 0

Helpful resources

Announcements
PBI_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

Get Ready for Power BI Dev Camp

Microsoft named a Leader in The Forrester Wave

Microsoft received the highest score of any vendor in both the strategy and current offering categories.

Get Ready for Power BI Dev Camp

Power BI Dev Camp - September 30th, 2021

Mark your calendars and join us for our next Power BI Dev Camp!

PowerPlatform 768x460.png

Microsoft Learn

Check out our new Discover Your Career Path blog post series and get all the details.

Top Kudoed Authors