I'm having some issue making this project https://github.com/royclarkson/spring-rest-service-oauth run. I cloned it and run mvn spring-boot:run
and as soon as the Tomcat is launched on port 8080, I accessed it from the browser:
http://localhost:8080/greeting
But it says, An Authentication object was not found in the SecurityContextunauthorized
The solution was to access the resource:
curl -X POST -vu clientapp:123456 http://localhost:8080/oauth/token -H "Accept: application/json" -d "password=spring&username=roy&grant_type=password&scope=read%20write&client_secret=123456&client_id=clientapp"
Response will be like:
{"access_token":"ff16372e-38a7-4e29-88c2-1fb92897f558","token_type":"bearer","expires_in":43199,"scope":"read write"}
And put the token:
curl http://localhost:8080/greeting -H "Authorization: Bearer ff16372e-38a7-4e29-88c2-1fb92897f558"
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.