Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

datetime from azure cli token is in the local timezone #751

Merged
merged 1 commit into from
May 18, 2022
Merged

datetime from azure cli token is in the local timezone #751

merged 1 commit into from
May 18, 2022

Conversation

yvespp
Copy link
Contributor

@yvespp yvespp commented May 16, 2022

While working on auto refresh I noticed that the token expiry from azure cli is in the local timezone but is interpreted as UTC in code. This causes the token not being refreshed in my timezone. (My time: 12:00 GMT+2, toke expiresOn time 13:20, token expiry in UTC 15:20).
This can be verified by running az account get-access-token --output json and comparing exp of the jwt with expiresOn from the cli.

@bmc-msft
Copy link
Contributor

In my testing, I saw a similar difference with expiresOn as indicated by @yvespp . I went to check how the CLI implements this to make sure we're not relying on a local configuration regarding time zones. That doesn't appear to be the case.

However, in my investigation, I came across the following from the SDK

        # Convert epoch int 'expires_on' to datetime string 'expiresOn' for backward compatibility
        # WARNING: expiresOn is deprecated and will be removed in future release.
        import datetime
        expiresOn = datetime.datetime.fromtimestamp(sdk_token.expires_on).strftime("%Y-%m-%d %H:%M:%S.%f")


        token_entry = {
            'accessToken': sdk_token.token,
            'expires_on': sdk_token.expires_on,  # epoch int, like 1605238724
            'expiresOn': expiresOn  # datetime string, like "2020-11-12 13:50:47.114324"
        }

In the future, we may want to consider parsing the JWT token itself, which includes more details as to the expiry state (including a not-before and expires-on timestamp).

@bmc-msft bmc-msft merged commit 34e6cad into Azure:main May 18, 2022
@yvespp yvespp deleted the expires_on_cli_date_format branch May 18, 2022 17:34
@cataggar cataggar added this to the azure_identity 0.3.0 milestone May 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants