rarestype/swift-jwt
π« **swift-jwt** π«
Requirements
The swift-jwt library requires Swift 6.2 or later.
| Platform | Status | | -------- | ------ | | π¬ Documentation | [[Status]](https://github.com/rarestype/swift-jwt/actions/workflows/Documentation.yml) | | π§ Linux | [[Status]](https://github.com/rarestype/swift-jwt/actions/workflows/Tests.yml) | | π Darwin | [[Status]](https://github.com/rarestype/swift-jwt/actions/workflows/Tests.yml) | | π Darwin (iOS) | [[Status]](https://github.com/rarestype/swift-jwt/actions/workflows/Tests.yml) | | π Darwin (tvOS) | [[Status]](https://github.com/rarestype/swift-jwt/actions/workflows/Tests.yml) | | π Darwin (visionOS) | [[Status]](https://github.com/rarestype/swift-jwt/actions/workflows/Tests.yml) | | π Darwin (watchOS) | [[Status]](https://github.com/rarestype/swift-jwt/actions/workflows/Tests.yml) |
Getting started
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.
Package Metadata
Repository: rarestype/swift-jwt
Default branch: master
README: README.md