Skip to content

Instantly share code, notes, and snippets.

@ianaya89
Last active November 28, 2019 19:47
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save ianaya89/08f1686d2b7bdf619c3f1e9dd3c1ae1b to your computer and use it in GitHub Desktop.
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