Java + TokenRequest = HTTP 405

First time poster…

I’ve followed the keycloak docs to get it up and running in docker. It’s given me image keycloak:26.0.0. I’m running windows 11.

I have followed the same steps as my colleagues to get a wildfly container up and running, with our app. I have tried setting up realm/client manually. I have tried importing colleagues settings.

Only problem is, where they get a HTTP 200 I get a HTTP 405. I appear to have everything the same as them. Run keycloak the same way. Running same codebase and config.
What on earth could be causing this?

The code in question…

    HTTPResponse response = new TokenRequest(
        URI.create(url + "/realms/" + realm + "/protocol/openid-connect/token"),
        new ClientID(clientId),
        new AuthorizationCodeGrant(
            new AuthorizationCode(authorizationCode),
            URI.create(redirectURI)),
        new Scope("openid", "profile")
    ).toHTTPRequest().send();

I can confirm, when debugging, the variables are the same as my colleagues.

I can only assume there is a system property, for example, which is having an affect.

The problem is Windows. How can you use Windows for developing? Just joking :slight_smile:

Without logging info, there’s no way to help

1 Like

So the URL being POST’ed it to is…

http://localhost:8081/realms/my-realm/protocol/openid-connect/token

(I am running my keycloak on port 8081).

Does this URL look ok? Is POST method correct?

On keycloak admin, when I click on the “Realm settings → Endpoints → OpenID endpoint configuration” it gives this…


“token_endpoint”: “http://localhost:8081/realms/my-realm/protocol/openid-connect/token”,

You can also get a 405 if the Content-type isn’t right. Is the body of your post application/x-www-form-urlencoded (and not JSON)?

It is x-www-form-urlencoded but that’s not set by me. The project uses com.nimbusds:oauth2-oidc-sdk.

Strangely enough, I cloned the repo, built and ran and no longer get the 405.