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
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
Hi Anonymous ,
It's glad to hear that your problem has been resolved. And thanks a lot for sharing the solution here, it will help the others in the community get the solution easily if they face the same problem with you. Much appreciated!
Best Regards