The Azure CLI is a command-line tool providing a great experience for managing Azure resources. The Azure command-line interface (CLI) is probably the second most-used tool after the web portal. The CLI runs on any platform and covers a wide variety of actions.To install Azure CLI , refer to https://docs.microsoft.com/en-us/cli/azure/install-azure-cli?view=azure-cli-latest
The very first command will be to log in to Azure:
az login
az login
The login operation has a unique session identifier. Once you sign in with this session ID, the CLI receives a notification on its back channel. The notification contains a JWT access token.
From this point on, the access token is used by most other CLI commands to access Azure Management REST API. API uses OAuth protocol where the access token is passed in the Authroisation HTTP header. As the CLI is a short-lived program: it runs for the duration of a single command execution and then quits. The process dies, so there’s no way to keep access tokens in memory between the executions. To avoid continually asking for user credentials, the CLI keeps its state on disk. If you go to the
~/.azure/
directory (%HOMEPATH%/.azure/
in Windows command-line) you can find json and other files. The access token has a limited lifespan aorund 60 minutes. To avoid requiring to login after access expiration, there is another powerful token—a refresh token. Whenever an access token expires, CLI goes to the authentication service, presents the refresh token, and asks for a new access token. The lifetime of a refresh token is longer, and it’s managed on the service side.