I am trying to use spring-security-oauth2.0
with Java based configuration. My configuration is done, but when i deploy application on tomcat and hit the /oauth/token
url for access token, Oauth
generate the follwoing error:
<oauth>
<error_description>Full authentication is required to access this resource</error_description>
<error>unauthorized</error>
</oauth>
My configuration is on Git hub, please click on link
The code is large, so refer to git. I am using chrome postman client for send request. follwing is my request.
POST /dummy-project-web/oauth/token HTTP/1.1
Host: localhost:8081
Cache-Control: no-cache
Content-Type: application/x-www-form-urlencoded
grant_type=client_credentials&client_id=abc%40gmail.com&client_secret=12345678
The error is just like, the URL is secure by Oauth
, but in configuration, i give the all permission for access this URL. What actual this problem is?
You should pre authenticate the token apis
"/oauth/token"
extend
ResourceServerConfigurerAdapter
and overrideconfigure function
to do this.eg:
The reason is that by default the
/oauth/token
endpoint is protected through Basic Access Authentication.All you need to do is add the
Authorization
header to your request.You can easily test it with a tool like
curl
by issuing the following command:curl.exe --user abc@gmail.com:12345678 http://localhost:8081/dummy-project-web/oauth/token?grant_type=client_credentials
setting
management.security.enabled=false
inapplication.properties
resolved the issue for me.The
client_id
andclient_secret
, by default, should go in the Authorization header, not the form-urlencoded body.client_id
andclient_secret
, with a colon between them:abc@gmail.com:12345678
.YWJjQGdtYWlsLmNvbToxMjM0NTY3OA==
Authorization: Basic YWJjQGdtYWlsLmNvbToxMjM0NTY3OA==
With Spring OAuth 2.0.7-RELEASE the following command works for me
It works with Chrome POSTMAN too, just make sure you client and secret in "Basic Auth" tab, set method to "POST" and add grant type in "form data" tab.
By default Spring OAuth requires basic HTTP authentication. If you want to switch it off with Java based configuration, you have to allow form authentication for clients like this: