Need a Authorization token for getting the job by rest request RRS feed

  • Question

  • Getting the job info by a rest request (GET{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.


    Friday, June 28, 2019 8:43 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

    Sunday, June 30, 2019 9:52 AM
  • Am using c# not powershell
    Thursday, July 18, 2019 3:32 PM
  • 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 = "" + tenantId;
                var authenticationContext = new AuthenticationContext(authContextURL);
                var credential = new ClientCredential(clientId, clientKey);
                var result = authenticationContext.AcquireTokenAsync("", credential);
                if (result == null)
                    throw new InvalidOperationException("Failed to obtain the JWT token");
                string token = result.Result.AccessToken;
                return token;

    Thursday, July 18, 2019 4:09 PM
  • dont know where to get the tenantId and all the data require, if you can point to the right direction will be great, thank you
    Thursday, August 22, 2019 10:16 PM
  • You can find Tenant ID in portal using these steps

    Go to > 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.

    Friday, August 23, 2019 4:47 AM
  • 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
    Sunday, August 25, 2019 8:55 PM