I'm currently working on a simple Spring Boot application where I pass client_id and secret to get the access token which gets me a refresh and access token.
But then when I try to access resources(my REST API) using that token (with this URL: curl -H "Authorization: Bearer ead8ba5d-88ad-4531-a821-db08bf25e888" localhost:8081/my-end-point ), it doesn't work for me and gives me following error-
{"error":"invalid_token","error_description":"Invalid access token: ead8ba5d-4531-db08bf2fe888"}
This is how my endpoint looks like-
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import java.security.Principal;
@RestController
@RequestMapping(path = "/my-end-point")
public class PrincipalResource {
@RequestMapping(method = RequestMethod.POST)
public Principal oauth(Principal principal) {
/*
* Translate the incoming request, which has an access token
* Spring security takes the incoming request and injects the Java Security Principal
* The converter inside Spring Security will handle the to json method which the Spring Security
* Oauth client will know how to read
*
* The @EnableResourceServer on the application entry point is what makes all this magic happen.
* If there is an incoming request token it will check the token validity and handle it accordingly
*
*
*/
return principal;
}
} `