this is my post-login action
exports.onExecutePostLogin = async (event, api) => {
const namespace = 'https://chats.com';
if (event.authorization) {
api.idToken.setCustomClaim(`${namespace}/roles`, event.authorization.roles);
api.accessToken.setCustomClaim(`${namespace}/roles`, event.authorization.roles);
}
};
now if you try to access token it shows it is undefined.
export const config = {
authRequired: false,
auth0Logout: true,
secret: "some client id",
baseURL: "http://localhost:8080/",
clientID: "client-id",
issuerBaseURL: "https://url.auth0.com",
};
app.use(
auth({
...config,
routes: {
login: false, // https://github.com/auth0/express-openid-connect/blob/master/EXAMPLES.md#3-route-customization
},
}),
);
app.get('/login', (req, res) => {
if (req.oidc.isAuthenticated) {
console.log(req.oidc.user);
res.redirect('/chat');
} else {
res.oidc.login({ returnTo: '/chat' });
}
});
router.get('/api/users/currentuser', requiresAuth(), async (req, res) => {
console.log(req.oidc.idToken); // getting id-token. decoded version is shown below.
console.log(req.oidc.accessToken); // undefined
res.status(200).send({ user: req.oidc.user });
});
this is my decoded idToken.
{
"https://chats.com/roles": [
"guest ",
"user "
],
"given_name": "pranshu",
"family_name": "shah",
"nickname": "pranshu.shah23",
"name": "pranshu shah",
"picture": "https://lh3.googleusercontent.com/a/AATXAJx6USgeS7fQB3WerDM0cSbZH8wmhaTxzPXjbdl3=s96-c",
"locale": "en",
.... other infos
}
- one way to add authorization permissions is through the authorizationParams object but one issue is that we don’t role of the user before login. so how can we generate access tokens based on role
- in short, what I want to do is I want to have an access token based on the role of the user. so i can call role enabled custom API.