Forum Discussion
PowerBI-JavaScript setAccessToken doesn't work
- 8 years ago
Hi bboy81905,
How you can see at the code in the lib, when you set the new access token it send it to the service, and aparently does not store your token:
Embed.prototype.setAccessToken = function (accessToken) { var embedType = this.config.type; return this.service.hpm.post('/' + embedType + '/token', accessToken, { uid: this.config.uniqueId }, this.iframe.contentWindow) .then(function (response) { return response.body; }) .catch(function (response) { throw response.body; }); };And when you call getAccessToken it will return the token wich you provided first in the config object (if it is lazy evaluated, as I think it is):
Embed.prototype.getAccessToken = function (globalAccessToken) { var accessToken = this.config.accessToken || this.element.getAttribute(Embed.accessTokenAttribute) || globalAccessToken; if (!accessToken) { throw new Error("No access token was found for element. You must specify an access token directly on the element using attribute '" + Embed.accessTokenAttribute + "' or specify a global token at: powerbi.accessToken."); } return accessToken; };I think you need to change the code at the "setAccessToken" function and add a line like:
this.config.accessToken = accessToken;
It will probably solve your problem but i dont think it is the right way to do.
dp001 me too did you get it work ?
Yes, I got it work.
I get the new token every 55minutes in server and set it in a hidden field.
In client side, set the new token every 56 minutes
report.setAccessToken(newToken)
- ansh24256 years agoRegular Visitor
Hi,
I am trying to refresh token after 55 mins.
I got the new token by using GenerateTokenAsync() method in c# and passed it to js file and I used setAccessToken(newToken) method there.
But my embedded report is not getting updated with the new token.
Can you please tell me how you got the new token from server side?