🎫 swift-jwt 🎫
pure swift jwt types with bring-your-own-crypto (byoc)
The swift-jwt library requires Swift 6.2 or later.
| Platform | Status |
|---|---|
| 💬 Documentation | |
| 🐧 Linux | |
| 🍏 Darwin | |
| 🍏 Darwin (iOS) | |
| 🍏 Darwin (tvOS) | |
| 🍏 Darwin (visionOS) | |
| 🍏 Darwin (watchOS) |
You can use swift-jwt with any cryptography library you like! One such library is 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 type:
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.