Last active
November 28, 2019 19:47
Star
You must be signed in to star a gist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getPrivateKey (path, ) { | |
// buscar private key con `fs` | |
} | |
const subject = user.id | |
const payload = { id: user.id } | |
const audience = user.isAdmin | |
? ['admin'] | |
: ['user'] | |
const permissions = user.isAdmin ? ['*'] : ['read'] | |
getPrivateKey('file/private.pem', function (err, privateKey) { | |
if (err) { | |
return cb(new createError.InternalServerError()) | |
} | |
const accessToken = jwt.sign(payload, privateKey, { | |
issuer: config.jwt.issuer, | |
algorithm: config.jwt.algorithm, | |
expiresIn: config.jwt.account.expiresIn, | |
audience, | |
subject, | |
permissions // custom claim para Authorization | |
}) | |
return cb(null, accessToken) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment