IdentityShroud/IdentityShroud.Core/DTO/JsonWebKey.cs

39 lines
1.2 KiB
C#
Raw Normal View History

2026-02-06 19:58:01 +01:00
using System.Text.Json.Serialization;
namespace IdentityShroud.Core.Messages;
2026-02-14 14:54:48 +01:00
// https://www.rfc-editor.org/rfc/rfc7517.html
2026-02-06 19:58:01 +01:00
public class JsonWebKey
{
[JsonPropertyName("kty")]
public string KeyType { get; set; } = "RSA";
2026-02-14 14:54:48 +01:00
// Common values sig(nature) enc(ryption)
2026-02-06 19:58:01 +01:00
[JsonPropertyName("use")]
2026-02-14 14:54:48 +01:00
public string? Use { get; set; } = "sig"; // "sig" for signature, "enc" for encryption
2026-02-06 19:58:01 +01:00
2026-02-14 14:54:48 +01:00
// Per standard this field is optional for now we will use RS256
2026-02-06 19:58:01 +01:00
[JsonPropertyName("alg")]
2026-02-14 14:54:48 +01:00
public string? Algorithm { get; set; } = "RS256";
2026-02-06 19:58:01 +01:00
[JsonPropertyName("kid")]
2026-02-14 14:54:48 +01:00
public required string KeyId { get; set; }
2026-02-06 19:58:01 +01:00
// RSA Public Key Components
[JsonPropertyName("n")]
2026-02-14 14:54:48 +01:00
public required string Modulus { get; set; }
2026-02-06 19:58:01 +01:00
[JsonPropertyName("e")]
2026-02-14 14:54:48 +01:00
public required string Exponent { get; set; }
2026-02-06 19:58:01 +01:00
// Optional fields
[JsonPropertyName("x5c")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public List<string> X509CertificateChain { get; set; }
[JsonPropertyName("x5t")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public string X509CertificateThumbprint { get; set; }
}