Deployed Keycloak Script Mapper does not show up in the GUI

折月煮酒 提交于 2020-07-10 10:32:46

问题


I'm using the docker image of Keycloak 10.0.2. I want Keycloak to supply access_tokens that can be used by Hasura. Hasura requires custom claims like this:

{
  "sub": "1234567890",
  "name": "John Doe",
  "admin": true,
  "iat": 1516239022,
  "https://hasura.io/jwt/claims": {
    "x-hasura-allowed-roles": ["editor","user", "mod"],
    "x-hasura-default-role": "user",
    "x-hasura-user-id": "1234567890",
    "x-hasura-org-id": "123",
    "x-hasura-custom": "custom-value"
  }
}

Following the documentation, and using a script I found online, (See this gist) I created a Script Mapper jar with this script (copied verbatim from the gist), in hasura-mapper.js:

var roles = [];
for each (var role in user.getRoleMappings()) roles.push(role.getName());
token.setOtherClaims("https://hasura.io/jwt/claims", {
    "x-hasura-user-id": user.getId(),
    "x-hasura-allowed-roles": Java.to(roles, "java.lang.String[]"),
    "x-hasura-default-role": "user",
});

and the following keycloak-scripts.json in META-INF/:

{
    "mappers": [
        {
            "name": "Hasura",
            "fileName": "hasura-mapper.js",
            "description": "Create Hasura Namespaces and roles"
        }
    ]
}

Keycloak debug log indicates it found the jar, and successfully deployed it. But what's the next step? I can't find the deployed mapper anywhere in the GUI, so how do I activate it? I tried creating a protocol Mapper, but the option 'Script Mapper' is not available. And Scopes -> Evaluate generates a standard access token.

How do I activate my deployed protocol mapper?


回答1:


Of course after you put up a question on SO you still keep searching, and I finally found the answer in this JIRA issue. The scripts feature has been a preview feature since (I think) version 8.

So when starting Keycloak you need to provide:

 -Dkeycloak.profile.feature.scripts=enabled 

and after that your Script Mapper will show up in the Mapper Type dropdown on the Create Mapper screen, and everything works.



来源:https://stackoverflow.com/questions/62213807/deployed-keycloak-script-mapper-does-not-show-up-in-the-gui

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!