本文整理汇总了TypeScript中shared/utils/jwtUtils.JwtUtils类的典型用法代码示例。如果您正苦于以下问题:TypeScript JwtUtils类的具体用法?TypeScript JwtUtils怎么用?TypeScript JwtUtils使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了JwtUtils类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: it
it('should decode payload when JWT is valid', () => {
const token = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJpZGFtIiwiaWF0IjoxNDgzMjI4ODAwLCJleHAiOjQxMDI0NDQ4MDAsImF1ZCI6ImNtYyIsInN1YiI6ImNtYyJ9.Q9-gf315saUt007Gau0tBUxevcRwhEckLHzC82EVGIM'
expect(JwtUtils.decodePayload(token)).to.be.deep.equal({
aud: 'cmc',
exp: 4102444800,
iat: 1483228800,
iss: 'idam',
sub: 'cmc'
})
})
示例2: catch
ErrorHandling.apply(async (req: express.Request, res: express.Response, next: express.NextFunction): Promise<void> => {
const jwt: string = JwtExtractor.extract(req)
if (jwt) {
try {
await IdamClient.invalidateSession(jwt)
} catch (error) {
const { id } = JwtUtils.decodePayload(jwt)
logger.error(`Failed invalidating JWT for userId ${id}`)
}
const cookies = new Cookies(req, res)
cookies.set(sessionCookie, '')
}
res.redirect(Paths.homePage.uri)
})
示例3: expect
expect(() => JwtUtils.decodePayload('malformed-jwt')).to.throw(Error, 'Unable to parse JWT token: malformed-jwt')
示例4: hasExpired
hasExpired (): boolean {
const { exp } = JwtUtils.decodePayload(this.bearerToken)
return moment().unix() >= exp
}