Skip to content

Commit ef8815b

Browse files
committed
DPoP - Update IdentityModel, wilson dependencies
- Pass a Dictionary instead of an anonymous type for jwk claims (needed due to changes in jwt handler) - replace deprecated IHeaderDictionary.Add with Append - replace deprecated ValidateToken with ValidateTokenAsync - tests need to use IdentityServer 7 to get its changes to support new wilson library. This forces us to drop net6.0 and net7.0 from the target frameworks of the dpop test project
1 parent 7f42ee3 commit ef8815b

File tree

5 files changed

+23
-22
lines changed

5 files changed

+23
-22
lines changed

src/DPoP/DPoP.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@
3939
</ItemGroup>
4040

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

4646
<PackageReference Include="Microsoft.Extensions.Logging" Version="6.0.0" />
4747
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />

src/DPoP/DPoPProofTokenFactory.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,21 +43,21 @@ public DPoPProof CreateProofToken(DPoPProofRequest request)
4343
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

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" />

test/DPoPTests/Framework/DPoP/DPoPJwtBearerEvents.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using IdentityModel;
22
using Microsoft.AspNetCore.Authentication.JwtBearer;
3+
using Microsoft.AspNetCore.Http;
34
using Microsoft.Extensions.Options;
45
using Microsoft.Net.Http.Headers;
56
using System.Text;
@@ -130,7 +131,7 @@ public override Task Challenge(JwtBearerChallengeContext context)
130131
}
131132
}
132133

133-
context.Response.Headers.Add(HeaderNames.WWWAuthenticate, sb.ToString());
134+
context.Response.Headers.Append(HeaderNames.WWWAuthenticate, sb.ToString());
134135

135136

136137
if (context.HttpContext.Items.ContainsKey("DPoP-Nonce"))

test/DPoPTests/Framework/DPoP/DPoPProofValidator.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ protected virtual Task ValidateHeaderAsync(DPoPProofValidatonContext context, DP
130130
return Task.CompletedTask;
131131
}
132132

133-
if (!token.TryGetHeaderValue<IDictionary<string, object>>(JwtClaimTypes.JsonWebKey, out var jwkValues))
133+
if (!token.TryGetHeaderValue<JsonElement>(JwtClaimTypes.JsonWebKey, out var jwkValues))
134134
{
135135
result.IsError = true;
136136
result.ErrorDescription = "Invalid 'jwk' value.";
@@ -169,7 +169,7 @@ protected virtual Task ValidateHeaderAsync(DPoPProofValidatonContext context, DP
169169
/// <summary>
170170
/// Validates the signature.
171171
/// </summary>
172-
protected virtual Task ValidateSignatureAsync(DPoPProofValidatonContext context, DPoPProofValidatonResult result)
172+
protected virtual async Task ValidateSignatureAsync(DPoPProofValidatonContext context, DPoPProofValidatonResult result)
173173
{
174174
TokenValidationResult tokenValidationResult;
175175

@@ -185,27 +185,27 @@ protected virtual Task ValidateSignatureAsync(DPoPProofValidatonContext context,
185185
};
186186

187187
var handler = new JsonWebTokenHandler();
188-
tokenValidationResult = handler.ValidateToken(context.ProofToken, tvp);
188+
tokenValidationResult = await handler.ValidateTokenAsync(context.ProofToken, tvp);
189189
}
190190
catch (Exception ex)
191191
{
192192
Logger.LogDebug("Error parsing DPoP token: {error}", ex.Message);
193193
result.IsError = true;
194194
result.ErrorDescription = "Invalid signature on DPoP token.";
195-
return Task.CompletedTask;
195+
return;
196196
}
197197

198198
if (tokenValidationResult.Exception != null)
199199
{
200200
Logger.LogDebug("Error parsing DPoP token: {error}", tokenValidationResult.Exception.Message);
201201
result.IsError = true;
202202
result.ErrorDescription = "Invalid signature on DPoP token.";
203-
return Task.CompletedTask;
203+
return;
204204
}
205205

206206
result.Payload = tokenValidationResult.Claims;
207207

208-
return Task.CompletedTask;
208+
return;
209209
}
210210

211211
/// <summary>

0 commit comments

Comments
 (0)