atay
atay

Reputation: 155

Keycloak - NullPointerException in codeToToken on token retreive

I'm trying to run keycloak as the simplest OpenID server with the simplest app to authenticate users.

My steps:

  1. I run keycloak insance docker run -p 8080:8080 -e KEYCLOAK_USER=admin -e KEYCLOAK_PASSWORD=admin jboss/keycloak
  2. I log in into keycloak instance, create new client with id swarm, I set Authorization Enabled to true, I set Valid Redirect URIs to http://myapp/test.php, rest is default.
  3. On http://myapp/test.php I have just link to http://localhost:8080/auth/realms/master/protocol/openid-connect/auth?client_id=swarm&response_type=code&scope=code&redirect_url=http://myapp/test.php which I click
  4. I'm redirected to keycloak page, where I log in as admin/admin and I'm redirected back to http://myapp/test.php?session_state=c15d4d10-31a9-41d8-a8ba-9ea84d8fd4fa&code=ey...FA (I cut code, as it was long)
  5. I'm trying to exchange that code for a token with curl manually, by calling curl -d "client_id=swarm" -d "grant_type=authorization_code" -d "client_secret=51d9de29-35f8-4692-bdfc-72f4c0a5b25f" -d "session_state=62f12f56-968b-4068-bbb5-95e5c9f1bc23" -d "code=eey...FA" http://localhost:8080/auth/realms/master/protocol/openid-connect/token
  6. I'm getting 500 Server error with no message.

In Keycloak logs I'm getting NullPointerException when trying to get a token from openid with this logs:

10:02:16,987 ERROR [org.keycloak.services.error.KeycloakErrorHandler] (default task-14) Uncaught server error: java.lang.NullPointerException at > org.keycloak.protocol.oidc.endpoints.TokenEndpoint.codeToToken(TokenEndpoint.java:310) at > org.keycloak.protocol.oidc.endpoints.TokenEndpoint.processGrantRequest(TokenEndpoint.java:172) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

Not sure what I can do next. I'll be helpful for any help.

Upvotes: 1

Views: 2261

Answers (1)

user2667044
user2667044

Reputation: 46

Provide a request_uri in your request #5. Use the same as in the first request.

Upvotes: 3

Related Questions