Skip to content

Commit

Permalink
Update swift version and readme for beta 3 (#164)
Browse files Browse the repository at this point in the history
* Update swift version and readme for beta 3

* Update README
  • Loading branch information
ptoffy authored Apr 24, 2024
1 parent c095132 commit 6f512cb
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 16 deletions.
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:5.9
// swift-tools-version:5.10
import PackageDescription

let package = Package(
Expand Down
38 changes: 23 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<a href="LICENSE"><img src="https://design.vapor.codes/images/mitlicense.svg" alt="MIT License"></a>
<a href="https://github.com/vapor/jwt-kit/actions/workflows/test.yml"><img src="https://img.shields.io/github/actions/workflow/status/vapor/jwt-kit/test.yml?event=push&style=plastic&logo=github&label=tests&logoColor=%23ccc" alt="Continuous Integration"></a>
<a href="https://codecov.io/github/vapor/jwt-kit"><img src="https://img.shields.io/codecov/c/github/vapor/jwt-kit?style=plastic&logo=codecov&label=codecov"></a>
<a href="https://swift.org"><img src="https://design.vapor.codes/images/swift59up.svg" alt="Swift 5.9+"></a>
<a href="https://swift.org"><img src="https://design.vapor.codes/images/swift510up.svg" alt="Swift 5.10+"></a>
<a href="https://www.swift.org/sswg/incubation-process.html"><img src="https://design.vapor.codes/images/sswg-graduated.svg" alt="SSWG Incubation Level: Graduated"></a>
</p>
<br>
Expand All @@ -24,12 +24,12 @@ The table below shows a list of JWTKit major releases alongside their compatible

|Version|Swift|SPM|
|---|---|---|
|5.0|5.9+|`from: "5.0.0"`|
|5.0|5.10+|`from: "5.0.0"`|

Use the SPM string to easily include the dependendency in your `Package.swift` file

```swift
.package(url: "https://github.com/vapor/jwt-kit.git", from: "5.0.0")
.package(url: "https://github.com/vapor/jwt-kit.git", from: "5.0.0-beta.3")
```

and add it to your target's dependencies:
Expand All @@ -42,7 +42,7 @@ and add it to your target's dependencies:
### Supported Platforms

JWTKit supports all platforms supported by Swift 5.9 and later, with the exception of Windows.
JWTKit supports all platforms supported by Swift 5.10 and later, with the exception of Windows.

## Overview

Expand Down Expand Up @@ -90,7 +90,7 @@ To add a signing key to the collection, use the `add` method for the respective

```swift
// Registers an HS256 (HMAC-SHA-256) signer.
await keys.addHS256(key: "secret")
await keys.addHMAC(key: "secret", digestAlgorithm: .sha256)
```

This example uses the _very_ secure key `"secret"`.
Expand All @@ -99,7 +99,7 @@ You can also add an optional key identifier (`kid`) to the key:

```swift
// Registers an HS256 (HMAC-SHA-256) signer with a key identifier.
await keys.addHS256(key: "secret", kid: "my-key")
await keys.addHMAC(key: "secret", digestAlgorithm: .sha256, kid: "my-key")
```

This is useful when you have multiple keys and need to select the correct one for verification. Based on the `kid` defined in the JWT header, the correct key will be selected for verification.
Expand All @@ -117,7 +117,7 @@ struct ExamplePayload: JWTPayload {
var exp: ExpirationClaim
var admin: BoolClaim

func verify(using key: JWTAlgorithm) throws {
func verify(using key: some JWTAlgorithm) throws {
try self.exp.verifyNotExpired()
}
}
Expand Down Expand Up @@ -210,7 +210,7 @@ To add an HMAC key to the key collection, use the `addHS256`, `addHS384`, or `ad

```swift
// Add HMAC with SHA-256 signer.
await keys.addHS256(key: "secret")
await keys.addHMAC(key: "secret", digestAlgorithm: .sha256)
```

> [!IMPORTANT]
Expand Down Expand Up @@ -238,7 +238,7 @@ Once you have an ECDSA key, you can add to the key collection using the followin

```swift
// Add ECDSA with SHA-256 algorithm
await keys.addES256(key: key)
await keys.addECDSA(key: key)
```

## EdDSA
Expand Down Expand Up @@ -303,10 +303,10 @@ Once you have an RSA key, you can add to the key collection using the following

```swift
// Add RSA with SHA-256 algorithm
await keys.addRS256(key: key)
await keys.addRSA(key: key, digestAlgorithm: .sha256)

// Add RSA with SHA-256 and PSS padding algorithm
await keys.addPS256(key: key)
await keys.addPSS(key: key, digestAlgorithm: .sha256)
```

## Claims
Expand Down Expand Up @@ -384,8 +384,12 @@ struct CustomParser: JWTParser {
And then use them like this:

```swift
let keyCollection = await JWTKeyCollection()
.addHS256(key: "secret", parser: CustomParser(), serializer: CustomSerializer())
let keyCollection = await JWTKeyCollection().addHMAC(
key: "secret",
digestAlgorithm: .sha256,
parser: CustomParser(),
serializer: CustomSerializer()
)

let payload = TestPayload(sub: "vapor", name: "Foo", admin: false, exp: .init(value: .init(timeIntervalSince1970: 2_000_000_000)))

Expand All @@ -403,8 +407,12 @@ let decoder = JSONDecoder(); decoder.dateDecodingStrategy = .iso8601
let parser = DefaultJWTParser(jsonDecoder: decoder)
let serializer = DefaultJWTSerializer(jsonEncoder: encoder)

let keyCollection = await JWTKeyCollection()
.addHS256(key: "secret", parser: parser, serializer: serializer)
let keyCollection = await JWTKeyCollection().addHMAC(
key: "secret",
digestAlgorithm: .sha256,
parser: parser,
serializer: serializer
)
```

---
Expand Down

0 comments on commit 6f512cb

Please sign in to comment.