Skip to main content

JsonWebKeySettings Class

Abblix.Oidc.Server

Abblix.Oidc.Server.Common.Configuration

JsonWebKeySettings Class

Flat configuration DTO for a single JSON Web Key, suitable for binding via Microsoft.Extensions.Configuration which cannot instantiate the abstract JsonWebKey base type directly. All cryptographic byte-array members are bound as base64url-encoded strings per RFC 7517; ToJsonWebKey() decodes them and maps the flat shape to the correct concrete subtype based on Kty.

public sealed class JsonWebKeySettings

Inheritance System.Object → JsonWebKeySettings

Remarks

Design rationale: a flat DTO that mirrors the RFC 7517 wire format keeps the configuration path free of System.Text.Json roundtrips and custom converters. Every JWK member binds out-of-the-box as a nullable string, the mapper handles base64url decoding and the kty dispatch in one place, and the schema lives as explicit C# code — refactor-safe and IntelliSense-friendly. The configuration binder itself produces path-aware error messages on invalid input, so operators do not have to translate generic JSON exceptions back to config paths.

Each property carries a Microsoft.Extensions.Configuration.ConfigurationKeyNameAttribute pointing at the RFC 7517 wire name from JsonWebKeyPropertyNames, so config keys can be written exactly as JWK consumers expect them (kty, n, e, …) and the binder maps them unambiguously to the C# properties.

A native polymorphic binding via [JsonPolymorphic] + [JsonDerivedType] was considered and rejected after empirical verification on net8.0 / net9.0 / net10.0: Microsoft.Extensions.Configuration.Binder does not honour these System.Text.Json attributes and still throws «Cannot create instance of abstract type» on JsonWebKey. The flat DTO is the practical workaround until the binder gains its own polymorphism support.

Adding support for a new JWK type that the RFC introduces (for example OKP per RFC 8037 for Ed25519 / X25519 keys) is a fully localised change: add the new fields to this DTO and a new branch in the Kty switch inside ToJsonWebKey(). No changes required in the polymorphic JsonWebKey hierarchy beyond the new concrete subtype itself.

Properties

JsonWebKeySettings.Alg Property

Algorithm intended for use with this key.

public string? Alg { get; init; }

Property Value

System.String

JsonWebKeySettings.Crv Property

EC curve identifier (crv): P-256, P-384, or P-521.

public string? Crv { get; init; }

Property Value

System.String

JsonWebKeySettings.D Property

RSA or EC private exponent / key (d).

public string? D { get; init; }

Property Value

System.String

JsonWebKeySettings.Dp Property

RSA first factor CRT exponent (dp).

public string? Dp { get; init; }

Property Value

System.String

JsonWebKeySettings.Dq Property

RSA second factor CRT exponent (dq).

public string? Dq { get; init; }

Property Value

System.String

JsonWebKeySettings.E Property

RSA public exponent (e).

public string? E { get; init; }

Property Value

System.String

JsonWebKeySettings.K Property

Symmetric (oct) key value.

public string? K { get; init; }

Property Value

System.String

JsonWebKeySettings.Kid Property

Key ID for selection in multi-key environments.

public string? Kid { get; init; }

Property Value

System.String

JsonWebKeySettings.Kty Property

Key type discriminator: RSA, EC, or oct.

public string? Kty { get; init; }

Property Value

System.String

JsonWebKeySettings.N Property

RSA modulus (n).

public string? N { get; init; }

Property Value

System.String

JsonWebKeySettings.P Property

RSA first prime factor (p).

public string? P { get; init; }

Property Value

System.String

JsonWebKeySettings.Q Property

RSA second prime factor (q).

public string? Q { get; init; }

Property Value

System.String

JsonWebKeySettings.Qi Property

RSA first CRT coefficient (qi).

public string? Qi { get; init; }

Property Value

System.String

JsonWebKeySettings.Use Property

Public key use: sig or enc.

public string? Use { get; init; }

Property Value

System.String

JsonWebKeySettings.X Property

EC X coordinate.

public string? X { get; init; }

Property Value

System.String

JsonWebKeySettings.Y Property

EC Y coordinate.

public string? Y { get; init; }

Property Value

System.String

Methods

JsonWebKeySettings.ToJsonWebKey() Method

Maps this flat DTO to the corresponding concrete JsonWebKey subtype.

public Abblix.Jwt.JsonWebKey ToJsonWebKey();

Returns

JsonWebKey

Exceptions

System.InvalidOperationException
Kty is missing or not RSA/EC/oct.

System.FormatException
A byte-array member is not valid base64url.

Operators

JsonWebKeySettings.implicit operator JsonWebKey(JsonWebKeySettings) Operator

Convenience implicit conversion to JsonWebKey; delegates to ToJsonWebKey().

public static Abblix.Jwt.JsonWebKey implicit operator Abblix.Jwt.JsonWebKey(Abblix.Oidc.Server.Common.Configuration.JsonWebKeySettings settings);

Parameters

settings JsonWebKeySettings

Returns

JsonWebKey