Created
September 25, 2020 19:55
-
-
Save regularberry/e20b0534032fa7094ae47d73d46608ab to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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