cancel
Showing results for 
Search instead for 
Did you mean: 

Fabric is Generally Available. Browse Fabric Presentations. Work towards your Fabric certification with the Cloud Skills Challenge.

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
PBI November 2023 Update Carousel

Power BI Monthly Update - November 2023

Check out the November 2023 Power BI update to learn about new features.

Community News

Fabric Community News unified experience

Read the latest Fabric Community announcements, including updates on Power BI, Synapse, Data Factory and Data Activator.

Power BI Fabric Summit Carousel

The largest Power BI and Fabric virtual conference

130+ sessions, 130+ speakers, Product managers, MVPs, and experts. All about Power BI and Fabric. Attend online or watch the recordings.