Framework
JWT
JWT provides integrations between JWTKit and Vapor to make it easy to work with JWTs in your Vapor application.
Overview
For more details, see the Vapor Docs.
Topics
Classes
actor JWTKeyCollectionA collection of JWT and JWK signers for handling JSON Web Tokens (JWTs).
Protocols
protocol ECDSACurveTypeA protocol defining the requirements for elliptic curve types used in ECDSA (Elliptic Curve Digital Signature Algorithm).protocol ECDSAKeyprotocol ECDSAPrivateKeyprotocol ECDSAPublicKeyprotocol ECDSASignatureprotocol ECDSASigningAlgorithmprotocol EdDSAKeyThis protocol represents a key that can be used for signing and verifying EdDSA signatures. BothEdDSA.PublicKeyandEdDSA.PrivateKeyconform to this protocol.protocol JWTAlgorithmA protocol defining the necessary functionality for a JWT (JSON Web Token) algorithm. All algorithms conform toJWTAlgorithmto provide custom signing and verification logic for JWT tokens.protocol JWTAuthenticatorprotocol JWTClaimA claim is a codable, top-level property of a JWT payload. Multiple claims form a payload. Some claims, such as expiration claims, are inherently verifiable. Each claim able to verify itself provides an appropriate method for doing so, depending on the specific claim.protocol JWTJSONDecoderprotocol JWTJSONEncoderprotocol JWTMultiValueClaimprotocol JWTParserprotocol JWTPayloadA JWT payload is a Publically Readable set of claims. Each variable represents a claim.protocol JWTSerializerprotocol JWTUnixEpochClaimprotocol MLDSAKeyThis protocol represents a key that can be used for signing and verifying MLDSA signatures. BothMLDSA.PublicKeyandMLDSA.PrivateKeyconform to this protocol, which is whatadd(mldsa:kid:parser:serializer:)accepts.protocol MLDSAPrivateKeyThe requirements JWTKit needs from the underlying SwiftCrypto private key backing anMLDSA.PrivateKey.protocol MLDSAPublicKeyThe requirements JWTKit needs from the underlying SwiftCrypto public key backing anMLDSA.PublicKey.protocol MLDSATypeAn MLDSA parameter set, which determines the strength of the keys and signatures it produces.protocol RSAKeyTheRSAKeyprotocol defines the common interface for both public and private RSA keys. Implementers of this protocol can represent keys used for cryptographic operations in the RSA algorithm.protocol ValidationTimePayloadA protocol defining the requirements for payloads that include a validation time.
Structures
struct AppleIdentityTokenstruct AudienceClaimThe “aud” (audience) claim identifies the recipients that the JWT is intended for. Each principal intended to process the JWT MUST identify itself with a value in the audience claim. If the principal processing the claim does not identify itself with a value in the “aud” claim when this claim is present, then the JWT MUST be rejected. In the general case, the “aud” value is an array of case- sensitive strings, each containing a StringOrURI value. In the special case when the JWT has one audience, the “aud” value MAY be a single case-sensitive string containing a StringOrURI value. The interpretation of audience values is generally application specific. Use of this claim is OPTIONAL.struct BoolClaimA claim which represents a boolstruct DefaultJWTParserstruct DefaultJWTSerializerstruct DigestAlgorithmstruct ECDSACurveA struct representing an Elliptic Curve used in Elliptic Curve Digital Signature Algorithm (ECDSA).struct EdDSACurveA struct representing an Elliptic Curve used in EdDSA (Edwards-curve Digital Signature Algorithm).struct EmptyPolicyThis Policy acts as a placeholder. Its result is always positive.struct ExpirationClaimThe “exp” (expiration time) claim identifies the expiration time on or after which the JWT MUST NOT be accepted for processing. The processing of the “exp” claim requires that the current date/time MUST be before the expiration date/time listed in the “exp” claim. Implementers MAY provide for some small leeway, usually no more than a few minutes, to account for clock skew. Its value MUST be a number containing a NumericDate value. Use of this claim is OPTIONAL.struct FirebaseAuthIdentityTokenstruct GoogleHostedDomainClaimstruct GoogleIdentityTokenstruct HMACKeystruct IDClaimThe “jti” (JWT ID) claim provides a unique identifier for the JWT. The identifier value MUST be assigned in a manner that ensures that there is a negligible probability that the same value will be accidentally assigned to a different data object; if the application uses multiple issuers, collisions MUST be prevented among values produced by different issuers as well. The “jti” claim can be used to prevent the JWT from being replayed. The “jti” value is a case- sensitive string. Use of this claim is OPTIONAL.struct IssuedAtClaimThe “iat” (issued at) claim identifies the time at which the JWT was issued. This claim can be used to determine the age of the JWT. Its value MUST be a number containing a NumericDate value. Use of this claim is OPTIONAL.struct IssuerClaimThe “iss” (issuer) claim identifies the principal that issued the JWT. The processing of this claim is generally application specific. The “iss” value is a case-sensitive string containing a StringOrURI value. Use of this claim is OPTIONAL.struct JWKA JSON Web Key.struct JWKIdentifierstruct JWKSA JSON Web Key Set.struct JWTErrorJWT error type.struct JWTHeaderThe header (details) used for signing and processing the JWT.struct LocaleClaimstruct MicrosoftIdentityTokenstruct NotBeforeClaimThe “nbf” (not before) claim identifies the time before which the JWT MUST NOT be accepted for processing. The processing of the “nbf” claim requires that the current date/time MUST be after or equal to the not-before date/time listed in the “nbf” claim. Implementers MAY provide for some small leeway, usually no more than a few minutes, to account for clock skew. Its value MUST be a number containing a NumericDate value. Use of this claim is OPTIONAL.struct SubjectClaimThe “sub” (subject) claim identifies the principal that is the subject of the JWT. The claims in a JWT are normally statements about the subject. The subject value MUST either be scoped to be locally unique in the context of the issuer or be globally unique. The processing of this claim is generally application specific. The “sub” value is a case-sensitive string containing a StringOrURI value. Use of this claim is OPTIONAL.struct TenantIDClaimThe “tid” (tenant ID) claim represents the unique identifier of the Azure AD tenant that the token was issued by. This claim is present in tokens when a user signs in to an application through Azure Active Directory. The tenant ID is a key piece of information for identifying the tenant realm and is essential for applications that are multi-tenant aware. The tenant ID is a GUID that is immutable and uniquely identifies an Azure AD tenant. This claim is crucial for applications that need to enforce tenant-specific access control, and for logging or auditing the tenant context of the authenticated user. The value of “tid” is a case-sensitive string representing a GUID. The presence of this claim and its proper validation are critical for the security of multi-tenant applications.struct X5CVerifierAn object for verifying JWS tokens that contain thex5cheader parameter with a set of known root certificates.
Type Aliases
typealias ECDSAParametersA typealias representing the parameters of an ECDSA (Elliptic Curve Digital Signature Algorithm) key.typealias ES256PrivateKeytypealias ES256PublicKeytypealias ES384PrivateKeytypealias ES384PublicKeytypealias ES512PrivateKeytypealias ES512PublicKeytypealias JWKSCacheA thread-safe and atomic class for retrieving JSON Web Key Sets which honors the HTTPCache-Control,ExpiresandEtagheaders.typealias MLDSA65PrivateKeyAn MLDSA private key using theMLDSA65parameter set, which signs and verifiesML-DSA-65tokens.typealias MLDSA65PublicKeyAn MLDSA public key using theMLDSA65parameter set, which signs and verifiesML-DSA-65tokens.typealias MLDSA87PrivateKeyAn MLDSA private key using theMLDSA87parameter set, which signs and verifiesML-DSA-87tokens.typealias MLDSA87PublicKeyAn MLDSA public key using theMLDSA87parameter set, which signs and verifiesML-DSA-87tokens.
Enumerations
enum ECDSAenum EdDSANamespace for the EdDSA (Edwards-curve Digital Signature Algorithm) signing algorithm. EdDSA is a modern signing algorithm that is efficient and fast.enum InsecureA container for older, cryptographically insecure algorithms.enum JWTHeaderFieldenum MLDSANamespace for the MLDSA (Module-Lattice-Based Digital Signature Algorithm) signing algorithm.