Following the implementation of OAUTH2 authentication and authorization under Spring Cloud, we will implement the OAUTH2 logout function based on Spring Cloud.
1 Add custom logout Endpoint
The so-called logout only requires invalidating access_token and refresh_token. We imitate org.springframework.security.oauth2.provider.endpoint.TokenEndpoint to write an Endpoint that invalidates access_token and refresh_token:
@FrameworkEndpointpublic class RevokeTokenEndpoint { @Autowired @Qualifier("consumerTokenServices") ConsumerTokenServices consumerTokenServices; @RequestMapping(method = RequestMethod.DELETE, value = "/oauth/token") @ResponseBody public String revokeToken(String access_token) { if (consumerTokenServices.revokeToken(access_token)){ return "Logout successfully"; }else{ return "Logout failed"; } }}2 Logout request method
The above is all the content of this article. I hope it will be helpful to everyone's learning and I hope everyone will support Wulin.com more.