Hooks - adding custom claims to access token
Hello guys,
I want access token or payload to have one additional field userRole: admin. I have tried adding the below code in Hooks. It looks like it is not getting called. the payload i see when i put the access token after signin doesn’t contain any custom claim i want.
Below is the code written for a hook.
module.exports = function(client, scope, audience, context, cb) {
var access_token = {};
access_token.scope = scope;
// Modify scopes or add extra claims
access_token['https://dev-2134sad/api/v2/claim'] = 'bar';
access_token['localhost/claim'] = 'foo';
access_token.scope.push('extra');
cb(null, access_token);
};
Below is the payload i get to see on jwt.io
iss": "dev-2134sad/",
"sub": "google-oauth2|106941439196639936172",
"aud": [
"localhost",
"dev-2134sad/userinfo"
],
"iat": 1558534812,
"exp": 1558542012,
"azp": "tN5gpava3f5ZoYghWKRzJC0yqp6s59UD",
"scope": "openid profile"
}