Keycloak Missing form parameter: grant_type

Borislav Stoilov picture Borislav Stoilov · Dec 15, 2018 · Viewed 22.3k times · Source

I have keycloak standalone running on my local machine.

I created new realm called 'spring-test', then new client called 'login-app'

According to the rest documentation:

POST: http://localhost:8080/auth/realms/spring-test/protocol/openid-connect/token

{
    "client_id": "login-app",
    "username": "user123",
    "password": "pass123",
    "grant_type": "password"
}

should give me the jwt token but I get bad request with response

{
    "error": "invalid_request",
    "error_description": "Missing form parameter: grant_type"
}

I am assuming that something is missing in my configuration.

EDIT: I was using json body but it should be application/x-www-form-urlencoded: the following body works:

token_type_hint:access_token&token:{token}&client_id:{client_id}&client_secret:{client_secret}

Answer

ipave picture ipave · Dec 15, 2018

You should send your data in a POST request with Content-Type header value set to application/x-www-form-urlencoded, not json.