"缺少授权类型"尽管"内容类型:application / x-www-form-urlencoded"

时间:2017-11-02 19:35:45

标签: spring oauth-2.0

this question类似,我将以下POST发送到服务器:

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

使用有效载荷:

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

但是,我还在

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

作为服务器的响应。知道为什么这不起作用吗?

请注意,如果我使用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"}

1 个答案:

答案 0 :(得分:0)

您的有效负载应该类似grant_type=password&username=john.doe&password=pw,而您将其作为JSON传递。您可以检查Spring security OAuth2 accept JSON是否有JSON有效负载