Answered by:
Need a Authorization token for getting the job by rest request

Question
-
Getting the job info by a rest request (GET https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Automation/automationAccounts/{automationAccountName}/jobs/{jobName}?api-version=2017-05-15-preview) am currently getting the error that i need a authorization token, do you know how can i get the token in order to put it on the header.
Regards
Answers
-
I find the answer in this video, hope this might help to anyone else.
- Marked as answer by josue ramirez Sunday, August 25, 2019 8:55 PM
All replies
-
Here is a Powershell script that might help you in getting the authorization token.
$account = Add-AzAccount -SubscriptionId $subscriptionId $TenantId=(Get-AzSubscription -SubscriptionId $subscriptionId).TenantId $TokenCache=$account.Context.TokenCache $cachedTokens = $tokenCache.ReadItems() ` | where { $_.TenantId -eq $tenantId } ` | Sort-Object -Property ExpiresOn -Descending $accessToken=$cachedTokens.GetValue(0).AccessToken
-
-
Here is a code snippet for getting authorization token using service principal that might help you.
private static string GetAccessToken(string tenantId, string clientId, string clientKey) { string authContextURL = "https://login.windows.net/" + tenantId; var authenticationContext = new AuthenticationContext(authContextURL); var credential = new ClientCredential(clientId, clientKey); var result = authenticationContext.AcquireTokenAsync("https://management.azure.com/", credential); if (result == null) { throw new InvalidOperationException("Failed to obtain the JWT token"); } string token = result.Result.AccessToken; Console.Write(token); return token; }
- Proposed as answer by SwathiDhanwada-MSFTMicrosoft employee, Moderator Thursday, July 18, 2019 4:09 PM
-
-
You can find Tenant ID in portal using these steps
Go to Portal.azure.com > Azure Active Directory > Properties. The directory ID it shows there is your tenant ID.
To get Client ID and client secret, you need to create service principle. Refer this document for more information.
-
I find the answer in this video, hope this might help to anyone else.
- Marked as answer by josue ramirez Sunday, August 25, 2019 8:55 PM