0
votes

i want to connect to Azure Data Catalog RestAPI using power shell script and below is my script which failed to run.

Get an Access Token with ADAL

$authContext = New-Object Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext ("{0}" -f $login)

$authenticationResult = $authContext.AcquireToken($ResourceId, $ClientId, $redirectUri, $PromptBehavior);

($token = $authenticationResult.AccessToken) | Out-File $accessToken

$authContext.AcquireToken($ResourceId, $ClientId, $redirectUri, $PromptBehavior)


$headers = @{ 

    "Authorization" = ("Bearer {0}" -f $token);

}

$url = "https://api.azuredatacatalog.com/catalogs/DefaultCatalog/search/search?searchTerms=name:=Orders&count=10&api-version=2016-03-30"

$response = Invoke-RestMethod -Method GET -Uri $url -Headers $headers 

I am getting below error message

Invoke-RestMethod : 401 - Unauthorized: Access is denied due to invalid credentials. Server Error

401 - Unauthorized: Access is denied due to invalid credentials. You do not have permission to view this directory or page using the credentials that you supplied.

At line:1 char:13 + $response = Invoke-RestMethod -Method GET -Uri $url -Headers $headers + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand

Please help me in resolving the issue

1
Are you using a Service Principal, Application, or an AD user to connect?Sage
Below are the details used to connect. # Output Token and Response from AAD Graph API $accessToken = ".\Token.txt" $output = ".\Output.json" # Application and Tenant Configuration $clientId = "****.****.****.****.****" $resourceId = "api.azuredatacatalog.com" $redirectUri = New-Object system.uri("login.live.com/oauth20_desktop.srf") $login = "login.windows.net/common/oauth2/authorize";Kumar

1 Answers

0
votes

You might need to grant your application access to the Azure Data Catalog via Azure AD.

enter image description here

Do note that this may require Administrator Approval to complete.