Last active
November 28, 2019 19:47
-
-
Save ianaya89/08f1686d2b7bdf619c3f1e9dd3c1ae1b to your computer and use it in GitHub Desktop.
This file contains hidden or 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