Swiftpack.co - Package - vapor/jwt

JWTKit

Documentation Team Chat MIT License Continuous Integration Swift 5.0


Original author

Github

link
Stars: 244

Dependencies

Releases

Adds JWT validation for Apple and Google - 2020-02-19 02:04:26

Allows for simple validation of Sign in with Apple or google. In your routes, you can now do this:

public func registerFromSignInWithApple(req: Request) throws -> EventLoopFuture<User> {
    req.jwt.apple
        .verify(applicationIdentifier: "com.whoever.myapp")
        .map { (token: AppleIdentityToken) in
            let uniqueUserID = token.subject.value

            // Create the user in the database

            return user
    }
}

Add JWKSCache helper for storing JWKS - 2020-02-14 19:55:14

Provides a way that servers can download JWKS files in response to HTTP requests such that only one request will ever be performing a download at a time. If the remote server provides caching headers this ensures the downloads are cached appropriately.

final class RouteController {
    let apple: JWKSCache

    init(app: Application) {
        apple = .init(keyURL: "https://appleid.apple.com/auth/keys", client: app.client)
    }

    func signIn(_ req: Request) throws -> EventLoopFuture<Void> {
        apple.keys(on: req).flatMap { jwks in
            guard let key = jwks.find(identifier: "AIDOPK1", type: .rsa) else {
                return req.eventLoop.makeFailedFuture(Abort(.internalServerError))
            }

            // Use the key here
        }
    }
}

JWT 4.0.0 Beta 2 - 2019-12-09 16:55:00

This package is now a Vapor + JWTKit integration.

import JWT
import Vapor

try app.jwt.signers.use(.es512(key: .generate()))

app.post("login") { req -> LoginResponse in
    let credentials = try req.content.decode(LoginCredentials.self)
    return try LoginResponse(
        token: req.jwt.sign(User(name: credentials.name))
    )
}

app.get("me") { req -> String in
    try req.jwt.verify(as: User.self).name
}

JWT 3.1.1 - 2019-10-24 15:41:28

  • Fixed warnings about public access modifier being redundant. (#108)

JWT 3.1.0 - 2019-10-23 14:48:44

  • Adds JWK signer support. (#106)
let json = """
{"kty":"RSA", ...}
"""
let signer = try JWTSigner.jwk(key: json)

4.0.0 Alpha 1.3 - 2019-10-07 22:08:53

  • Fixed an intermittent verification failure with ECDSA signed tokens. (#103, #104)

JWTKit 4.0.0 Alpha 1.2 - 2019-08-29 22:48:36

  • Fixed ECDSA signature encoding to follow spec. (#100, #102)

JWTKit 4.0.0 Alpha 1.1 - 2019-08-15 04:27:14

Fixed:

  • Added jwtkit_ namespace to OpenSSL shim methods to avoid clashes (#101)

JWTKit 4.0.0 Alpha 1 - 2019-06-13 22:24:52

More information on Vapor 4 alpha releases:

https://medium.com/@codevapor/vapor-4-alpha-1-releases-begin-94a4bc79dd9a

API Docs:

https://api.vapor.codes/jwt-kit/master/JWTKit/index.html

JWT 3.0.0 - 2018-08-14 19:48:34

JWT 3.0 is here 🎉 🔏 JSON Web Token signing and verification (HMAC, RSA)

Docs: https://docs.vapor.codes/3.0/jwt/getting-started/

API Docs: https://api.vapor.codes/jwt/latest/JWT

JWT 3.0.0 RC 2.1.2 - 2018-05-31 16:22:35

Fixed:

  • Fixed a potential security issue that made JWT verification vulnerable to timing attacks. JWT verification will now always check all bytes, even if it has already detected a miss.

JWT 3.0.0 RC 2.1 - 2018-03-25 23:12:28

Fixed:

  • Updated to latest crypto digest methods.

API Docs: https://api.vapor.codes/jwt/3.0.0-rc.2.1/JWT/

Milestone: 3.0.0-rc.2.1

JWT 3.0.0 RC 2 - 2018-03-21 22:32:06

New:

  • Vapor is now running on Swift NIO!

Milestone

JWT 3.0.0 RC 1 - 2018-02-28 03:39:14

New:

  • Added RS256, RS384, and RS512 signature support
import Crypto
import JWT

// create public and private key (only public required for verification)
let privateKey: Data = ...
let publicKey: Data = ...
let privateSigner = JWTSigner.rs256(key: .private2048(privateKey))
let publicSigner = JWTSigner.rs256(key: .public2048(publicKey))

// serialize jwt (requires private key)
let payload: TestPayload = ...
var jwt = JWT(payload: payload)
_ = try jwt.sign(using: publicSigner) // throws, can't sign w/ public signer
let data = try jwt.sign(using: privateSigner)

// parse jwt (public and private key work)
let parsed = try JWT<TestPayload>(from: data, verifiedUsing: publicSigner)
let parsed2 = try JWT<TestPayload>(from: data, verifiedUsing: privateSigner) // also works
print(parsed.payload)
print(parsed2.payload)

Milestone

JWT 3.0.0 Beta 1.1 - 2018-02-15 02:46:52

JWT 3.0.0 Beta 1 - 2018-02-12 17:29:10

JWT 2.3.0 - 2017-09-13 20:49:30

New:

  • Swift 4 support.

Milestone

JWT 2.2.1 - 2017-07-20 00:04:25

Fixed:

  • Publicize required KeyIDHeader initializer.

JWT 2.2.0 - 2017-07-19 23:55:20

New:

  • JWK support for RSA Keys
  • StringBacked is now public
  • Key ID header

Milestone

JWT 2.1.1 - 2017-06-05 15:52:33

Fixed:

  • Expose internal API to prevent compiler crash related to SR-2925.

Milestone

JWT 2.1 - 2017-05-25 13:43:49

New:

  • X509 certificate support.

Fixed:

  • Worked around Swift Foundation date bug.
  • Playgrounds file works again.

JWT 2.0.1 - 2017-05-19 15:08:28

Fixed:

  • Better JWT signing error.

Milestone

JWT 2.0 - 2017-05-18 18:54:44

🎉

JWT 2.0 seeks to improve and simplify the great features of JWT.

JWT 1.0.1 (for Vapor 1) - 2017-04-07 21:01:12

Fixed:

  • Crashes on Linux with Swift 3.1 (#41 -> #44)

Upgrading is highly recommended for Linux deployments.

To upgrade, do one of the following:

  • Use swift package update; or
  • Use vapor update (Toolbox ≥ 1.0.9 required); or
  • Perform a complete clean (including Package.pins if exists) and build/regenerate again.

JWT 2.0 Beta 2 - 2017-04-07 11:34:11

New:

  • Updated readme

JWT 2.0 Beta 1 - 2017-03-29 18:25:59

Fixed:

  • Removed different encoding options
  • Use bytes in the JWT

https://github.com/vapor/jwt/pull/39

JWT 1.0.0 (for Vapor 1.x) - 2017-03-29 16:21:23

Fixed:

  • signature validation errors when parsing tokens from external sources
  • default settings not using the Base64url encoding (as defined by RFC 7519)

Pull requests:

  • #38

JWT 0.11.1 - 2017-03-20 10:57:55

Fixed:

  • Base64URL encoding by default

JWT 0.11 - 2017-03-19 14:17:14

New:

  • Added .rawToken

Fixed:

  • Different order in JSON serialization will no longer cause issues with signature verification

JWT 0.10.1 - 2017-03-19 13:18:52

Fixed:

  • makeBytes() update