rolesroles claim in the ID token and userinfo response, so I can leverage OAUTH2_ADDITIONAL_CLAIMSOAUTH2_ADDITIONAL_CLAIMS in pgAdmin for access control.grantsgrants structure and set a custom rolesroles claim. However, neither this dynamic claim nor even a simple static claim (for testing) appears in the ID token or userinfo output.function flatRoles(ctx, api) {
api.v1.claims.setClaim("test", "hello");
}function flatRoles(ctx, api) {
api.v1.claims.setClaim("test", "hello");
}userinfouserinfo and the tokentoken in pgAdmin logstesttest or rolesroles) is never visible./**
* Flatten roles into a top-level "roles" claim.
* Format: "roles": ["role1", "role2", ...]
*
* Flow: Complement Token
* Triggers: Pre Userinfo Creation, Pre Access Token Creation
*
* @param ctx
* @param api
*/
function flatRoles(ctx, api) {
const userGrants = ctx.v1.user?.grants?.grants;
if (!userGrants || userGrants.length === 0) {
return;
}
const flatRoles = [];
userGrants.forEach(grant => {
if (grant.roles && grant.roles.length > 0) {
grant.roles.forEach(role => flatRoles.push(role));
}
});
if (flatRoles.length > 0) {
api.v1.claims.setClaim("roles", flatRoles);
}
}/**
* Flatten roles into a top-level "roles" claim.
* Format: "roles": ["role1", "role2", ...]
*
* Flow: Complement Token
* Triggers: Pre Userinfo Creation, Pre Access Token Creation
*
* @param ctx
* @param api
*/
function flatRoles(ctx, api) {
const userGrants = ctx.v1.user?.grants?.grants;
if (!userGrants || userGrants.length === 0) {
return;
}
const flatRoles = [];
userGrants.forEach(grant => {
if (grant.roles && grant.roles.length > 0) {
grant.roles.forEach(role => flatRoles.push(role));
}
});
if (flatRoles.length > 0) {
api.v1.claims.setClaim("roles", flatRoles);
}
}
Join the Discord to ask follow-up questions and connect with the community