簡易的decode程式碼範例
func testJWT() -> Void {
let testToken = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJodHRwczovL3NhbXBsZXMuYXV0aDAuY29tIiwic3ViIjoiYXV0aDB8MTAxMDEwMTAxMCIsImF1ZCI6Imh0dHBzOi8vc2FtcGxlcy5hdXRoMC5jb20iLCJleHAiOjEzNzI2NzQzMzYsImlhdCI6MTM3MjYzODMzNiwianRpIjoicXdlcnR5MTIzNDU2IiwibmJmIjoxMzcyNjM4MzM2fQ.LvF9wSheCB5xarpydmurWgi9NOZkdES5AbNb_UWk9Ew"
do {
let jwt = try decode(jwt: testToken)
print("JWT raw data: \(jwt)")
} catch let error as NSError {
print("JWT error: \(error.localizedDescription)")
}
}
decode後印出來的字串可以至jwt.io網站驗證是否正確
沒有留言:
張貼留言