az account get-access-token CLI command Specifics

Karl Gardner 195 Reputation points
2024-08-09T02:54:02.1333333+00:00

Hello,

Wondering what exactly does the az account get-access-token command in Azure CLI do: https://learn.microsoft.com/en-us/cli/azure/account?view=azure-cli-latest#az-account-get-access-token

Their is not much explanation in the documentation. It authenticates/athorizes with Entra Id to get an access token for a specific app registration. Does it use the Microsoft Identity Platform Outh2 to get an access token with the login.microsoftonline.com/{tenant}/oauth2/v2.0/authorize and login.microsoftonline.com/{tenant}/oauth2/v2.0/token endpoints? Seems like it would use the /token endpoint to get an access token and use the auth code flow:

https://learn.microsoft.com/en-us/entra/identity-platform/v2-oauth2-auth-code-flow

Not 100% sure of that though.

Thanks!

Microsoft Security Microsoft Entra Microsoft Entra ID
0 comments No comments
{count} vote

Accepted answer
  1. Navya 19,795 Reputation points Microsoft External Staff Moderator
    2024-08-12T07:20:01.84+00:00

    Hi @Karl Gardner

    Thank you for posting this in Microsoft Q&A.

    I understand you want to know exactly what the 'az account get-access-token' command does in the Azure CLI.

    Authentication is the process of proving that you're who you say you are. Authorization is the act of granting an authenticated party permission to do something. Access tokens are a type of security token designed for authorization, granting access to specific resources on behalf on an authenticated user.

    The az account get-access-token command in Azure CLI is used to obtain an access token for the current Azure account. When you run this command, it retrieves an access token that can be used to authenticate and authorize requests to Azure resources. By default, the returned access token is for Azure Resource Manager (ARM) and the default subscription/tenant.

    It uses the authentication information that is already stored in the Azure CLI to obtain an access token. This means that you do not need to manually authenticate again when running this command. The Azure CLI stores the authentication information for the current Azure account, which includes the user's credentials and the Azure AD tenant information.

    AAD stands for Azure Active Directory, which is a cloud-based identity and access management service. It offers a secure method for managing access to Azure resources, applications, and APIs.

    A resource endpoint is a unique identifier for an Azure service or API that can be used to request an access token. These endpoints are used to specify the resource for which the access token is requested. Endpoints are typically in the format of https://{resource-name}.azure.com/ or https://{resource-name}. microsoft.com/.

    For example:

    • Azure Resource Manager: https://management.azure.com/
    • Azure Storage: https://storage.azure.com/
    • Microsoft Graph: https://graph.microsoft.com/
    • Event Hubs: https://eventhubs.azure.com/

    These resource endpoints are used to request an access token that can be used to authenticate and authorize requests to the corresponding Azure service or API.

    In the video, the presenter used an Application ID URI in the --resource parameter, which is a different story. When you create an app registration in Azure AD, you can specify an Application ID URI, which is a unique identifier for your application. This URI is used to identify your application when requesting an access token. The format of the Application ID URI is api://{client-id}, where {client-id} is the client ID of your app registration.

    When you use the Application ID URI as the --resource parameter, the Azure CLI requests an access token for your application, which can be used to authenticate and authorize requests to your application's APIs.

    For more information: Authenticate to Azure using Azure CLI

    Hope this helps. Do let us know if you any further queries.

    Thanks,

    Navya.

    If this answers your query, do click Accept Answer and Yes for was this answer helpful. And, if you have any further query do let us know.

    4 people found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Abiola Akinbade 29,405 Reputation points Volunteer Moderator
    2024-08-09T07:55:43.32+00:00

    You're on the right track. The az account get-access-token is to obtain an access token for Azure Resource Manager (ARM) or Azure services. However it usually uses the credentials you've already given when logging into the Azure CLI and not authorization code flow.

    You can mark it 'Accept Answer' and 'Upvote' if this helped you

    Regards,

    Abiola


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.