Skip to content

Instantly share code, notes, and snippets.

@regularberry
Created September 25, 2020 19:55
Show Gist options
  • Save regularberry/e20b0534032fa7094ae47d73d46608ab to your computer and use it in GitHub Desktop.
Save regularberry/e20b0534032fa7094ae47d73d46608ab to your computer and use it in GitHub Desktop.
import Foundation
import SwiftJWT
// Your ClassKit Catalog Key ID
let header = Header(kid: "<insert key id>")
// iss = your Developer Team ID
// iat - start time when the JWT is valid
// exp - when the JWT expires
let claims = ClaimsStandardJWT(iss: "<insert team id>", exp: Date(timeIntervalSinceNow: 3600), iat: Date())
var jwt = JWT(header: header, claims: claims)
let privateKeyPath = URL(fileURLWithPath: "/Users/path/to/your-key.p8")
do {
let privateKey: Data = try Data(contentsOf: privateKeyPath, options: .alwaysMapped)
let signer = JWTSigner.es256(privateKey: privateKey)
let signedJWT = try jwt.sign(using: signer)
print(signedJWT)
} catch {
print(error)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment