JWTWrapper
这是一个方便的库,用于将 JWT 封装在结构中,并使得解析更加容易。这不是JWT 发布者或验证器,它只是对解析您的应用程序中的令牌有效负载和信息的简单抽象。
安装
Carthage
github "LucianoPAlmeida/JWTWrapper" ~> 1.0
CocoaPods
pod 'JWTWrapper', '~> 1.0'
用法
let jwt = JWT(string: "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJNZSIsImlhdCI6MTUwNjI4Nzg3MCwiZXhwIjoxNTA2Mzc0MjcwLCJhdWQiOiJ3d3cuZXhhbXBsZS5jb20iLCJzdWIiOiJleGVtcGxlIiwianRpIjoiand0aWQxMCIsIm5iZiI6MTUwNjM3NDI3MCwiZmlyc3RfbmFtZSI6IkpvaG4iLCJsYXN0X25hbWUiOiJEb2UiLCJlbWFpbCI6ImRvZUBleGFtcGxlLmNvbSIsImlkIjoxMiwiaGVpZ2h0IjoxLjc1LCJudW1iZXIiOjc4OX0.sJVuJ39lIouTnTEYlE_0ZlXVp8GXCy9Z7djQwZUDwLI")
// Headers
jwt.algorithm // "HS256"
jwt.type //"JWT"
// Claims
jwt.issuer //"Me"
jwt.audience //"www.example.com")
jwt.subject //"exemple"
jwt.issuedAt //"2017-09-24"
jwt.expirationDate //"2017-09-25"
jwt.id //"jwtid10"
jwt.notBefore //"2017-09-25"
jwt.isExpired //false or true in case its expired
//Payload
jwt.payload["first_name"] // "John"
jwt.payload.string(for: "last_name") //"Doe"
jwt.payload.string(for: "email") // "[email protected]"
jwt.payload.int(for: "id") // 12
jwt.payload.double(for: "height") // 1.75
jwt.payload.float(for: "height") // 1.75
jwt.payload.number(for: "number") // 789
许可证
JWTWrapper遵照< Nielsen'stivoLO开放源代码协议< Nielsen'sfor< Nielsen'slr< Nielsen's_community< Nielsen'shref="https://opensource.org/licenses/MIT" rel="nofollow">MIT许可证>