microsoft / powerbi-client-angular

Power BI Angular component. This library lets you embed Power BI report, dashboard, dashboard tile, report visual, or Q&A in your Angular application.
Other
134 stars 63 forks source link

Refresh Token #29

Open daniel-seitz opened 2 years ago

daniel-seitz commented 2 years ago

According to the docs we have to implement functionality to refresh the token automatically.

Is there / do you / could you have any plans to implement this functionality on this package?

Would be nice if we could subscribe to a method in this package instead of everyone writing their own manual solution.

jaspreet1234567 commented 9 months ago

@daniel-seitz - Did you find any solution to this?

daniel-seitz commented 9 months ago

@jaspreet1234567 yes, I wrote it myself. Take the time of expiry, I subtracted some minutes and request a new token then.

jaspreet1234567 commented 9 months ago

@daniel-seitz - Thanks for the info. I did the same but unbale to update the token in power-bi. How you update the new token with i-frame?

daniel-seitz commented 9 months ago

Ok, the whole process:

 <powerbi-report
    [embedConfig]="embedConfig"
    [cssClassName]="'embedded-report'"
    [phasedEmbedding]="false"
    [eventHandlers]="eventHandlers"
    ></powerbi-report>

we hook into the rendered event:

get eventHandlers(): Map<string, EventHandler|null> {
    return new Map([
      ['loaded', () => { ... }],
      ['pageChanged', (event: any) => { ... }],
      ['rendered', () => {
// HERE
      }],
      ['error', (error: any) => { ...  }]
    ])

Of course, instead of HERE we call a function (that also gets called on the document:visibilitychanged event - when the tab is switched to and showing the report again.)

the logic is somehow like this:

Thats it.

Regarding your answer: You just need to replace the embedConfig with a new reference, not just update the accessToken property.

jaspreet1234567 commented 9 months ago

Thanks @daniel-seitz for the quick response and solution. Will try it and let you know. I think it will work.

jaspreet1234567 commented 7 months ago

Hi @daniel-seitz - Regarding your text: You just need to replace the embedConfig with a new reference, not just update the accessToken property.

Do we just need to update the access token property like: embedConfig.accessToken with new token OR need to create new embedConfig object and assign again to Input property like: [embedConfig]="embedConfig"