Skip to content

az cli returns expiresOn in local time but sdk assumes c++ time #5075

@janbernloehr

Description

@janbernloehr

Describe the bug
When using an AzureCliCredential, the ExpiresOn field is parsed from the the output of the call

az account get-access-token --output json --scope "https://storage.azure.com/.default"

which returns the field expiresOn in local time but does not add time zone information. However, Azure::DateTime assumes - when no time zone information is present - that the date is in UTC.

The IsFresh method of Azure::TokenCache then compares the parsed ExpiresOn with Azure::DateTime(std::chrono::system_clock::now()) which is UTC time thus yielding a wrong comparison.

Exception or Stack Trace

To Reproduce
Steps to reproduce the behavior:
Inject the following debug code in TokenCache::IsFresh in token_cache.cpp:

  const DateTime end_point = DateTime(now) + minimumExpiration;
  std::cout << "lhs: " << item->AccessToken.ExpiresOn.ToString() << " rhs: " << end_point.ToString() << std::endl;

Then call any api using the AzureCliCredential that requires a token.

Code Snippet

Expected behavior
The AzureCliCredential should correctly take the time zone information into account.

Screenshots

Setup (please complete the following information):

  • OS: Ubuntu 22.04
  • IDE : VsCode
  • Version of the Library used: Azure Identity 1.6.0-beta.1 and Azure Core 1.10.2

Additional context
Add any other context about the problem here.

Information Checklist
Kindly make sure that you have added all the following information above and checkoff the required fields otherwise we will treat the issuer as an incomplete report

  • Bug Description Added
  • Repro Steps Added
  • Setup information Added

Metadata

Metadata

Assignees

Labels

Azure.IdentityClientThis issue points to a problem in the data-plane of the library.bugThis issue requires a change to an existing behavior in the product in order to be resolved.customer-reportedIssues that are reported by GitHub users external to the Azure organization.needs-team-attentionWorkflow: This issue needs attention from Azure service team or SDK team

Type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions