Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
alexandruMP
Regular Visitor

OAuth2 Dataset Credentails Update after take over fails

I am trying to take over a dataset that has data in ADX and although the take over is successful, the dataset credentials need to be updated.

*SPN and user have full admin rights on workspace and Adx cluster

I have the following script:

 

 

 

 

 

$PWord = ConvertTo-SecureString -String $clientSecret -AsPlainText -Force
$Credential = New-Object -TypeName "System.Management.Automation.PSCredential" -ArgumentList $clientId, $PWord


Connect-PowerBIServiceAccount -Tenant $Tenant -ServicePrincipal -Credential $Credential



################ Taking over dataset as SPN  ####################

Invoke-PowerBIRestMethod -Url "groups/$($Workspace)/datasets/$($Dataset)/Default.TakeOver" -Method POST -Body "" 

####################  "Resetting" Credentials towards datasource of dataset ####################


# Apparently we need the id of the "Gateway" that the datasets resides within. If it doesn't have a gateway (if it's a cloud data source for instance) it uses Microsofts "Default" gateway. We need its ID.
$BounGateway=Invoke-PowerBIRestMethod -Url "groups/$($Workspace)/datasets/$($Dataset)/Default.GetBoundGatewayDataSources" -Method GET | ConvertFrom-Json 

$Accesstoken = Get-PowerBiAccessToken

$Body =
@{
credentialDetails = @{
credentialType = "OAuth2";
credentials = "{`"credentialData`":[{`"name`":`"accessToken`", `"value`":`"$($Accesstoken.Authorization)`"}]}";
encryptedConnection = "Encrypted";
encryptionAlgorithm = "None";
privacyLevel = "None"
}
} | ConvertTo-Json

Write-Output $Body

Invoke-PowerBIRestMethod -Url "gateways/$($BounGateway.value.gatewayId)/datasources/$($BounGateway.value.id)" -Method PATCH -Body $Body | ConvertFrom-Json 

 

 

 

 

 

 
The body of the request I have created it using the example from here: https://docs.microsoft.com/en-us/rest/api/power-bi/gateways/update-datasource#oauth2-credentials-exa...

Finally, as you can see in the script I use an SPN and an access token for it and the last PATCH request returns: 

 

 

 

 

 

Invoke-PowerBIRestMethod:
Line |
  44 |  Invoke-PowerBIRestMethod -Url "gateways/$($BounGateway.value.gatewayI …
     |  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | One or more errors occurred. (Response status code does not indicate success: 400 (Bad Request).)

 

 

 

 

 


I tried to use an actual user to do this operation, but the PATCH request with the user access token returns 401:

 

 

 

 

 

Invoke-PowerBIRestMethod:
Line |
  14 |  Invoke-PowerBIRestMethod -Url "gateways/$($BounGateway.value.gatewayI …
     |  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | One or more errors occurred. (Response status code does not indicate success: 401 (Unauthorized).)

 

 

 

 

 

 

This story seems to be related to this ,  but it is unanswered for OAuth2.

I was wondering is somebody has figured what the issue is, as far as I have searched the only working credential types are "key" and "basic".

 

@NandanHegde @Jayendran 

1 REPLY 1
V-lianl-msft
Community Support
Community Support

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.