Contents

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) |

Check deployment minimums

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