-
Notifications
You must be signed in to change notification settings - Fork 2.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Keycloack Identity and Access Management #1779
Comments
Hey, @lobosan I have created a small utility which connects the hasura and keycloak. https://github.com/httpsOmkar/keycloak-hasura-connector |
@httpsOmkar it's awesome news. Can you tell me your username in discord? |
Hello @mnlbox My discord id is omkar#0915 |
Hi @httpsOmkar you are awesome thanks for your great support :) |
@httpsOmkar thank you for this contribution 🎉 I'm closing this issue now. If any of you would like to add something to it, feel free to re-open it 🙂 |
Just wanted to add my 2 cents to this. Since keycloak is an awesome selfhosted auth server. There are ways to configure keycloak directly, without the necessity of plugging a separate webhook service between. keycloak has this feature of script mappers, you can basically write JS inside the configuration to put additional hasura claims into the JWT token, just like with auth0 rules: I think its self explainable |
Hello, I'm looking to setup hasura with keycloak. I entered the script mapper and then I'm trying to configure the JWT mode and trying to set HASURA_GRAPHQL_JWT_SECRE. The json config is composed of the type and the jkw url of the my keycloak server. I received the following error:
I really don't know how to fix this. My guess was a problem of criptography but I tried every accepted configuration without any success. Thanks |
@Nico-L you have to provide the json as a string
|
@webdeb that was a quick answer! A string is required if put the config directly in the docker-compose file, but I have to supply the json object if I use env variables. Does it make sense to you? Anyway, the problem was in the realm keys definition: I had a array of 3 keys, two of them wasn't supported by Hasura. I just kept the RS256 key and Hasura launched without error. Everything seems OK, even though I expected the jwt-secret to appear in the Request Headers of the console. It's not there, but the jwt token is decoded so I guess it's OK. Now, Hasura requested both x-hasura-default-role and x-hasura-allowed-roles. This last one is a bit tricky as if you just put a javascript group inside the json claim of the script wrapper, it is traducted as a json object:
translates into in the token:
which is not validated by Hasura. You have define a java array before (from stackoverflow) and pass it to the claim. So the working script mapper is the following:
Then the token is validated. |
@Nico-L Basically, you have to translate the js array into a Java List 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",
}); So, you can just add roles from your realm, to your users and put them into allowed roles, don't need to code it every time you add a role |
A side-note on "x-hasura-role" don't put it into the JWT, it's better to provide it via the headers, so you can use different roles (of allowed) for different tasks. |
@webdeb I wish I found your example sooner, I spend a bit of a time looking for the script mapper before realizing that I had to add the -Dkeycloak.profile.feature.upload_scripts=enabled Great tips, I'll modify my script accordingly. |
Another Approach..
|
There is nice tutorial for newest Keycloak 23.0.6 for anyone interested: |
Hi guys, can you please create a similar tutorial to this one: Firebase + Hasura, but based on Keycloak + Hasura?
Also if you could deploy it on OpenShift to showcase an open source fullstack example running in a production environment it would be a dream come true, specially if you add to the stack an API Gateway.
All the best and thanks for considering my proposal.
The text was updated successfully, but these errors were encountered: