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:defaultJWTSerializer:logger:)Creates a new empty Signers collection.
Instance Properties
Instance Methods
add(ecdsa:kid:parser:serializer:)Adds an ECDSA key to the collection.add(eddsa:kid:parser:serializer:)Adds an EdDSA key to the collection using anEdDSAKey.add(hmac:digestAlgorithm:kid:parser:serializer:)Adds an HMAC key to the collection.add(jwk:isDefault:)Adds a singleJWK(JSON Web Key) to the collection.add(jwks:)Adds aJWKS(JSON Web Key Set) directly to the collection.add(jwksJSON:)Adds aJWKS(JSON Web Key Set) to the collection by decoding a JSON string.add(pss:digestAlgorithm:kid:parser:serializer:)Adds a PSS key to the collection.add(rsa:digestAlgorithm:kid:parser:serializer:)Adds an RSA key to the collection.addUnsecuredNone(kid:parser:serializer:)Adds a configuration for JWTs without a signature.clearDefault()Removes the default signer. The signer might still exist in the collection as non-default one.getKey(for:alg:)Retrieves the key associated with the provided key identifier (KID) and algorithm (ALG), if available.remove(kid:)Removes the key with the selected KID from the collection. If the default matches, that one is also removed.removeAll(except:clearingDefault:)Removes all keys from the collection except the ones defined in thekidsparameter.sign(_:kid:header:)Signs a JWT payload and returns the JWT string.unverified(_:as:parser:)Decodes an unverified JWT payload.verify(_:as:iteratingKeys:)Verifies and decodes a JWT token to extract the payload.
Relationships
Conforms To
Swift.SendableSwift.SendableMetatype_Concurrency.Actor