springboot2整合OAuth2.0认证实例

springboot2整合OAuth2.0实例

代码实例放到:https://github.com/haoxiaoyong1014/springboot-examples

springboot-oauth2 包括: springboot-oauth2-authorization-server(认证服务)和springboot-oauth2-resource-server(资源服务)
springBoot版本:2.0.1.RELEASE

授权码模式:

  • 访问认证服务器

  • http://localhost:8888/oauth/authorize?response_type=code&client_id=merryyou&redirect_uri=https://github.com/haoxiaoyong1014?tab=repositories&scope=all

  • 是否同意并授权

在这里插入图片描述

  • 假设用户给予授权,认证服务器将用户导向客户端事先指定的"重定向URI"(redirection URI),同时附上一个授权码(code)。

在这里插入图片描述

  • 拿到这个授权码(code)去交换 access_token
    • 认证服务器核对了授权码和重定向URI,确认无误后,向客户端发送访问令牌(access token)和更新令牌(refresh token)。

在这里插入图片描述
在这里插入图片描述

  • 还有一点需要说明 在请求头中处理了加入 Content-Type : application/x-www-form-urlencoded 还要加入:Authorization:Basic bWVycnl5b3U6bWVycnl5b3U=
    其中 Authorization的值是 CLIENT_ID 和 CLIENT_SECRET Base64加密得到 详细内容在 springboot-examples/springboot-oauth2-authorization-server/src/test/java/cn/merryyou/security/SpringBoot2Oauth2Test.java 中

在这里插入图片描述
写在最后

加wx,获得更多关于Spring Security OAuth2.0视频

image.png

评论 25
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值