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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch 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
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!

November Carousel

Fabric Community Update - November 2024

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

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.