From abfb5761ee381b7e1e5342a5525ceca8c8fd81dd Mon Sep 17 00:00:00 2001 From: vnugent Date: Thu, 4 Jul 2024 23:57:37 -0400 Subject: analyzer pass --- .../src/IdentityUtility/JwtPayload.cs | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) (limited to 'lib') diff --git a/lib/Hashing.Portable/src/IdentityUtility/JwtPayload.cs b/lib/Hashing.Portable/src/IdentityUtility/JwtPayload.cs index eb33e00..1fc5f61 100644 --- a/lib/Hashing.Portable/src/IdentityUtility/JwtPayload.cs +++ b/lib/Hashing.Portable/src/IdentityUtility/JwtPayload.cs @@ -1,5 +1,5 @@ /* -* Copyright (c) 2023 Vaughn Nugent +* Copyright (c) 2024 Vaughn Nugent * * Library: VNLib * Package: VNLib.Hashing.Portable @@ -22,6 +22,7 @@ * along with VNLib.Hashing.Portable. If not, see http://www.gnu.org/licenses/. */ +using System.Text.Json; using System.Collections.Generic; using VNLib.Utils; @@ -31,9 +32,9 @@ namespace VNLib.Hashing.IdentityUtility /// /// A fluent api structure for adding and committing claims to a /// - public readonly record struct JwtPayload : IIndexable + public readonly record struct JwtPayload : IIndexable { - private readonly Dictionary Claims; + private readonly Dictionary Claims; private readonly JsonWebToken Jwt; internal JwtPayload(JsonWebToken jwt, int initialCapacity) @@ -43,7 +44,7 @@ namespace VNLib.Hashing.IdentityUtility } /// - public readonly object this[string key] + public readonly object? this[string key] { get => Claims[key]; set => Claims[key] = value; @@ -55,7 +56,7 @@ namespace VNLib.Hashing.IdentityUtility /// The clame name /// The value of the claim /// The chained response object - public readonly JwtPayload AddClaim(string claim, object value) + public readonly JwtPayload AddClaim(string claim, object? value) { Claims.Add(claim, value); return this; @@ -69,5 +70,15 @@ namespace VNLib.Hashing.IdentityUtility Jwt.WritePayload(Claims); Claims.Clear(); } + + /// + /// Writes all claims to the payload segment + /// + /// Json serializer options to pass to the serializer + public readonly void CommitClaims(JsonSerializerOptions? options) + { + Jwt.WritePayload(Claims, options); + Claims.Clear(); + } } } -- cgit