Last active
December 13, 2020 23:55
-
-
Save jatinvaidya/1fa53c1aa2a75a3ac90d0866010e8a68 to your computer and use it in GitHub Desktop.
caching-in-auth0-login-action-script
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 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