I am trying to logout by revoking access_token like this :
@FrameworkEndpoint
public class SecurityLogoutController {
@Autowired
private ConsumerTokenServices consumerTokenServices;
@DeleteMapping( "/oauth/token" )
public ResponseEntity<Void> logout( WebRequest request ) {
String bearer = "bearer";
String authorizationHeader = request.getHeader( HttpHeaders.AUTHORIZATION );
log.info( "authorization header: {}", authorizationHeader );
if ( authorizationHeader != null && StringUtils.containsIgnoreCase( authorizationHeader, bearer ) ) {
String accessTokenID = authorizationHeader.substring( bearer.length() + 1 );
log.info( "access_token: {}", accessTokenID );
consumerTokenServices.revokeToken( accessTokenID );
}
return ...;
}
}
But every time I send this delete request with Postman I got this response:
{
"timestamp": "2018-05-30T01:09:11.710+0000",
"status": 401,
"error": "Unauthorized",
"message": "Unauthorized",
"path": "/oauth/token"
}
The endpoint is protected by Spring Security behind the scene and I don't know how and where this endpoint is protected. What I don't understand is: why the client should authenticate again since to get the access_token it had been authenticated? It seems strange for me.
Now when I authenticate the client, Postman automatically replace the Authorization header value and set it with basic authentication. Something like: Basic Y2hpY293YS11aXNlcnZpY2U6Y2aXNlcnZpY2U=
Need some helps... Thanks