Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#if SUPPORTS_SYSTEM_TEXT_JSON
using Microsoft.Identity.Client.Platforms.net;
using JsonProperty = System.Text.Json.Serialization.JsonPropertyNameAttribute;
using JsonIgnore = System.Text.Json.Serialization.JsonIgnoreAttribute;
#else
using Microsoft.Identity.Json;
#endif
Expand All @@ -29,8 +30,22 @@ internal class ManagedIdentityResponse
/// </summary>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How will we keep this object ManagedIdentityResponse in sync with MsalTokenResponse, e.g. RefreshIn is missing?

/// <remarks>The date is represented as the number of seconds from "1970-01-01T0:0:0Z UTC"
/// (corresponds to the token's exp claim).</remarks>
[JsonIgnore]
public string ExpiresOn { get; set; } // The actual property consumers use

[JsonProperty("expires_on")]
public string ExpiresOn { get; set; }
public string ExpiresOnRaw // Proxy for "expires_on" JSON field
{
get => ExpiresOn; // When serializing, return ExpiresOn value
set => ExpiresOn = value; // When deserializing, store in ExpiresOn
}

[JsonProperty("expires_in")]
public string ExpiresInRaw // Proxy for "expires_in" JSON field
{
get => null; // Never serialize this (return null)
set => ExpiresOn = value; // When deserializing, store in ExpiresOn
}

/// <summary>
/// The resource the access token was requested for.
Expand Down
10 changes: 9 additions & 1 deletion src/client/Microsoft.Identity.Client/Utils/DateTimeHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,15 @@ public static long GetDurationFromManagedIdentityTimestamp(string dateTimeStamp)
// Example: "1697490590" (Unix timestamp representing seconds since 1970-01-01)
if (long.TryParse(dateTimeStamp, out long expiresOnUnixTimestamp))
{
return expiresOnUnixTimestamp - DateTimeHelpers.CurrDateTimeInUnixTimestamp();
var timestamp = expiresOnUnixTimestamp - DateTimeHelpers.CurrDateTimeInUnixTimestamp();

// If the timestamp is negative, return the original expiresOnUnixTimestamp. It's format is "seconds from now".
if (timestamp < 0)
{
return expiresOnUnixTimestamp;
}

return timestamp;
}

// Try parsing as ISO 8601
Expand Down