OAuth安全环境中注销用户的访问令牌

  • 定义一个@FrameworkEndpoint,以便它被FrameworkEndpointHandlerMapping取代而不是标准的RequestMappingHandlerMapping被拾取和解析.

    @FrameworkEndpoint
    public class RevokeTokenEndpoint {

    @Autowired
    @Qualifier("consumerTokenServices")
    ConsumerTokenServices consumerTokenServices;@RequestMapping(method = RequestMethod.DELETE, value = "/oauth/token")
    @ResponseBody
    public Msg<String> revokeToken(String access_token) {if (consumerTokenServices.revokeToken(access_token)){return new Msg(MessageType.MSG_TYPE_SUCCESS,null,"注销成功");}else{return new Msg(MessageType.MSG_TYPE_FAILURE,null,"注销失败");}
    }
    

    }

  • 上述方法从参数中获取access_token,网上还有一种方法是从request Header中获取access_token:

    public void revokeToken(HttpServletRequest request) {String authorization = request.getHeader("Authorization");if (authorization != null && authorization.contains("Bearer")){String tokenId = authorization.substring("Bearer".length()+1);tokenServices.revokeToken(tokenId);}
    }
    
  • 从服务器端删除cookie(针对前端页面的cookie操作)

    @Component
    public class CustomPostZuulFilter extends ZuulFilter{@Overridepublic Object run() {final RequestContext ctx = RequestContext.getCurrentContext();String requestURI = ctx.getRequest().getRequestURI();String requestMethod = ctx.getRequest().getMethod();if (requestURI.contains("oauth/token") && requestMethod.equals("DELETE")) {Cookie cookie = new Cookie("refreshToken", "");cookie.setMaxAge(0);cookie.setPath(ctx.getRequest().getContextPath() + "/oauth/token");ctx.getResponse().addCookie(cookie);}return null;}@Overridepublic boolean shouldFilter() {return true;}@Overridepublic int filterOrder() {return 10;}@Overridepublic String filterType() {return "post";}
    }
    
  • 从AngularJS客户端删除访问令牌,除了从令牌存储中撤销访问令牌之外,还需要从客户端删除access_token cookie。

    $scope.logout = function() {logout($scope.loginData);
    }
    function logout(params) {var req = {method: 'DELETE',url: "oauth/token"}$http(req).then(function(data){$cookies.remove("access_token");window.location.href="login";},function(){console.log("error");});
    } //单击“ 注销”链接时将调用此功能:
    <a class="btn btn-info" href="#" ng-click="logout()">Logout</a>
    

OAuth2 logout相关推荐

  1. 前后端分离单点登录SSO实现方案 淘宝、京东跨域获取Cookie、OAuth2、QQ客户端多种模式

    演示Demo站点 http://sso.exrick.cn 开源版Github地址 https://github.com/Exrick/x-boot) 开发文档 https://www.kanclou ...

  2. 163邮箱接口post登录战网(一)

    最近学习post技术,登录没有反爬的网站又没啥难度,所以选这个对于新手比较难的网站,也欢迎各位大佬指点. 言归正传. 登录的URL:http://reg.163.com/open/oauth2/log ...

  3. 申请Azure第三方登录

    具体流程看官网说明文档 https://docs.microsoft.com/zh-cn/azure/active-directory/develop/active-directory-protoco ...

  4. Spring Cloud 随笔:记录在使用 OAuth2 遇到的巨坑

    点击上方"方志朋",选择"置顶或者星标" 你的关注意义重大! 本文转载文章,原文链接 https://www.shangyang.me/2017/06/01/s ...

  5. java oauth sso 源码_基于Spring Security Oauth2的SSO单点登录+JWT权限控制实践

    概 述 在前文<基于Spring Security和 JWT的权限系统设计>之中已经讨论过基于 Spring Security和 JWT的权限系统用法和实践,本文则进一步实践一下基于 Sp ...

  6. oauth2 单点登录_Spring Security Oauth2和Spring Boot实现单点登录

    最近在学习单点登录相关,调查了一下目前流行的单点登录解决方案:cas 和 oauth2,文章主要介绍oauth2 单点登录.希望这篇文章能帮助大家学习相关内容. 我们将使用两个单独的应用程序: 授权服 ...

  7. 搭建认证服务器 - Spring Security Oauth2.0 集成 Jwt 之 【授权码认证流程】 总结

    在搭建介绍流程之前,确保您已经搭建了一个 Eureka 注册中心,因为没有注册中心的话会报错(也有可能我搭建的认证服务器是我项目的一个子模块的原因):Request execution error. ...

  8. 项目使用encode_Spring Cloud Security:Oauth2使用入门

    Spring Cloud Security 为构建安全的SpringBoot应用提供了一系列解决方案,结合Oauth2可以实现单点登录.令牌中继.令牌交换等功能,本文将对其结合Oauth2入门使用进行 ...

  9. Spring Cloud Security:Oauth2使用入门

    摘要 Spring Cloud Security 为构建安全的SpringBoot应用提供了一系列解决方案,结合Oauth2可以实现单点登录.令牌中继.令牌交换等功能,本文将对其结合Oauth2入门使 ...

最新文章

  1. MySQL环境配置和入门讲解!
  2. 六、pink老师学习笔记——CSS三角形之美 margin负值之美文字围绕浮动元素行内块元素布局的巧妙运用
  3. 我给女朋友讲编程html系列(1) -- Html快速入门
  4. Json序列化空时间字段出异常
  5. freeCodeCamp:Seek and Destroy
  6. S3C2440 LCD驱动(FrameBuffer)实例开发一(转)
  7. Kubernetes(K8s) 1.14.3 单机版配置 node 节点 是 taint 时解决方法
  8. 移植 libuv 到 Visual C++ 6.0 并支持在 Windows XP 系统下编译
  9. java计算机毕业设计济南旅游网站源码+mysql数据库+系统+lw文档+部署
  10. mysql sphinx windows安装_window下安装sphinx实例
  11. afdsafdsafdsaf
  12. 我的NVIDIA开发者之旅——NVIDIA云原生技术
  13. java上位机开发(编译和部署)
  14. Win10微软补丁KB5018410致金蝶客户端无法连接中间件
  15. 数据库性能测试-mysql篇
  16. GetKeyState 和 GetAsyncKeyState 区别
  17. 9个网站,给不知道去哪找数据的你
  18. C++排序——宇宙总统
  19. 球体动画Android,使用CSS创建一个炫酷的球体动画效果
  20. Mac 触控板或鼠标的光标跟踪灵敏度终端设置

热门文章

  1. [PYTHON]Scons工具简介
  2. 不容错过的Java高级面试题
  3. A Strong Baseline and Batch Normalization Neck for Deep Person Re-identification(论文笔记)(2019CVPR)
  4. 使用c语言实现复数运算的程序,用C语言实现的复数运算程序设计
  5. 百钱百鸡php穷举法,PHP经典题:百钱百鸡问题(穷举算法)
  6. C#程序实现窗体的最大化/最小化
  7. 员工每月工资数据集可视化分析
  8. 机器学习项目泰坦尼克号问题陈述
  9. WEB 请求处理二:Nginx 请求 反向代理
  10. nginx_tcp转发