Classes

The following classes are available globally.

JWTEncoder

  • A thread safe encoder that signs the JWT header and claims using the provided algorithm and encodes a JWT instance as either Data or a JWT String.

    Usage Example:

    struct MyClaims: Claims {
       var name: String
    }
    var jwt = JWT(claims: MyClaims(name: "John Doe"))
    let privateKey = "<PrivateKey>".data(using: .utf8)!
    let rsaJWTEncoder = JWTEncoder(jwtSigner: JWTSigner.rs256(privateKey: privateKey))
    do {
       let jwtString = try rsaJWTEncoder.encodeToString(jwt)
    } catch {
       print("Failed to encode JWT: \(error)")
    }
    
    See more

    Declaration

    Swift

    public class JWTEncoder : BodyEncoder

JWTDecoder

  • A thread safe decoder that decodes either Data or a JWT String as a JWT instance and verifies the signiture using the provided algorithm.

    Usage Example:

    struct MyClaims: Claims {
       var name: String
    }
    let publicKey = "<PublicKey>".data(using: .utf8)!
    let rsaJWTDecoder = JWTDecoder(jwtVerifier: JWTVerifier.rs256(publicKey: publicKey))
    do {
       let jwt = try rsaJWTDecoder.decode(JWT<MyClaims>.self, fromString: exampleJWTString)
    } catch {
       print("Failed to decode JWT: \(error)")
    }
    
    See more

    Declaration

    Swift

    public class JWTDecoder : BodyDecoder