软件编程
位置:首页>> 软件编程>> java编程>> Spring Cloud下OAUTH2注销的实现示例

Spring Cloud下OAUTH2注销的实现示例

作者:智顶笔记  发布时间:2023-06-01 22:54:58 

标签:Spring,Cloud,OAUTH2

接上文Spring Cloud下基于OAUTH2认证授权的实现,我们将基于Spring Cloud实现OAUTH2的注销功能。

1 增加自定义注销Endpoint

所谓注销只需将access_token和refresh_token失效即可,我们模仿org.springframework.security.oauth2.provider.endpoint.TokenEndpoint写一个使access_token和refresh_token失效的Endpoint:


@FrameworkEndpoint
public 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 "注销成功";
   }else{
     return "注销失败";
   }
 }
}

2 注销请求方式

Spring Cloud下OAUTH2注销的实现示例

来源:http://www.wisely.top/2017/07/25/spring-cloud-oauth2-logout/

0
投稿

猜你喜欢

手机版 软件编程 asp之家 www.aspxhome.com