vanetix/elixir-keycloak

404 when calling Keycloak.Service.get_token()

cstaud opened this issue · 1 comments

When trying to receive a token from keycloak with the get_token() function a 404 and some html is returned:

iex(5)> client = Keycloak.Service.get_token()


14:12:37.174 [warn]  
A serializer was not configured for content-type 'text/html'.

To remove this warning for this content-type, add the following to your `config.exs` file:

    config :oauth2,
      serializers: %{
        "text/html" => MySerializer
      }

To remove this warning entirely, add the following to you `config.exs` file:

    config :oauth2,
      warn_missing_serializer: false

 
14:12:37.187 [debug] OAuth2 Provider Response %OAuth2.Response{body: "<html><head><title>Error</title></head><body>404 - Not Found</body></html>", headers: [{"connection", "keep-alive"}, {"content-length", "74"}, {"content-type", "text/html"}, {"date", "Wed, 30 Jan 2019 14:12:37 GMT"}], status_code: 404}
{:error,
 %OAuth2.Response{
   body: "<html><head><title>Error</title></head><body>404 - Not Found</body></html>",
   headers: [
     {"connection", "keep-alive"},
     {"content-length", "74"},
     {"content-type", "text/html"},
     {"date", "Wed, 30 Jan 2019 14:12:37 GMT"}
   ],
   status_code: 404
 }}

Receiving the token data with curl works well.

curl -d 'client_id=admin-cli' -d 'client_secret=xxx' -d 'grant_type=client_credentials' 'http://keycloak:8080/auth/realms/test/protocol/openid-connect/token' | python -m json.tool

My first guess would be that a wrong api endpoint is used...

Nevermind. It is required to add the protocol to the site config.

config: keycloak
   site: localhost

doesn't work.

config: keycloak
    site: http://localhost

works.