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

Update Wilson and IdentityModel dependencies #409

Merged
merged 8 commits into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
4 changes: 2 additions & 2 deletions src/DPoP/DPoP.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="IdentityModel" Version="6.2.0" />
<PackageReference Include="IdentityModel" Version="7.0.0-preview.2" />
<PackageReference Include="minver" Version="4.3.0" PrivateAssets="All" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="6.30.0" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="7.3.1" />

<PackageReference Include="Microsoft.Extensions.Logging" Version="6.0.0" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
Expand Down
18 changes: 9 additions & 9 deletions src/DPoP/DPoPProofTokenFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,21 @@ public DPoPProof CreateProofToken(DPoPProofRequest request)
object jwk;
if (string.Equals(jsonWebKey.Kty, JsonWebAlgorithmsKeyTypes.EllipticCurve))
{
jwk = new
jwk = new Dictionary<string, object>
{
kty = jsonWebKey.Kty,
x = jsonWebKey.X,
y = jsonWebKey.Y,
crv = jsonWebKey.Crv
{ "kty", jsonWebKey.Kty },
{ "x", jsonWebKey.X },
{ "y", jsonWebKey.Y },
{ "crv", jsonWebKey.Crv }
};
}
else if (string.Equals(jsonWebKey.Kty, JsonWebAlgorithmsKeyTypes.RSA))
{
jwk = new
jwk = new Dictionary<string, object>
{
kty = jsonWebKey.Kty,
e = jsonWebKey.E,
n = jsonWebKey.N
{ "kty", jsonWebKey.Kty },
{ "e", jsonWebKey.E },
{ "n", jsonWebKey.N }
};
}
else
Expand Down
2 changes: 1 addition & 1 deletion src/IdentityTokenValidator/IdentityTokenValidator.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
<ItemGroup>
<PackageReference Include="minver" Version="4.3.0" PrivateAssets="All" />

<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="6.30.0" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="7.3.1" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="6.0.0" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public async Task<IdentityTokenValidationResult> ValidateAsync(string identityTo
};
}

var result = ValidateSignature(identityToken, handler, parameters, options, logger);
var result = await ValidateSignatureAsync(identityToken, handler, parameters, options, logger);
if (result.IsValid == false)
{
if (result.Exception is SecurityTokenSignatureKeyNotFoundException)
Expand Down Expand Up @@ -123,7 +123,7 @@ public async Task<IdentityTokenValidationResult> ValidateAsync(string identityTo
};
}

private TokenValidationResult ValidateSignature(string identityToken, JsonWebTokenHandler handler, TokenValidationParameters parameters, OidcClientOptions options, ILogger logger)
private async Task<TokenValidationResult> ValidateSignatureAsync(string identityToken, JsonWebTokenHandler handler, TokenValidationParameters parameters, OidcClientOptions options, ILogger logger)
{
if (parameters.RequireSignedTokens)
{
Expand Down Expand Up @@ -174,7 +174,7 @@ private TokenValidationResult ValidateSignature(string identityToken, JsonWebTok
parameters.IssuerSigningKeys = keys;
}

return handler.ValidateToken(identityToken, parameters);
return await handler.ValidateTokenAsync(identityToken, parameters);
}

private static string CheckRequiredClaim(ClaimsPrincipal user)
Expand Down
2 changes: 1 addition & 1 deletion src/OidcClient/OidcClient.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="IdentityModel" Version="6.2.0" />
<PackageReference Include="IdentityModel" Version="7.0.0-preview.2" />
<PackageReference Include="minver" Version="4.3.0" PrivateAssets="All" />

<PackageReference Include="Microsoft.Extensions.Logging" Version="6.0.0" />
Expand Down
8 changes: 4 additions & 4 deletions test/DPoPTests/DPoPTests.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks>
<TargetFrameworks>net8.0</TargetFrameworks>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@brockallen, when you review this, I want to call this out. I made this change because tests need to use IdentityServer 7 to get its changes that support the new version of wilson.

The tests are creating an IdentityServer test host and then using it to get dpop tokens. The problem is that if our tests use IdentityServer 6.3 but we update the wilson dependency in IM.OC.DPoP, IdentityServer will use that wilson version too. Once we update wilson, we need the updated version of IdentityServer (that uses JsonElements instead of Dictionary<string, object>) in order to deserialize the proof tokens. And IdentityServer 7 of course only targets net8.0. So, this forces us to drop net6.0 and net7.0 from the target frameworks of this test project.

</PropertyGroup>

<PropertyGroup>
Expand All @@ -17,9 +17,9 @@

<ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="6.0.0" />
<PackageReference Include="Duende.IdentityServer" Version="6.3.0" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="6.0.0" />
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="8.0.2" />
<PackageReference Include="Duende.IdentityServer" Version="7.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.2" />

<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.4" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3" />
Expand Down
3 changes: 2 additions & 1 deletion test/DPoPTests/Framework/DPoP/DPoPJwtBearerEvents.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using IdentityModel;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Options;
using Microsoft.Net.Http.Headers;
using System.Text;
Expand Down Expand Up @@ -130,7 +131,7 @@ public override Task Challenge(JwtBearerChallengeContext context)
}
}

context.Response.Headers.Add(HeaderNames.WWWAuthenticate, sb.ToString());
context.Response.Headers.Append(HeaderNames.WWWAuthenticate, sb.ToString());


if (context.HttpContext.Items.ContainsKey("DPoP-Nonce"))
Expand Down
12 changes: 6 additions & 6 deletions test/DPoPTests/Framework/DPoP/DPoPProofValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ protected virtual Task ValidateHeaderAsync(DPoPProofValidatonContext context, DP
return Task.CompletedTask;
}

if (!token.TryGetHeaderValue<IDictionary<string, object>>(JwtClaimTypes.JsonWebKey, out var jwkValues))
if (!token.TryGetHeaderValue<JsonElement>(JwtClaimTypes.JsonWebKey, out var jwkValues))
{
result.IsError = true;
result.ErrorDescription = "Invalid 'jwk' value.";
Expand Down Expand Up @@ -169,7 +169,7 @@ protected virtual Task ValidateHeaderAsync(DPoPProofValidatonContext context, DP
/// <summary>
/// Validates the signature.
/// </summary>
protected virtual Task ValidateSignatureAsync(DPoPProofValidatonContext context, DPoPProofValidatonResult result)
protected virtual async Task ValidateSignatureAsync(DPoPProofValidatonContext context, DPoPProofValidatonResult result)
{
TokenValidationResult tokenValidationResult;

Expand All @@ -185,27 +185,27 @@ protected virtual Task ValidateSignatureAsync(DPoPProofValidatonContext context,
};

var handler = new JsonWebTokenHandler();
tokenValidationResult = handler.ValidateToken(context.ProofToken, tvp);
tokenValidationResult = await handler.ValidateTokenAsync(context.ProofToken, tvp);
}
catch (Exception ex)
{
Logger.LogDebug("Error parsing DPoP token: {error}", ex.Message);
result.IsError = true;
result.ErrorDescription = "Invalid signature on DPoP token.";
return Task.CompletedTask;
return;
}

if (tokenValidationResult.Exception != null)
{
Logger.LogDebug("Error parsing DPoP token: {error}", tokenValidationResult.Exception.Message);
result.IsError = true;
result.ErrorDescription = "Invalid signature on DPoP token.";
return Task.CompletedTask;
return;
}

result.Payload = tokenValidationResult.Claims;

return Task.CompletedTask;
return;
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion test/JwtValidationTests/Infrastructure/Crypto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public static IdentityModel.Jwk.JsonWebKeySet CreateKeySet(RsaSecurityKey key)
public static string CreateJwt(RsaSecurityKey key, string issuer, string audience, params Claim[] claims)
{
var jwtClaims = new List<Claim>(claims);
jwtClaims.Add(new Claim(JwtClaimTypes.IssuedAt, "now"));
jwtClaims.Add(new Claim(JwtClaimTypes.IssuedAt, DateTime.UtcNow.Ticks.ToString(), ClaimValueTypes.Integer64));

SigningCredentials credentials = null;
if (key != null)
Expand Down
5 changes: 3 additions & 2 deletions test/JwtValidationTests/Infrastructure/NetworkHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System;
using System.Net;
using System.Net.Http;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

Expand Down Expand Up @@ -86,11 +87,11 @@ protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage
{
if (_selector != null)
{
response.Content = new StringContent(_selector(request));
response.Content = new StringContent(_selector(request), Encoding.UTF8, "application/json");
}
else
{
response.Content = new StringContent(_document);
response.Content = new StringContent(_document, Encoding.UTF8, "application/json");
}
}

Expand Down
5 changes: 3 additions & 2 deletions test/OidcClient.Tests/Infrastructure/NetworkHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System;
using System.Net;
using System.Net.Http;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

Expand Down Expand Up @@ -86,11 +87,11 @@ protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage
{
if (_selector != null)
{
response.Content = new StringContent(_selector(request));
response.Content = new StringContent(_selector(request), Encoding.UTF8, "application/json");
}
else
{
response.Content = new StringContent(_document);
response.Content = new StringContent(_document, Encoding.UTF8, "application/json");
}
}

Expand Down
2 changes: 1 addition & 1 deletion test/OidcClient.Tests/OidcClient.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="6.12.0"/>
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="7.3.1"/>

<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.4"/>
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3"/>
Expand Down
Loading