[Profile] az account get-access-token: Show expiresOn for Managed Identity#14128
Merged
[Profile] az account get-access-token: Show expiresOn for Managed Identity#14128
Conversation
Collaborator
|
add to S172 |
jiasli
commented
Jun 30, 2020
| /src/azure-cli/azure/cli/command_modules/privatedns/ @MyronFanQiu @haroldrandom | ||
| /src/azure-cli/azure/cli/command_modules/policyinsights/ @cheggert | ||
| /src/azure-cli/azure/cli/command_modules/profile/ @jiasli @arrownj | ||
| /src/azure-cli/azure/cli/command_modules/profile/ @jiasli @arrownj @qianwens |
Member
Author
Juliehzl
approved these changes
Jul 3, 2020
qianwens
approved these changes
Jul 3, 2020
arrownj
reviewed
Jul 3, 2020
jiasli
commented
Jul 3, 2020
Collaborator
|
add to S172 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Currently,
az account get-access-tokenshows"expiresOn": "N/A"for Managed Identity:It works for a user account:
This is because
msrestazure.azure_active_directory.MSIAuthentication's token entry hasexpires_on, while ADAL's token entry hasexpiresOn.This PRs fixes this by converting the epoch
expires_onto ISOexpiresOn:Testing Guide
More info
In fact, the REST call in ADAL for token retrieval is:
Request:
Response:
{ "token_type": "Bearer", "scope": "user_impersonation", "expires_in": "3595", "ext_expires_in": "3595", "expires_on": "1593413327", "not_before": "1593409427", "resource": "https://management.core.windows.net/", "access_token": "...", "refresh_token": "...", "foci": "1" }ADAL ignores
expires_on, but calculatesexpiresOnbased on the current time andexpires_in.https://github.com/AzureAD/azure-activedirectory-library-for-python/blob/6f0c4755658fbbacf50de684c16eb378d1dbfb92/adal/oauth2_client.py#L187
This is why the microsecond
443545appears in"expiresOn": "2020-06-29 17:22:16.443545", whileexpires_onis an integer1593413327.