-
Notifications
You must be signed in to change notification settings - Fork 73
Verification of Tokens from external Auth Provider (Keycloak) #175
Comments
Hi @andreasewering, did you solve your issue? I have the same problem.
However, I only get 401 responses (with correct JWTs)... |
OK, I think I solved it...
|
You should be able to do that by implementing your own FromJWT instance |
@domenkozar If he's going to a JWK, a FromJSON instance is already available. |
Yes, I use this instance for JWK. For tokens, I'll make my own instance to decode my claims. |
@cdupont I was not able to solve my issue. Since it is a test realm keycloak, I might as well paste some stuff here. I send the request and automatically decode to a JWKSet using servant client. Printing the result gives me I then create my settings, for now using unsafeHead `firstOfJwkSet :: JWKSet -> JWK jwkSetToSettings :: JWKSet -> JWTSettings I also tried not overwriting validationKeys or jwtAlg, but I got the same result. My endpoint just looks like this right now:
data AuthUser = AuthUser ` Example token (paste in jwt.io to see the claims): eyJhbGciOiJSUzI1NiIsInR5cCIgOiAiSldUIiwia2lkIiA6ICJoLTZuMk9Ic1VBNlp0aEN4b2tYS3BZOTJid1RvSGlVWnJGQ1Y2OWRjSzZvIn0.eyJqdGkiOiIxMTAzNzc3Mi1iZjQ4LTQxZjQtYTQzYi1kMzJiYTY4NmQ0NGUiLCJleHAiOjE2MDI4MjY3OTUsIm5iZiI6MCwiaWF0IjoxNjAyODI2NDk1LCJpc3MiOiJodHRwczovL2F1dGguYXBwcy5hbmRyZW5hLmRlL2F1dGgvcmVhbG1zL3Rlc3QiLCJhdWQiOiJ0ZXN0Y2xpZW50Iiwic3ViIjoiMGVlNjQ0YTQtY2M5MC00YTFlLTlmYjgtMmNmNjI2NzFiNWMxIiwidHlwIjoiQmVhcmVyIiwiYXpwIjoidGVzdGNsaWVudCIsImF1dGhfdGltZSI6MCwic2Vzc2lvbl9zdGF0ZSI6ImQyYzk4NmZjLTJmMGUtNDYxMi04YjNhLWFlNzU0ZDE4ZjllZSIsImFjciI6IjEiLCJhbGxvd2VkLW9yaWdpbnMiOltdLCJyZWFsbV9hY2Nlc3MiOnsicm9sZXMiOlsib2ZmbGluZV9hY2Nlc3MiLCJ1bWFfYXV0aG9yaXphdGlvbiJdfSwicmVzb3VyY2VfYWNjZXNzIjp7ImFjY291bnQiOnsicm9sZXMiOlsibWFuYWdlLWFjY291bnQiLCJtYW5hZ2UtYWNjb3VudC1saW5rcyIsInZpZXctcHJvZmlsZSJdfX0sInNjb3BlIjoiIiwibmFtZSI6IlRpYmVyaXVzIEVzdG9yIiwicHJlZmVycmVkX3VzZXJuYW1lIjoidGVzdCIsImdpdmVuX25hbWUiOiJUaWJlcml1cyIsImZhbWlseV9uYW1lIjoiRXN0b3IifQ.jKfS59uyeWC3j8ovrV91BwWuRCOC6z3jhZdeSZFgUyA6XB-7eGT-pv6vEzYLYPI47mba2GIdSt1WtB7s4s_QW2vmFETj2lZ9SmDf4NvukQWjpUlr7E3SueYZpwl69-BOFnxjWFdzTqEKC4cGbIdlJzzDBXa3nXe0JTLyFt9b9G2O_Bej503fyhJecUhTw3kVo9FBE1D9ntYbueSsTozq0dgymvjM91tK78lh9xD_7KBj6InlE_FuJDhFFgBuAnql-5J8V9xo2mhSfikMeRpdMx4YeS7hpBHdk415S3_jBUxRQibBzvbjRjYXYL_OiDHF5NIAghVbWEZHdAhUtwEHGQ |
@cdupont How did you solve it in your case? Is the derived FromJWT instance the problem? |
@andreasewering I looks all good to me. Some ideas: why not decoding directly to a JWK instead of going through a JWKSet (like in my example above)? |
I figured it out. It seems to be a problem with the default FromJWT instance, that assumes that claims go in a 'dat' field of the decoded jwt. Using dummy instances as follows instance ToJWT Jose.ClaimsSet where led to a success. Now I can work from there and write the instance I actually need. I'll close this now, but it would be great if errors would give a better error message though. Maybe I'll do a pull request later on. |
Hello,
I am trying to set up a Haskell Web Server where some endpoints are protected by Keycloak.
However, I cannot get it to work, any valid access token gets converted into "Indefinite".
My current process is:
I get the JWKSet from the Keycloak Server (RS256 algorithm) via Servant-Client. This works as expected, the request goes through without issues.
I build the JWTSettings needed for Servant-Auth by starting with default settings and then adding the JWKSet from the previous step as "validationKeys" and the first member of the set as signing key (as far as i understand JWT token validation without signing #121 the signing key ends up unused anyways if I only verify).
I use defaultCookieSettings as I do not intend to use Cookies
I add
Auth '[JWT] AuthUser
to a route to protect it. AuthUser is a record with a single field "preferred_username" since that is the part of the claims I currently need.The Code compiles, but requests to the protected path get blocked by the authorization, although
the header
Authorization: Bearer <token>
is set with a newly generated access token.There is no error log, the only clue is that the AuthResult is Indefinite.
Can you give me a clue? What I am doing wrong? Is there an easy way to debug this?
The text was updated successfully, but these errors were encountered: