Unable to get role information back in JWT using Java 2.x APIs

You have to create and deploy an action to get roles added to your ID and access token. Here’s an example from our Spring Role Based Access Control (RBAC) lab:

exports.onExecutePostLogin = async (event, api) => {
  const namespace = "https://spring-boot.example.com";
  if (event.authorization) {
    api.idToken.setCustomClaim("preferred_username", event.user.email);
    api.idToken.setCustomClaim(`${namespace}/roles`, event.authorization.roles);
    api.accessToken.setCustomClaim(`${namespace}/roles`, event.authorization.roles);
  }
};