Skip to content

Instantly share code, notes, and snippets.

@jatinvaidya
Last active December 13, 2020 23:55
Show Gist options
  • Save jatinvaidya/1fa53c1aa2a75a3ac90d0866010e8a68 to your computer and use it in GitHub Desktop.
Save jatinvaidya/1fa53c1aa2a75a3ac90d0866010e8a68 to your computer and use it in GitHub Desktop.
caching-in-auth0-login-action-script
function getToken(cb) {
if (global.ACCESS_TOKEN)
return (cb(null, global.ACCESS_TOKEN));
request.post({
url: "https://tenant.auth0.com/oauth/token",
json: {
client_id: "configuration.CLIENT_ID",
client_secret: configuration.SECRET,
audience: "external API",
grant_type: "client_credentials"
}
},
function (err, res, data) {
if (err || res.statusCode !== 200) {
return cb(new UnauthorizedError('Authorization Extension: ' + (err && err.message)));
}
global.ACCESS_TOKEN = data.access_token;
cb(null, global.ACCESS_TOKEN);
}
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment