1

Similar to this question I am sending the following POST to the server:

content-type: application/x-www-form-urlencoded
authorization: Basic dGVzdGp3dGNsaWVudGlkOlhZN2ttem9OemwxMDA=
accept: */*

With the payload:

{"username"="test", "password": "pw", "email": "test@example.com"}

However, I'm still getting

{
  "error": "invalid_request",
  "error_description": "Missing grant type"
}

as response from the server. Any idea why this is not working?


Note that the request is working if I use curl:

$ curl testjwtclientid:XY7kmzoNzl100@localhost:8080/oauth/token -d grant_type=password -d username=john.doe -d password=pw -v
*   Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 8080 (#0)
* Server auth using Basic with user 'testjwtclientid'
> POST /oauth/token HTTP/1.1
> Host: localhost:8080
> Authorization: Basic dGVzdGp3dGNsaWVudGlkOlhZN2ttem9OemwxMDA=
> User-Agent: curl/7.47.0
> Accept: */*
> Content-Length: 49
> Content-Type: application/x-www-form-urlencoded
> 
* upload completely sent off: 49 out of 49 bytes
< HTTP/1.1 200 
< X-Content-Type-Options: nosniff
< X-XSS-Protection: 1; mode=block
< Cache-Control: no-cache, no-store, max-age=0, must-revalidate
< Pragma: no-cache
< Expires: 0
< X-Frame-Options: DENY
< Cache-Control: no-store
< Pragma: no-cache
< Content-Type: application/json;charset=UTF-8
< Transfer-Encoding: chunked
< Date: Thu, 02 Nov 2017 19:21:29 GMT
< 
* Connection #0 to host localhost left intact
{"access_token":"<an-ugly-long-token>","token_type":"bearer","expires_in":43199,"scope":"read write","jti":"80e2b6af-d999-4fb6-a4cd-5e6ab9c3fcaa"}
Stefan Falk
  • 23,898
  • 50
  • 191
  • 378
  • 1
    Your payload should be something like grant_type=password&username=john.doe&password=pw, whereas you are passing it as JSON. You can check https://stackoverflow.com/questions/38165131/spring-security-oauth2-accept-json for JSON payload – Amit K Bist Nov 02 '17 at 21:35
  • I am putting my comment as answer, please accept if it resolved your issue. – Amit K Bist Nov 02 '17 at 23:36

1 Answers1

0

Your payload should be something like grant_type=password&username=john.doe&password=pw, whereas you are passing it as JSON. You can check Spring security OAuth2 accept JSON for JSON payload

Amit K Bist
  • 6,760
  • 1
  • 11
  • 26