Forum Discussion
Update Credential to OAUTH2 type via REST API
I also tried the below scenarios wherein :
Initially generated the access token for the user :
$password = "” | ConvertTo-SecureString -asPlainText -Force $username = "" $credentialSelf = New-Object System.Management.Automation.PSCredential($username, $password)
Login-PowerBI -Credential $credentialSelf
$headers = Get-PowerBIAccessToken
$accessToken = $headers.Values -replace "Bearer ", "" |
Then implemented the below code to update the cred:
$credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList "<<Client ID>>", $clientsec $workspace =Get-PowerBIWorkspace -Name $workspacename $workspace
foreach($dataset in $datasets){ }
|
I referred the below link for the logic:
which was succesful for key and basic auth but unable to update for OAuth.
So can someone help me with that?
Jayendran : I referred to your code for Power BI automation but it had only cred update via basic auth.
So can you please help me with this 🙂
Hi NandanHegde
You wrote it was succesful for key and basic. Can you share your code for key? I got it working for basic, but it won't work for key.
I used this code for 'basic':
$UpdateUserCredentialBasic = @{
credentialType ="Basic"
basicCredentials = @{
username= '$(username)'
password= '$(password)'
}} | ConvertTo-Json;
Thanks in advance. Unfortunately I cannot help you with your problem.
- NandanHegde6 years agoSuper User
Hi MGroeneveld :
Please refer to the below code for key pair:
$UpdateUserCredential =
@{
credentialDetails = @{
credentialType = "Key";
credentials = "{`"credentialData`":[{`"name`":`"key`", `"value`":`"$(key)`"}]}";
encryptedConnection = "Encrypted";
encryptionAlgorithm = "None";
privacyLevel = "None"
}
} | ConvertTo-Jsonwhere $(key) is the access key passed as a parameter in Azure devops
Hope this provides you a clarity
- MGroeneveld6 years agoFrequent Visitor
Thanks for the reply. I used the code as you suggested. The pipeline deploys succesful, however the credentials aren't properly updated. On the powerBI website, I still get the message that the credentials of one of my datasources are missing.
Do I miss something else? Do I need to change some policies of access control settings?