Class
JWTKeyCollection
A collection of JWT and JWK signers for handling JSON Web Tokens (JWTs).
actor JWTKeyCollection
Overview
This actor provides methods to manage multiple keys. It can be used to verify and decode JWTs, as well as to sign and encode JWTs. It also facilitates the encoding and decoding of JWTs using custom or default JSON encoders and decoders.
Topics
Initializers
init(defaultJWTParser: some JWTParser, defaultJWTSerializer: some JWTSerializer, logger: Logger)Creates a new empty Signers collection.
Instance Properties
Instance Methods
func add(ecdsa: some ECDSAKey, kid: JWKIdentifier?, parser: some JWTParser, serializer: some JWTSerializer) -> SelfAdds an ECDSA key to the collection.func add(eddsa: some EdDSAKey, kid: JWKIdentifier?, parser: some JWTParser, serializer: some JWTSerializer) -> SelfAdds an EdDSA key to the collection using anEdDSAKey.func add(hmac: HMACKey, digestAlgorithm: DigestAlgorithm, kid: JWKIdentifier?, parser: some JWTParser, serializer: some JWTSerializer) -> SelfAdds an HMAC key to the collection.func add(jwk: JWK, isDefault: Bool?) throws -> SelfAdds a singleJWK(JSON Web Key) to the collection.func add(jwks: JWKS) throws -> SelfAdds aJWKS(JSON Web Key Set) directly to the collection.func add(jwksJSON: String) throws -> SelfAdds aJWKS(JSON Web Key Set) to the collection by decoding a JSON string.func add(pss: some RSAKey, digestAlgorithm: DigestAlgorithm, kid: JWKIdentifier?, parser: some JWTParser, serializer: some JWTSerializer) -> SelfAdds a PSS key to the collection.func add(rsa: some RSAKey, digestAlgorithm: DigestAlgorithm, kid: JWKIdentifier?, parser: some JWTParser, serializer: some JWTSerializer) -> SelfAdds an RSA key to the collection.func addUnsecuredNone(kid: JWKIdentifier?, parser: some JWTParser, serializer: some JWTSerializer) -> SelfAdds a configuration for JWTs without a signature.func clearDefault() -> BoolRemoves the default signer. The signer might still exist in the collection as non-default one.func getKey(for: JWKIdentifier?, alg: String?) async throws -> any JWTAlgorithmRetrieves the key associated with the provided key identifier (KID) and algorithm (ALG), if available.func remove(kid: JWKIdentifier) -> BoolRemoves the key with the selected KID from the collection. If the default matches, that one is also removed.func removeAll(except: [JWKIdentifier], clearingDefault: Bool) -> IntRemoves all keys from the collection except the ones defined in thekidsparameter.func sign(some JWTPayload, kid: JWKIdentifier?, header: JWTHeader) async throws -> StringSigns a JWT payload and returns the JWT string.func unverified(_:as:parser:)Decodes an unverified JWT payload.func verify(_:as:iteratingKeys:)Verifies and decodes a JWT token to extract the payload.
Relationships
Conforms To
Swift.SendableSwift.SendableMetatype_Concurrency.Actor