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
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions sdk/identity/src/token_credentials/cli_credentials.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::str;
use std::{io::ErrorKind, str::Utf8Error};

mod az_cli_date_format {
use chrono::{DateTime, TimeZone, Utc};
use chrono::{DateTime, Local, TimeZone, Utc};
use serde::{self, Deserialize, Deserializer};

const FORMAT: &str = "%Y-%m-%d %H:%M:%S.%6f";
Expand All @@ -18,8 +18,11 @@ mod az_cli_date_format {
D: Deserializer<'de>,
{
let s = String::deserialize(deserializer)?;
Utc.datetime_from_str(&s, FORMAT)
.map_err(serde::de::Error::custom)
// expiresOn from azure cli uses the local timezone and needs to be converted to UTC
let local_datetime = Local
.datetime_from_str(&s, FORMAT)
.map_err(serde::de::Error::custom)?;
Ok(local_datetime.with_timezone(&Utc))
}
}

Expand Down