March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early bird discount ends December 31.
Register NowBe 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
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!
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
The following example from documentation is what I used as a template for writing my function:
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
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!