Forum Discussion
How to implement getNewUserAccessToken() function for PowerBI embedded
- Anonymous4 years ago
Hi Anonymous , I have created the PowerBI embedded by using creating a portal using the Power Platform. There I used the procedure mentioned here: Set up Power BI integration - Power Apps | Microsoft Docs
It was not possible to create the refresh token, because the token aquisition is done by the Power Platform.
However it was possible to extend the tokenlifetime by creating an Azure AD policy and assign it to the Power BI service account. I was struggling with it because I tried to extend the tokenlifetime of the PowerApp account that was registered in my tenant, that didn't solve the issue. The embedded PowerBI session still expired after hour.
Below the PowerShell script that I have used to extend the token lifetime to 23 hours and it works as expected.
# Login Connect-AzureAD Get-AzureADServicePrincipal -filter "DisplayName eq 'Power BI Service'" -Verbose #Define policy for 23 hours $policy = New-AzureADPolicy -Definition @('{"TokenLifetimePolicy":{"Version":1,"AccessTokenLifetime":"23:00:00"}}') -DisplayName "PowerBI-access-token-Policy" -IsOrganizationDefault $false -Type "TokenLifetimePolicy" # Get ID of the service principal $sp = Get-AzureADServicePrincipal -Filter "DisplayName eq 'Power BI Service'" # Assign policy to the id of the service principal found in the previous step Add-AzureADServicePrincipalPolicy -Id $sp.ObjectId -RefObjectId $policy.id
The reply marked as the solution doesn't do what the OP asked for -- refreshing the access token. It's a different approach, extending the lifetime of the original access token. It's frustrating coming to this page looking for help on how to refresh the access token, and the 'solution' is something totally different -- and something that doesn't work in all situations.
I'd encourage moderators to not allow marking a question 'solved' when it has not, in fact, been solved. The answer is at best a workaround that achieves the same goal, without ever answering the original question. The OP asked for how to implement getNewUserAccessToken(), specifically. The 'answer' is something else entirely.