https://github.com/rarestype/swift-jwt
pure swift jwt types with bring-your-own-crypto (byoc)
https://github.com/rarestype/swift-jwt
autosync jwt swift-server
Last synced: about 1 month ago
JSON representation
pure swift jwt types with bring-your-own-crypto (byoc)
- Host: GitHub
- URL: https://github.com/rarestype/swift-jwt
- Owner: rarestype
- License: apache-2.0
- Created: 2026-04-02T02:29:51.000Z (2 months ago)
- Default Branch: master
- Last Pushed: 2026-04-22T08:02:57.000Z (about 1 month ago)
- Last Synced: 2026-04-22T08:27:26.650Z (about 1 month ago)
- Topics: autosync, jwt, swift-server
- Language: Swift
- Homepage: https://swiftinit.org/docs/swift-jwt/jwt
- Size: 18.6 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
- Notice: NOTICE
Awesome Lists containing this project
README
π« Β **swift-jwt** Β π«
pure swift jwt types with bring-your-own-crypto (byoc)
[documentation and api reference](https://swiftinit.org/docs/swift-jwt/jwt)
## Requirements
The swift-jwt library requires Swift 6.2 or later.
| Platform | Status |
| -------- | ------ |
| π¬ Documentation | [](https://github.com/rarestype/swift-jwt/actions/workflows/Documentation.yml) |
| π§ Linux | [](https://github.com/rarestype/swift-jwt/actions/workflows/Tests.yml) |
| π Darwin | [](https://github.com/rarestype/swift-jwt/actions/workflows/Tests.yml) |
| π Darwin (iOS) | [](https://github.com/rarestype/swift-jwt/actions/workflows/Tests.yml) |
| π Darwin (tvOS) | [](https://github.com/rarestype/swift-jwt/actions/workflows/Tests.yml) |
| π Darwin (visionOS) | [](https://github.com/rarestype/swift-jwt/actions/workflows/Tests.yml) |
| π Darwin (watchOS) | [](https://github.com/rarestype/swift-jwt/actions/workflows/Tests.yml) |
[Check deployment minimums](https://swiftinit.org/docs/swift-jwt#ss:platform-requirements)
## Getting started
You can use swift-jwt with any cryptography library you like! One such library is [swift-cryptography](https://github.com/rarestype/swift-cryptography). If you do choose to use swift-cryptography, hereβs how you would sign `some JSONEncodable` payload, using that libraryβs [`RSA.PrivateKey`](https://swiftinit.org/docs/swift-cryptography/cryptography/rsa/privatekey) type:
```swift
import Cryptography
import JSON
import JWT
extension RSA.PrivateKey {
func jwt(signing claims: some JSONEncodable) throws -> String {
let header: JSON.WebTokenHeader = .init(alg: .rs256)
return try header.sign(encoding: claims) {
try self.sign(hashing: $0[...], padding: .pkcs1_legacy, algorithm: .sha256)
}
}
}
```
But really, you could use any cryptography library you like, as long as it can sign a `String`.