Skip to content
This repository was archived by the owner on Feb 23, 2025. It is now read-only.

Fix AuthenticationTime calculation #329

Merged
merged 1 commit into from
Jul 14, 2021
Merged
Show file tree
Hide file tree
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
6 changes: 3 additions & 3 deletions src/OidcClient/OidcClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -234,16 +234,16 @@ public virtual async Task<LoginResult> ProcessResponseAsync(
}
}

var user = ProcessClaims(result.User, userInfoClaims);

var authTimeValue = result.TokenResponse.TryGet(JwtClaimTypes.AuthenticationTime);
var authTimeValue = result.User.FindFirst(JwtClaimTypes.AuthenticationTime)?.Value;
DateTimeOffset? authTime = null;

if (authTimeValue.IsPresent() && long.TryParse(authTimeValue, out long seconds))
{
authTime = DateTimeOffset.FromUnixTimeSeconds(seconds);
}

var user = ProcessClaims(result.User, userInfoClaims);

var loginResult = new LoginResult
{
User = user,
Expand Down
4 changes: 3 additions & 1 deletion test/OidcClient.Tests/CodeFlowResponseTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ public async Task Valid_response_with_id_token_should_succeed()
var url = $"?state={state.State}&code=bar";
var idToken = Crypto.CreateJwt(null, "https://authority", "client",
new Claim("at_hash", Crypto.HashData("token")),
new Claim("sub", "123"));
new Claim("sub", "123"),
new Claim("auth_time", "123"));

var tokenResponse = new Dictionary<string, object>
{
Expand All @@ -77,6 +78,7 @@ public async Task Valid_response_with_id_token_should_succeed()
result.AccessToken.Should().Be("token");
result.IdentityToken.Should().NotBeNull();
result.User.Should().NotBeNull();
result.AuthenticationTime.Should().Be(DateTimeOffset.FromUnixTimeSeconds(123));

result.User.Claims.Count().Should().Be(1);
result.User.Claims.First().Type.Should().Be("sub");
Expand Down