Skip to content

Commit

Permalink
datetime from azure cli token is in the local timezone (#751)
Browse files Browse the repository at this point in the history
  • Loading branch information
yvespp authored May 18, 2022
1 parent dfb2430 commit 34e6cad
Showing 1 changed file with 6 additions and 3 deletions.
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

0 comments on commit 34e6cad

Please sign in to comment.