Hi,
I want to inject permissions into the user’s JWT token where the permissions is obtained from a public authorisation API. I tried to use the following rule but failed:
function (user, context, callback) {
const url = require("url");
const request = require("request");
const authURL = new url.URL("https://some-domain.com/get_permissions");
authURL.searchParams.append("email", user.email);
return request(authURL.toString(), function(error, response, body) {
if (!error && response.statusCode === 200) {
const permissions = JSON.parse(body);
context.accessToken.permissions = permissions;
}
return callback(null, user, context);
});
}
I got the following JWT token:
{
"iss": "https://test.eu.auth0.com/",
"aud": [
"https://test.eu.auth0.com/userinfo"
],
"permissions": []
}
Is there any suggestion on how to accomplish my goal?
Regards,
Herry