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

  • 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

    Friday, June 28, 2019 8:43 PM

Answers

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
    Moderator
  • 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 = "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;
    
            }

    Thursday, July 18, 2019 4:09 PM
    Moderator
  • 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 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.

    Friday, August 23, 2019 4:47 AM
    Moderator
  • I find the answer in this video, hope this might help to anyone else.

    https://www.youtube.com/watch?v=ujzrq8Fg9Gc

    • Marked as answer by josue ramirez Sunday, August 25, 2019 8:55 PM
    Sunday, August 25, 2019 8:55 PM