Skip to content

rarestype/swift-jwt

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🎫   swift-jwt   🎫

pure swift jwt types with bring-your-own-crypto (byoc)

documentation and api reference

Requirements

The swift-jwt library requires Swift 6.2 or later.

Platform Status
💬 Documentation Status
🐧 Linux Status
🍏 Darwin Status
🍏 Darwin (iOS) Status
🍏 Darwin (tvOS) Status
🍏 Darwin (visionOS) Status
🍏 Darwin (watchOS) Status

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.

About

pure swift jwt types with bring-your-own-crypto (byoc)

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors