Structures

The following structures are available globally.

  • A representation of a JSON Web Token header. https://tools.ietf.org/html/rfc7515#section-4.1

    Usage Example:

    struct MyClaims: Claims {
       var name: String
    }
    let myHeader = Header(kid: "keyID")
    let jwt = JWT(header: myHeader, claims: MyClaims(name: "Kitura"))
    
    See more

    Declaration

    Swift

    public struct Header: Codable
  • JWT

    A struct representing the Header and Claims of a JSON Web Token.

    Usage Example:

    struct MyClaims: Claims {
       var name: String
    }
    let jwt = JWT(claims: MyClaims(name: "Kitura"))
    let key = "<PrivateKey>".data(using: .utf8)!
    let signedJWT: String? = try? jwt.sign(using: .rs256(key: key, keyType: .privateKey))
    
    See more

    Declaration

    Swift

    public struct JWT<T: Claims>: Codable
  • A struct representing the different errors that can be thrown by SwiftJWT

    See more

    Declaration

    Swift

    public struct JWTError: Error, Equatable
  • A struct that will be used to sign the JWT Header and Claims and generate a signed JWT. For RSA and ECDSA, the provided key should be a .utf8 encoded PEM String.

    Usage Example:

    let pemString = """
    -----BEGIN RSA PRIVATE KEY-----
    MIICWwIBAAKBgQDdlatRjRjogo3WojgGHFHYLugdUWAY9iR3fy4arWNA1KoS8kVw
    33cJibXr8bvwUAUparCwlvdbH6dvEOfou0/gCFQsHUfQrSDv+MuSUMAe8jzKE4qW
    +jK+xQU9a03GUnKHkkle+Q0pX/g6jXZ7r1/xAK5Do2kQ+X5xK9cipRgEKwIDAQAB
    AoGAD+onAtVye4ic7VR7V50DF9bOnwRwNXrARcDhq9LWNRrRGElESYYTQ6EbatXS
    3MCyjjX2eMhu/aF5YhXBwkppwxg+EOmXeh+MzL7Zh284OuPbkglAaGhV9bb6/5Cp
    uGb1esyPbYW+Ty2PC0GSZfIXkXs76jXAu9TOBvD0ybc2YlkCQQDywg2R/7t3Q2OE
    2+yo382CLJdrlSLVROWKwb4tb2PjhY4XAwV8d1vy0RenxTB+K5Mu57uVSTHtrMK0
    GAtFr833AkEA6avx20OHo61Yela/4k5kQDtjEf1N0LfI+BcWZtxsS3jDM3i1Hp0K
    Su5rsCPb8acJo5RO26gGVrfAsDcIXKC+bQJAZZ2XIpsitLyPpuiMOvBbzPavd4gY
    6Z8KWrfYzJoI/Q9FuBo6rKwl4BFoToD7WIUS+hpkagwWiz+6zLoX1dbOZwJACmH5
    fSSjAkLRi54PKJ8TFUeOP15h9sQzydI8zJU+upvDEKZsZc/UhT/SySDOxQ4G/523
    Y0sz/OZtSWcol/UMgQJALesy++GdvoIDLfJX5GBQpuFgFenRiRDabxrE9MNUZ2aP
    FaFp+DyAe+b4nDwuJaW2LURbr8AEZga7oQj0uYxcYw==
    -----END RSA PRIVATE KEY-----
    """
    let privateKey = pemString.data(using: .utf8)!
    let jwtSigner = JWTSigner.rs256(privateKey: privateKey)
    struct MyClaims: Claims {
       var name: String
    }
    let jwt = JWT(claims: MyClaims(name: "Kitura"))
    let signedJWT = try? jwt.sign(using: jwtSigner)
    
    See more

    Declaration

    Swift

    public struct JWTSigner
  • A struct that will be used to verify the signature of a JWT is valid for the provided Header and Claims. For RSA and ECDSA, the provided key should be a .utf8 encoded PEM String.

    Usage Example:

    let pemString = """
    -----BEGIN PUBLIC KEY-----
    MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDdlatRjRjogo3WojgGHFHYLugd
    UWAY9iR3fy4arWNA1KoS8kVw33cJibXr8bvwUAUparCwlvdbH6dvEOfou0/gCFQs
    HUfQrSDv+MuSUMAe8jzKE4qW+jK+xQU9a03GUnKHkkle+Q0pX/g6jXZ7r1/xAK5D
    o2kQ+X5xK9cipRgEKwIDAQAB
    -----END PUBLIC KEY-----
    """
    let signedJWT = "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1lIjoiS2l0dXJhIn0.o2Rv_w1W6qfkldgb6FwzC3tAFEzo7WyYcLyykijCEqDbW8A7TwoFev85KGo_Bi7eNaSgZ6Q8jgkA31r8EDQWtSRg3_o5Zlq-ZCndyVeibgbyM2BMVUGcGzkUD2ikARfnb6GNGHr2waVeFSDehTN8WTLl0mGFxUE6wx5ZugR7My0"
    struct MyClaims: Claims {
       var name: String
    }
    let jwt = JWT(claims: MyClaims(name: "Kitura"))
    let publicKey = pemString.data(using: .utf8)!
    let jwtVerifier = JWTVerifier.rs256(publicKey: publicKey)
    let verified: Bool = jwt.verify(signedJWT, using: jwtVerifier)
    
    See more

    Declaration

    Swift

    public struct JWTVerifier
  • ValidateClaimsResult list the possible results of a call to JWT.validateClaims method. In case of successful validation, .success is returned, all other cases list various problems that may occur during claims validation and indicate that the validation failed.

    See more

    Declaration

    Swift

    public struct ValidateClaimsResult: CustomStringConvertible, Equatable