Skip to content

Instantly share code, notes, and snippets.

@eugeniop
Last active August 29, 2015 14:09
Show Gist options
  • Save eugeniop/b778915e9f4d1cecd0b8 to your computer and use it in GitHub Desktop.
Save eugeniop/b778915e9f4d1cecd0b8 to your computer and use it in GitHub Desktop.
JWT in rules
function (user, context, callback) {
var CLIENT_SECRET = 'TARGET_API_CLIENT_SECRET'; // Target API Client secret
var CLIENT_ID = 'TARGET_API_CLIENT_ID';
var jwt_user = {
user_id: user.id,
email: user.email,
name: user.name
};
var options = {
expiresInMinutes: 600, //should match the app's expiration
audience: TARGET_CLIENT_ID,
subject: user.user.id
issuer: 'THIS AUTH SERVER' //e.g. "https://eugeniopace.auth0.com"
};
user.id_token = jwt.sign(jwt_user, new Buffer(TARGET_API_CLIENT_SECRET, 'base64'), options);
callback(null, user, context);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment