Skip to content

Instantly share code, notes, and snippets.

@cardoso
Created March 10, 2021 18:45
Show Gist options
  • Save cardoso/cc17ebb764602b1a474a7bc635d2db1f to your computer and use it in GitHub Desktop.
Save cardoso/cc17ebb764602b1a474a7bc635d2db1f to your computer and use it in GitHub Desktop.
func generateJWT(for userId: String) throws -> String {
struct StreamClaims: Claims {
let user_id: String
}
let myClaims = StreamClaims(user_id: userId)
var myJWT = JWT(claims: myClaims)
let key = "[my_secret]"
let keyData = key.data(using: .utf8)!
let signer = JWTSigner.hs256(key: keyData)
return try myJWT.sign(using: signer)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment