/// <summary> /// Defines the 'jwk' header. /// </summary> /// <param name="jwk"></param> /// <returns></returns> public JwtDescriptorBuilder Jwk(Jwk jwk) => AddHeader(HeaderParameters.JwkUtf8, jwk.ToString());
/// <summary>Defines the <see cref="Jwk"/> used to decrypt the tokens.</summary> public TokenValidationPolicyBuilder WithDecryptionKey(string issuer, Jwk encryptionKey) => WithDecryptionKeys(new Jwks(issuer, encryptionKey));
/// <summary>Initializes a new instance of the <see cref="JwkJweDescriptor"/> class.</summary> public JwksJweDescriptor(Jwk encryptionKey, KeyManagementAlgorithm alg, EncryptionAlgorithm enc, CompressionAlgorithm?zip = null, string?typ = null, string?cty = JwtContentTypeValues.Jwks) : base(encryptionKey, alg, enc, zip, typ, cty) { }
/// <summary> /// Defines the default signature validation when there is no issuer configuration. /// Use the method <see cref="RequireSignature(string, Jwk, SignatureAlgorithm)"/> for linking the issuer with the signature. /// </summary> public TokenValidationPolicyBuilder RequireSignatureByDefault(Jwk key, SignatureAlgorithm?algorithm) => RequireSignatureByDefault(new Jwks(key), algorithm);
/// <summary>Defines the <see cref="Jwk"/> used to decrypt the tokens.</summary> public TokenValidationPolicyBuilder WithDecryptionKey(Jwk encryptionKey) => WithDecryptionKeys(new Jwks(encryptionKey));
/// <summary>Initializes a new instance of the <see cref="JweDescriptor{TPayload}"/> class.</summary> /// <param name="encryptionKey"></param> /// <param name="alg"></param> /// <param name="enc"></param> /// <param name="zip"></param> /// <param name="typ"></param> /// <param name="cty"></param> protected JweDescriptor(Jwk encryptionKey, KeyManagementAlgorithm alg, EncryptionAlgorithm enc, CompressionAlgorithm?zip = null, string?typ = null, string?cty = null) { _encryptionKey = encryptionKey ?? throw new ArgumentNullException(nameof(encryptionKey)); _alg = alg ?? throw new ArgumentNullException(nameof(alg)); _enc = enc ?? throw new ArgumentNullException(nameof(enc)); _zip = zip ?? CompressionAlgorithm.NoCompression; var kid = encryptionKey.Kid; if (!kid.EncodedUtf8Bytes.IsEmpty) { _kid = kid; if (zip != null) { if (cty != null) { _cty = cty; Header.FastAdd( new JwtMember(JwtHeaderParameterNames.Alg, alg.Name), new JwtMember(JwtHeaderParameterNames.Enc, enc.Name), new JwtMember(JwtHeaderParameterNames.Kid, kid), new JwtMember(JwtHeaderParameterNames.Zip, zip.Name), new JwtMember(JwtHeaderParameterNames.Cty, cty)); } else { Header.FastAdd( new JwtMember(JwtHeaderParameterNames.Alg, alg.Name), new JwtMember(JwtHeaderParameterNames.Enc, enc.Name), new JwtMember(JwtHeaderParameterNames.Kid, kid), new JwtMember(JwtHeaderParameterNames.Zip, zip.Name)); } } else { if (cty != null) { _cty = cty; Header.FastAdd( new JwtMember(JwtHeaderParameterNames.Alg, alg.Name), new JwtMember(JwtHeaderParameterNames.Enc, enc.Name), new JwtMember(JwtHeaderParameterNames.Kid, kid), new JwtMember(JwtHeaderParameterNames.Cty, cty)); } else { Header.FastAdd( new JwtMember(JwtHeaderParameterNames.Alg, alg.Name), new JwtMember(JwtHeaderParameterNames.Enc, enc.Name), new JwtMember(JwtHeaderParameterNames.Kid, kid)); } } } else { if (zip != null) { if (cty != null) { _cty = cty; Header.FastAdd( new JwtMember(JwtHeaderParameterNames.Alg, alg.Name), new JwtMember(JwtHeaderParameterNames.Enc, enc.Name), new JwtMember(JwtHeaderParameterNames.Zip, zip.Name), new JwtMember(JwtHeaderParameterNames.Cty, cty)); } else { Header.FastAdd( new JwtMember(JwtHeaderParameterNames.Alg, alg.Name), new JwtMember(JwtHeaderParameterNames.Enc, enc.Name), new JwtMember(JwtHeaderParameterNames.Zip, zip.Name)); } } else { if (cty != null) { _cty = cty; Header.FastAdd( new JwtMember(JwtHeaderParameterNames.Alg, alg.Name), new JwtMember(JwtHeaderParameterNames.Enc, enc.Name), new JwtMember(JwtHeaderParameterNames.Cty, cty)); } else { Header.FastAdd( new JwtMember(JwtHeaderParameterNames.Alg, alg.Name), new JwtMember(JwtHeaderParameterNames.Enc, enc.Name)); } } } if (typ != null) { _typ = typ; Header.Add(JwtHeaderParameterNames.Typ, typ); } }
public JwtReader(Jwk encryptionKey) => throw new NotImplementedException();
internal Jwt(JwtHeader header, byte[] data, Jwk encryptionKey) { Header = header; Binary = data; EncryptionKey = encryptionKey; }
internal Jwt(JwtHeader header, Jwt nestedToken, Jwk encryptionKey) { Header = header; _nestedToken = nestedToken; EncryptionKey = encryptionKey; }
/// <summary>Initializes a new instance of <see cref="PlaintextJweDescriptor"/>.</summary> public PlaintextJweDescriptor(Jwk encryptionKey, KeyManagementAlgorithm alg, EncryptionAlgorithm enc, CompressionAlgorithm?zip = null, string?typ = JwtMediaTypeValues.Plain, string?cty = null) : base(encryptionKey, alg, enc, zip, typ, cty) { }