connectedcars / node-jwtutils Goto Github PK
View Code? Open in Web Editor NEWZero dependency JWT encoding and decoding for Node
License: MIT License
Zero dependency JWT encoding and decoding for Node
License: MIT License
node-jwtutils/bin/jwtdecode.test.js
Line 48 in 3d12cac
Add examples with:
class TokenCache {
constructor(pubKeys) {
this.pubkeys = {}
this.tokens = {}
}
set(jwt, jwtHeader, jwtBody) {
this.tokens[jwt] = {
body: jwtBody,
expiresAt: Math.max(jwtBody.expiresAt, Date.now() + 3600 * 1000) // Don't cache for more than an hour
}
}
get(jwt) {
// Check expiresAt
return this.tokens[jwt].body
}
}
let tokenCache = new TokenCache()
let decodedJwtBody = JwtUtils.decode(jwt, pubKeys, allowedAudinces, { cache: tokenCache })
For example by using:
return jwtServiceAuth.getGoogleAccessToken(serviceAccount, 300, [
'https://www.googleapis.com/auth/devstorage.read_write'
])
fx.
const unixNow = Math.floor(Date.now() / 1000)
let customValidators = {
exp: (exp, unixTimeNow, maxExpires) => {
if(!exp) {
throw new JwtVerifyError(`No expires set on token`)
}
if(maxExpires =< 0) {
return true
}
if(exp < unixTimeNow + maxExpires) {
throw new JwtVerifyException('Too long expiry')
} else {
return true
}
}
}
let decodedJwtBody = JwtUtils.decode(jwt, pubKeys, allowedAudinces, { validators => customValidators, maxExpires: 300 })
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.