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

Commit 9b48585

Browse files
authored
Merge pull request #409 from IdentityModel/joe/wilson
Update Wilson and IdentityModel dependencies
2 parents 9b017ae + c6c180a commit 9b48585

File tree

17 files changed

+106
-45
lines changed

17 files changed

+106
-45
lines changed

src/DPoP/DPoP.csproj

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626
<!-- Recommended: Embed symbols containing Source Link in the main file (exe/dll) -->
2727
<DebugType>embedded</DebugType>
2828

29+
<!-- Enable Trimming Warnings to allow consumers to publish as trimmed -->
30+
<IsTrimmable Condition="'$(TargetFramework)' == 'net6.0'">true</IsTrimmable>
31+
2932
<ContinuousIntegrationBuild Condition="'$(GITHUB_ACTIONS)' == 'true'">True</ContinuousIntegrationBuild>
3033

3134
<AssemblyOriginatorKeyFile>../../key.snk</AssemblyOriginatorKeyFile>
@@ -40,9 +43,9 @@
4043
</ItemGroup>
4144

4245
<ItemGroup>
43-
<PackageReference Include="IdentityModel" Version="6.2.0" />
46+
<PackageReference Include="IdentityModel" Version="7.0.0-preview.3" />
4447
<PackageReference Include="minver" Version="4.3.0" PrivateAssets="All" />
45-
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="6.30.0" />
48+
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="7.3.1" />
4649

4750
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.0" />
4851
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />

src/DPoP/DPoPProof.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// Copyright (c) Brock Allen & Dominick Baier. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.
33

4-
54
namespace IdentityModel.OidcClient.DPoP;
65

76
/// <summary>

src/DPoP/DPoPProofPayload.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Copyright (c) Brock Allen & Dominick Baier. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.
3+
4+
5+
using System.Text.Json.Serialization;
6+
7+
namespace IdentityModel.OidcClient.DPoP;
8+
9+
/// <summary>
10+
/// Internal class to aid serialization of DPoP proof token payloads. Giving
11+
/// each claim a property allows us to add this type to the source generated
12+
/// serialization
13+
/// </summary>
14+
internal class DPoPProofPayload
15+
{
16+
[JsonPropertyName(JwtClaimTypes.JwtId)]
17+
public string JwtId { get; set; } = default!;
18+
[JsonPropertyName(JwtClaimTypes.DPoPHttpMethod)]
19+
public string DPoPHttpMethod { get; set; } = default!;
20+
[JsonPropertyName(JwtClaimTypes.DPoPHttpUrl)]
21+
public string DPoPHttpUrl { get; set; } = default!;
22+
[JsonPropertyName(JwtClaimTypes.IssuedAt)]
23+
public long IssuedAt { get; set; }
24+
[JsonPropertyName(JwtClaimTypes. DPoPAccessTokenHash)]
25+
public string? DPoPAccessTokenHash { get; set; }
26+
[JsonPropertyName(JwtClaimTypes. Nonce)]
27+
public string? Nonce { get; set; }
28+
}

src/DPoP/DPoPProofTokenFactory.cs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -40,24 +40,24 @@ public DPoPProof CreateProofToken(DPoPProofRequest request)
4040

4141
// jwk: representing the public key chosen by the client, in JSON Web Key (JWK) [RFC7517] format,
4242
// as defined in Section 4.1.3 of [RFC7515]. MUST NOT contain a private key.
43-
object jwk;
43+
Dictionary<string, object> jwk;
4444
if (string.Equals(jsonWebKey.Kty, JsonWebAlgorithmsKeyTypes.EllipticCurve))
4545
{
46-
jwk = new
46+
jwk = new Dictionary<string, object>
4747
{
48-
kty = jsonWebKey.Kty,
49-
x = jsonWebKey.X,
50-
y = jsonWebKey.Y,
51-
crv = jsonWebKey.Crv
48+
{ "kty", jsonWebKey.Kty },
49+
{ "x", jsonWebKey.X },
50+
{ "y", jsonWebKey.Y },
51+
{ "crv", jsonWebKey.Crv }
5252
};
5353
}
5454
else if (string.Equals(jsonWebKey.Kty, JsonWebAlgorithmsKeyTypes.RSA))
5555
{
56-
jwk = new
56+
jwk = new Dictionary<string, object>
5757
{
58-
kty = jsonWebKey.Kty,
59-
e = jsonWebKey.E,
60-
n = jsonWebKey.N
58+
{ "kty", jsonWebKey.Kty },
59+
{ "e", jsonWebKey.E },
60+
{ "n", jsonWebKey.N }
6161
};
6262
}
6363
else
@@ -71,12 +71,12 @@ public DPoPProof CreateProofToken(DPoPProofRequest request)
7171
{ JwtClaimTypes.JsonWebKey, jwk },
7272
};
7373

74-
var payload = new Dictionary<string, object>
74+
var payload = new DPoPProofPayload
7575
{
76-
{ JwtClaimTypes.JwtId, CryptoRandom.CreateUniqueId() },
77-
{ JwtClaimTypes.DPoPHttpMethod, request.Method },
78-
{ JwtClaimTypes.DPoPHttpUrl, request.Url },
79-
{ JwtClaimTypes.IssuedAt, DateTimeOffset.UtcNow.ToUnixTimeSeconds() },
76+
JwtId = CryptoRandom.CreateUniqueId(),
77+
DPoPHttpMethod = request.Method,
78+
DPoPHttpUrl = request.Url,
79+
IssuedAt = DateTimeOffset.UtcNow.ToUnixTimeSeconds()
8080
};
8181

8282
if (!string.IsNullOrWhiteSpace(request.AccessToken))
@@ -87,17 +87,17 @@ public DPoPProof CreateProofToken(DPoPProofRequest request)
8787
var hash = sha256.ComputeHash(Encoding.ASCII.GetBytes(request.AccessToken));
8888
var ath = Base64Url.Encode(hash);
8989

90-
payload.Add(JwtClaimTypes.DPoPAccessTokenHash, ath);
90+
payload.DPoPAccessTokenHash = ath;
9191
}
9292

9393
if (!string.IsNullOrEmpty(request.DPoPNonce))
9494
{
95-
payload.Add(JwtClaimTypes.Nonce, request.DPoPNonce!);
95+
payload.Nonce = request.DPoPNonce!;
9696
}
9797

9898
var handler = new JsonWebTokenHandler() { SetDefaultTimesOnTokenCreation = false };
9999
var key = new SigningCredentials(jsonWebKey, jsonWebKey.Alg);
100-
var proofToken = handler.CreateToken(JsonSerializer.Serialize(payload), key, header);
100+
var proofToken = handler.CreateToken(JsonSerializer.Serialize(payload, SourceGenerationContext.Default.DPoPProofPayload), key, header);
101101

102102
return new DPoPProof { ProofToken = proofToken! };
103103
}

src/DPoP/JsonWebKeys.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public static JsonWebKey CreateRsa(string algorithm = OidcConstants.Algorithms.A
3131
/// </summary>
3232
public static string CreateRsaJson(string algorithm = OidcConstants.Algorithms.Asymmetric.PS256)
3333
{
34-
return JsonSerializer.Serialize(CreateRsa(algorithm));
34+
return JsonSerializer.Serialize(CreateRsa(algorithm), SourceGenerationContext.Default.JsonWebKey);
3535
}
3636

3737
/// <summary>
@@ -53,7 +53,7 @@ public static JsonWebKey CreateECDsa(string algorithm = OidcConstants.Algorithms
5353
/// </summary>
5454
public static string CreateECDsaJson(string algorithm = OidcConstants.Algorithms.Asymmetric.ES256)
5555
{
56-
return JsonSerializer.Serialize(CreateECDsa(algorithm));
56+
return JsonSerializer.Serialize(CreateECDsa(algorithm), SourceGenerationContext.Default.JsonWebKey);
5757
}
5858

5959
internal static string GetCurveNameFromSigningAlgorithm(string alg)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using System.Text.Json.Serialization;
2+
using Microsoft.IdentityModel.Tokens;
3+
4+
namespace IdentityModel.OidcClient.DPoP
5+
{
6+
[JsonSourceGenerationOptions(
7+
WriteIndented = false,
8+
PropertyNamingPolicy = JsonKnownNamingPolicy.CamelCase,
9+
GenerationMode = JsonSourceGenerationMode.Metadata,
10+
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull)]
11+
[JsonSerializable(typeof(JsonWebKey))]
12+
[JsonSerializable(typeof(DPoPProofPayload))]
13+
internal partial class SourceGenerationContext : JsonSerializerContext
14+
{
15+
}
16+
}

src/IdentityTokenValidator/IdentityTokenValidator.csproj

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
<!-- Recommended: Embed symbols containing Source Link in the main file (exe/dll) -->
2424
<DebugType>embedded</DebugType>
2525

26+
<!-- Enable Trimming Warnings to allow consumers to publish as trimmed -->
27+
<IsTrimmable Condition="'$(TargetFramework)' == 'net6.0'">true</IsTrimmable>
28+
2629
<ContinuousIntegrationBuild Condition="'$(GITHUB_ACTIONS)' == 'true'">True</ContinuousIntegrationBuild>
2730

2831
<AssemblyOriginatorKeyFile>../../key.snk</AssemblyOriginatorKeyFile>
@@ -38,7 +41,7 @@
3841
<ItemGroup>
3942
<PackageReference Include="minver" Version="4.3.0" PrivateAssets="All" />
4043

41-
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="6.30.0" />
44+
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="7.3.1" />
4245
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.0" />
4346
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
4447
</ItemGroup>

src/IdentityTokenValidator/JwtHandlerIdentityTokenValidator.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public async Task<IdentityTokenValidationResult> ValidateAsync(string identityTo
8181
};
8282
}
8383

84-
var result = ValidateSignature(identityToken, handler, parameters, options, logger);
84+
var result = await ValidateSignatureAsync(identityToken, handler, parameters, options, logger);
8585
if (result.IsValid == false)
8686
{
8787
if (result.Exception is SecurityTokenSignatureKeyNotFoundException)
@@ -123,7 +123,7 @@ public async Task<IdentityTokenValidationResult> ValidateAsync(string identityTo
123123
};
124124
}
125125

126-
private TokenValidationResult ValidateSignature(string identityToken, JsonWebTokenHandler handler, TokenValidationParameters parameters, OidcClientOptions options, ILogger logger)
126+
private async Task<TokenValidationResult> ValidateSignatureAsync(string identityToken, JsonWebTokenHandler handler, TokenValidationParameters parameters, OidcClientOptions options, ILogger logger)
127127
{
128128
if (parameters.RequireSignedTokens)
129129
{
@@ -174,7 +174,7 @@ private TokenValidationResult ValidateSignature(string identityToken, JsonWebTok
174174
parameters.IssuerSigningKeys = keys;
175175
}
176176

177-
return handler.ValidateToken(identityToken, parameters);
177+
return await handler.ValidateTokenAsync(identityToken, parameters);
178178
}
179179

180180
private static string CheckRequiredClaim(ClaimsPrincipal user)

src/OidcClient/OidcClient.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
</ItemGroup>
4343

4444
<ItemGroup>
45-
<PackageReference Include="IdentityModel" Version="6.2.0" />
45+
<PackageReference Include="IdentityModel" Version="7.0.0-preview.3" />
4646
<PackageReference Include="minver" Version="4.3.0" PrivateAssets="All" />
4747

4848
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.0" />

test/DPoPTests/DPoPTests.csproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks>
4+
<TargetFrameworks>net8.0</TargetFrameworks>
55
</PropertyGroup>
66

77
<PropertyGroup>
@@ -17,9 +17,9 @@
1717

1818
<ItemGroup>
1919
<FrameworkReference Include="Microsoft.AspNetCore.App" />
20-
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="6.0.0" />
21-
<PackageReference Include="Duende.IdentityServer" Version="6.3.0" />
22-
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="6.0.0" />
20+
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="8.0.2" />
21+
<PackageReference Include="Duende.IdentityServer" Version="7.0.1" />
22+
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.2" />
2323

2424
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.4" />
2525
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3" />

0 commit comments

Comments
 (0)