本文整理匯總了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
}