From 825c042bcb3c392359122ad85baee3cfc336c153 Mon Sep 17 00:00:00 2001 From: Joe DeCock Date: Thu, 16 Oct 2025 21:33:53 -0500 Subject: [PATCH] Use latest IdentityModel and AccessTokenManagement packages in JwtBearer, BFF --- Directory.Packages.props | 14 +++++--------- .../AspNetCore.Authentication.JwtBearer.csproj | 2 +- .../DPoP/DPoPExtensions.cs | 3 ++- .../DPoP/DPoPProofValidator.cs | 5 +++-- ...spNetCore.Authentication.JwtBearer.Tests.csproj | 4 ++-- .../DPoP/DPoPProofValidatorTestBase.cs | 3 ++- .../Pages/Diagnostics/ViewModel.cs | 5 +++-- .../Hosts.RemoteApi.DPoP/DPoP/DPoPExtensions.cs | 3 ++- .../DPoP/DPoPProofValidator.cs | 3 ++- 9 files changed, 22 insertions(+), 20 deletions(-) diff --git a/Directory.Packages.props b/Directory.Packages.props index 5199f3b11..12c51d6bd 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -42,18 +42,14 @@ - + - + - - - - - - + + + diff --git a/aspnetcore-authentication-jwtbearer/src/AspNetCore.Authentication.JwtBearer/AspNetCore.Authentication.JwtBearer.csproj b/aspnetcore-authentication-jwtbearer/src/AspNetCore.Authentication.JwtBearer/AspNetCore.Authentication.JwtBearer.csproj index 5cf525060..d0d87a42a 100644 --- a/aspnetcore-authentication-jwtbearer/src/AspNetCore.Authentication.JwtBearer/AspNetCore.Authentication.JwtBearer.csproj +++ b/aspnetcore-authentication-jwtbearer/src/AspNetCore.Authentication.JwtBearer/AspNetCore.Authentication.JwtBearer.csproj @@ -8,7 +8,7 @@ - + diff --git a/aspnetcore-authentication-jwtbearer/src/AspNetCore.Authentication.JwtBearer/DPoP/DPoPExtensions.cs b/aspnetcore-authentication-jwtbearer/src/AspNetCore.Authentication.JwtBearer/DPoP/DPoPExtensions.cs index d28c3862b..097fe4a78 100644 --- a/aspnetcore-authentication-jwtbearer/src/AspNetCore.Authentication.JwtBearer/DPoP/DPoPExtensions.cs +++ b/aspnetcore-authentication-jwtbearer/src/AspNetCore.Authentication.JwtBearer/DPoP/DPoPExtensions.cs @@ -1,6 +1,7 @@ // Copyright (c) Duende Software. All rights reserved. // See LICENSE in the project root for license information. +using System.Buffers.Text; using System.Text.Json; using Duende.IdentityModel; using Microsoft.AspNetCore.Authentication; @@ -44,5 +45,5 @@ internal static class DPoPExtensions /// /// Create the value of a thumbprint /// - public static string CreateThumbprint(this JsonWebKey jwk) => Base64Url.Encode(jwk.ComputeJwkThumbprint()); + public static string CreateThumbprint(this JsonWebKey jwk) => Base64Url.EncodeToString(jwk.ComputeJwkThumbprint()); } diff --git a/aspnetcore-authentication-jwtbearer/src/AspNetCore.Authentication.JwtBearer/DPoP/DPoPProofValidator.cs b/aspnetcore-authentication-jwtbearer/src/AspNetCore.Authentication.JwtBearer/DPoP/DPoPProofValidator.cs index bad212e01..d80d7a1e4 100644 --- a/aspnetcore-authentication-jwtbearer/src/AspNetCore.Authentication.JwtBearer/DPoP/DPoPProofValidator.cs +++ b/aspnetcore-authentication-jwtbearer/src/AspNetCore.Authentication.JwtBearer/DPoP/DPoPProofValidator.cs @@ -1,6 +1,7 @@ // Copyright (c) Duende Software. All rights reserved. // See LICENSE in the project root for license information. +using System.Buffers.Text; using System.Security.Cryptography; using System.Text; using System.Text.Json; @@ -263,7 +264,7 @@ internal class DPoPProofValidator : IDPoPProofValidator var bytes = Encoding.UTF8.GetBytes(context.AccessToken); var hash = SHA256.HashData(bytes); - var accessTokenHash = Base64Url.Encode(hash); + var accessTokenHash = Base64Url.EncodeToString(hash); if (accessTokenHash != result.AccessTokenHash) { result.SetError("Invalid 'ath' value."); @@ -278,7 +279,7 @@ internal class DPoPProofValidator : IDPoPProofValidator return; } var jtiBytes = Encoding.UTF8.GetBytes(jtiString); - result.TokenIdHash = Base64Url.Encode(SHA256.HashData(jtiBytes)); + result.TokenIdHash = Base64Url.EncodeToString(SHA256.HashData(jtiBytes)); } if (string.IsNullOrEmpty(result.TokenIdHash)) diff --git a/aspnetcore-authentication-jwtbearer/test/AspNetCore.Authentication.JwtBearer.Tests/AspNetCore.Authentication.JwtBearer.Tests.csproj b/aspnetcore-authentication-jwtbearer/test/AspNetCore.Authentication.JwtBearer.Tests/AspNetCore.Authentication.JwtBearer.Tests.csproj index 0b1f5d96b..d0f3afe2b 100644 --- a/aspnetcore-authentication-jwtbearer/test/AspNetCore.Authentication.JwtBearer.Tests/AspNetCore.Authentication.JwtBearer.Tests.csproj +++ b/aspnetcore-authentication-jwtbearer/test/AspNetCore.Authentication.JwtBearer.Tests/AspNetCore.Authentication.JwtBearer.Tests.csproj @@ -10,8 +10,8 @@ - - + + diff --git a/aspnetcore-authentication-jwtbearer/test/AspNetCore.Authentication.JwtBearer.Tests/DPoP/DPoPProofValidatorTestBase.cs b/aspnetcore-authentication-jwtbearer/test/AspNetCore.Authentication.JwtBearer.Tests/DPoP/DPoPProofValidatorTestBase.cs index baceb26e4..1947ac9c9 100644 --- a/aspnetcore-authentication-jwtbearer/test/AspNetCore.Authentication.JwtBearer.Tests/DPoP/DPoPProofValidatorTestBase.cs +++ b/aspnetcore-authentication-jwtbearer/test/AspNetCore.Authentication.JwtBearer.Tests/DPoP/DPoPProofValidatorTestBase.cs @@ -1,6 +1,7 @@ // Copyright (c) Duende Software. All rights reserved. // See LICENSE in the project root for license information. +using System.Buffers.Text; using System.Security.Claims; using System.Security.Cryptography; using System.Text; @@ -19,7 +20,7 @@ public abstract class DPoPProofValidatorTestBase { ProofValidator = CreateProofValidator(); var jtiBytes = Encoding.UTF8.GetBytes(TokenId); - TokenIdHash = Base64Url.Encode(SHA256.HashData(jtiBytes)); + TokenIdHash = Base64Url.EncodeToString(SHA256.HashData(jtiBytes)); Context = new() { Options = Options, diff --git a/bff/hosts/Hosts.IdentityServer/Pages/Diagnostics/ViewModel.cs b/bff/hosts/Hosts.IdentityServer/Pages/Diagnostics/ViewModel.cs index 4d93aaf24..f312d4caa 100644 --- a/bff/hosts/Hosts.IdentityServer/Pages/Diagnostics/ViewModel.cs +++ b/bff/hosts/Hosts.IdentityServer/Pages/Diagnostics/ViewModel.cs @@ -1,9 +1,10 @@ // Copyright (c) Duende Software. All rights reserved. // See LICENSE in the project root for license information. + +using System.Buffers.Text; using System.Text; using System.Text.Json; -using Duende.IdentityModel; using Microsoft.AspNetCore.Authentication; namespace IdentityServerHost.Pages.Diagnostics; @@ -17,7 +18,7 @@ public class ViewModel if (result.Properties.Items.ContainsKey("client_list")) { var encoded = result.Properties.Items["client_list"]; - var bytes = Base64Url.Decode(encoded); + var bytes = Base64Url.DecodeFromChars(encoded); var value = Encoding.UTF8.GetString(bytes); Clients = JsonSerializer.Deserialize(value); diff --git a/bff/hosts/RemoteApis/Hosts.RemoteApi.DPoP/DPoP/DPoPExtensions.cs b/bff/hosts/RemoteApis/Hosts.RemoteApi.DPoP/DPoP/DPoPExtensions.cs index 54656c069..beb2bf0ed 100644 --- a/bff/hosts/RemoteApis/Hosts.RemoteApi.DPoP/DPoP/DPoPExtensions.cs +++ b/bff/hosts/RemoteApis/Hosts.RemoteApi.DPoP/DPoP/DPoPExtensions.cs @@ -1,6 +1,7 @@ // Copyright (c) Duende Software. All rights reserved. // See LICENSE in the project root for license information. +using System.Buffers.Text; using System.Text.Json; using Duende.IdentityModel; using Microsoft.AspNetCore.Authentication; @@ -66,7 +67,7 @@ static class DPoPExtensions /// public static string CreateThumbprint(this JsonWebKey jwk) { - var jkt = Base64Url.Encode(jwk.ComputeJwkThumbprint()); + var jkt = Base64Url.EncodeToString(jwk.ComputeJwkThumbprint()); return jkt; } } diff --git a/bff/hosts/RemoteApis/Hosts.RemoteApi.DPoP/DPoP/DPoPProofValidator.cs b/bff/hosts/RemoteApis/Hosts.RemoteApi.DPoP/DPoP/DPoPProofValidator.cs index cbff2e5e1..984f7879c 100644 --- a/bff/hosts/RemoteApis/Hosts.RemoteApi.DPoP/DPoP/DPoPProofValidator.cs +++ b/bff/hosts/RemoteApis/Hosts.RemoteApi.DPoP/DPoP/DPoPProofValidator.cs @@ -1,6 +1,7 @@ // Copyright (c) Duende Software. All rights reserved. // See LICENSE in the project root for license information. +using System.Buffers.Text; using System.Security.Cryptography; using System.Text; using System.Text.Json; @@ -226,7 +227,7 @@ public class DPoPProofValidator var bytes = Encoding.UTF8.GetBytes(context.AccessToken); var hash = sha.ComputeHash(bytes); - var accessTokenHash = Base64Url.Encode(hash); + var accessTokenHash = Base64Url.EncodeToString(hash); if (accessTokenHash != result.AccessTokenHash) { result.IsError = true;