Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
etsygankov
Frequent Visitor

Automatic refresh of Access Token doesn't work

I am "emedding for organization" and trying to use the automatic refresh of access token described here by providing eventHooks.accessTokenProvider.

 

Here is the code that does embedding (notice accessTokenProvider and getNewToken implementation):

 

 

 

let getNewToken = async function () {
            
    var result = await $.ajax({
        type: "POST",
        url: "/gettoken"
    });

    return result.Token;
}

let config = {
    type: type,
    tokenType: models.TokenType.Aad,
    accessToken: common.accessToken,
    embedUrl: embedUrl,
    id: embedId,
    settings: settings,
    eventHooks: {
        accessTokenProvider: getNewToken
    }
};

 

 

 

Report loads fine and then I see periodic calls to /powerbi/refresh/subscribe in Fiddler. They complete with HTTP 200.

 

After some time, the access token expires, and I can see that PowerBI calls my getNewToken function and that the new refresh token is being returned -- the Chrome debugger shows the updated access token on line "return result.Token". 

 

But subsequent calls to /powerbi/refresh/subscribe still have the old access token in Authorization: Bearer and fail with HTTP 401.

 

Does anybody know why the updated access token returned from accessTokenProvider is not being used for further ajax calls to PowerBI?

 

Do you have any working examples of implementing accessTokenProvider?

 

Thank you!

 

 

3 REPLIES 3
v-shex-msft
Community Support
Community Support

Hi @etsygankov,

I'm not so sure if the issue is caused by the compatibility of the ajax function and accessTokenProvider, have you tried to use other types of functions instead?

In addition, you can also take a look at the following document if it helps:

Refresh the access token in Power BI embedded analytics | Microsoft Docs

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

The following example from documentation is what I used as a template for writing my function:

 

etsygankov_0-1652358338684.png

Do you know if "return token" is a string or a type? If a type, is there documentation on what that type should be?

 

Thanks

HI @etsygankov,

The token should be a variable defined with string type in the function and used to get the token string from API response.
Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

Find out what's new and trending in the Fabric Community.

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

Check out the November 2024 Power BI update to learn about new features.

Top Kudoed Authors