Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

How to implement getNewUserAccessToken() function for PowerBI embedded

On Microsoft docs you can find an example how to refresh the powerbiembedded token to overcome the 1 hour lifetime. Refresh the access token in Power BI embedded analytics | Microsoft Docs   Howev...
  • Anonymous's avatar
    Anonymous
    4 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