@therobot/jwt-handler
v0.0.2
Published
JWT Wrapper
Downloads
3
Readme
@therobot/jwt-handler
Set ENV
- JWT_ALGORITHM - default RS256
- JWT_PASSPHRASE - default empty string
- JWT_PRIVATE_KEY - base64 encoded
-----BEGIN ENCRYPTED PRIVATE KEY-----\n ...
- JWT_PUBLIC_KEY - base64 encoded
-----BEGIN PUBLIC KEY-----\n ...
- JWT_PUBLIC_KEY_FALLBACK - previous value, fallback during key rotation
Usage
Only .sign()
can throw errors, data
and verify
will return { error: String }
.data()
- token data, memorized, calling it multiple times is ok.token
- token parsed from header string (noBearer
)verify(token)
- return data, without memorizationsign(data)
- signs values with private key
const jwtHandler = require('@therobot/jwt-handler')
const context = ({ req }) => {
return {
jwt: jwtHandler(req.headers['authorization']),
}
}
const resolvers = {
Query: {
me: async (obj, args, { jwt }) => {
const authData = jwt.data()
if (authData.error) {
throw new Error('Unauthorized: ' + authData.error)
}
},
},
}