3

We are using Azure Data Lake Gen1 as source in our Tabular model. We have deployed this model on on-prem server. Now, every time we have to manually refresh the credentials to process the model. We want to automate that. I have already tried following link.

https://blog.gbrueckl.at/2017/11/processing-azure-analysis-services-oauth-sources-like-azure-data-lake-store/

But gives following error

credentials provided cannot be used for the DataLake source

This is the credentials object that is getting created from script:

{
    "AuthenticationKind":  "OAuth2",
    "kind":  "DataLake",
    "path":  "https://mydatalake.azuredatalakestore.net/",
    "Expires":  "Thu, 21 Mar 2020 01:37:50 GMT",
    "AccessToken":  "",
    "RefreshToken":  ""
}

Code:

[string] $ClientID = ""
[string] $AASServerName = ""
[string] $AASDatabaseName = ""
[string] $CredentialName =""
[string] $Password = ""

Import-Module SqlServer

$authUrl = "https://login.microsoftonline.com/{tenantid}/oauth2/v2.0/token"
$body = @{ 
    "client_id" = $ClientID;  
    "scope" = "openid offline_access";
    "grant_type" = "password";
    "username" = $CredentialName
    "password" = $Password
}



Write-Output "Getting Authentication-Token ..." 
$adlsToken = Invoke-RestMethod -Uri $authUrl –Method POST -Body $body

$dtformat = "r"
$dateTime = Get-Date -f $dtformat 
$newdateTime=[datetime]::ParseExact($datetime,$dtformat,$Null).AddSeconds($adlsToken.expires_in).ToString($dtformat)

#modify the token so it can be used within our ADLS Datasource
$adlsToken | Add-Member -NotePropertyName "AuthenticationKind" "OAuth2"
$adlsToken | Add-Member -NotePropertyName "kind" "DataLake"
$adlsToken | Add-Member -NotePropertyName "path" "https://mydatalake.azuredatalakestore.net/"
$adlsToken | Add-Member -NotePropertyName "Expires" $newdateTime
$adlsToken | Add-Member -NotePropertyName "AccessToken" $adlsToken.access_token 
$adlsToken | Add-Member -NotePropertyName "RefreshToken" $adlsToken.refresh_token 

$adlsToken = $adlsToken | Select-Object -Property * -ExcludeProperty  scope,expires_in,ext_expires_in,token_type, id_token,refresh_token,access_token,token_type

Write-Output "Updating DataSource with latest token ..." 
#Update the DataSource with a valid Token
$updateDataSource = '{
"createOrReplace": {
"object": {
"database": "'+$AASDatabaseName+'",
"dataSource": "DataLake/https://mydatalake azuredatalakestore net/xyx/data"
},
"dataSource": {
"type": "structured",
"name": "DataLake/https://mydatalake azuredatalakestore net/xyx/data",
"connectionDetails": {
"protocol": "data-lake-store",
"address": {
"url": "https://mydatalake.azuredatalakestore.net"
}
},
"credential": ' + (ConvertTo-Json $adlsToken) + '
}
}
}'

 $updateDataSource

Invoke-ASCmd -Server $AASServerName -Database $AASDatabaseName -Query $updateDataSource



Write-Output "Start Processing <dataOnly> ..." 
$processObject = '
{
  "refresh": {
    "type": "dataOnly",
    "objects": [ {"database": "' + $AASDatabaseName + '"} ]
  }
}'
Invoke-ASCmd -Server $AASServerName -Database $AASDatabaseName -Query $processObject


Write-Output "Finished!"
chetan S
  • 31
  • 1
  • https://stackoverflow.com/questions/63520758/unable-to-get-refresh-token-of-https-management-azure-com-using-powershell Hi Chetan, have you found the solution of this problem, I have posted similar requirement in stackoverflow, but I haven't got any proper solution. If you have resolved, please help me out with your solution. – Ashish-BeJovial Aug 24 '20 at 12:07
  • Yes, I moved to .Net. This version did not work for me. – chetan S Mar 24 '21 at 04:21

0 Answers0