灵活、无侵入、可插拔,这么牛,必须Star一个 ⭐ !
:tw-1f4cc: 这个仅仅作为 Spring Security 的一个扩展,不会侵入你原有的权限体系。你需要引入Spring Boot Starter Security。
自行使用Maven命令mvn install
到本地仓库,然后引入:
<dependency>
<groupId>cn.felord</groupId>
<artifactId>spring-security-extension</artifactId>
<version>1.0.0</version>
</dependency>
然后参考sample项目进行开发。
- 个人博客 码农小胖哥的博客:https://www.felord.cn/
- 公众号:码农小胖哥
关注公众号:码农小胖哥 回复 2021开工福利 和 2022开工福利 获取原创50万字的PDF。
- Github:https://github.com/NotFound403/felord/spring-security-oauth2-tutorial
- Gitee: https://gitee.com/felord/spring-security-oauth2-tutorial
目前的分支有:
- main 体验Gitee三方授权。
- wechat 微信网页授权实现,对非标准OAuth2的定制改造,强调自定义能力。
- oauth2client 体验Spring Security OAuth2 Client功能。
- resourceserver 体验OAuth2 资源服务器功能。
- jose jose规范讲解体验,十分重要,必须熟练掌握。
- springauthserver Spring Authorization Server初步体验入门。
- customconsent Spring Authorization Server自定义授权确认(consent required)页面。
- privatekeyjwt OAuth2客户端授权方式(Client Authentication Method)
private_key_jwt
实现(独家)。 - clientsecretjwt OAuth2客户端授权方式(Client Authentication Method)
client_secret_jwt
实现(独家)。 - 其它新分支持续更新中
- 1-Spring Security OAuth2专栏介绍
- 2-直观体验OAuth2
- 3-OAuth2登录流程分析
- 4-OAuth2.0协议简单认识
- 5-OAuth2.1的已知变动
- 6-Spring Security OAuth2配置项详解
- 7-OAuth2AuthorizationRequestRedirectFilter
- 8-OAuth2LoginAuthenticationFilter
- 9-Spring Boot中OAuth2的自动配置
- 10-微信OAuth2授权登录
- 11-OAuth2登录的配置逻辑
- 12-OAuth2LoginConfigurer的初始化
- 13-OAuth2LoginConfigurer的配置
- 14-OAuth2ClientConfigurer
- 15-JOSE规范
- 16-Spring Security中的JOSE类库
- 17-什么是资源服务器
- 18-Spring Security中的资源服务器
- 19-Spring Security资源服务器配置详解
- 20-BearerTokenAuthenticationFilter
- 21-Spring Authorization Server介绍
- 22-Spring Authorization Server初体验
- 23-Spring Authorization Server结合客户端
- 24-Spring Authorization Server执行日志分析
- 25-Spring Authorization Server的配置总览
- 26-ProviderContextFilter
- 27-令牌自省OAuth2TokenIntrospectionEndpointFilter
- 28-JWKSet公钥令牌端点过滤器
- 29-授权服务器配置信息端点过滤器
- 30-OAuth2授权端点配置类
- 31-授权服务器如何处理客户端授权请求
- 32-Spring Authorization Server 0.2.3 的变化
- 33-授权码授权请求的具体逻辑
- 34-自定义OAuth2授权确认页面
- 35-OAuth2授权服务器客户端认证配置
- 36-OAuth2客户端认证过滤器详解
- 37-Spring Authorization Server利用JWT对OAuth2客户端进行认证(国内首发)
- 未上架,待补充 催更
登录方式有三种。
POST /login?username=user&password=12345 HTTP/1.1
Host: localhost:8085
需要先实现必须的配置接口
发送验证码后调用验证码登录接口:
POST /login/captcha?phone=11111111111&captcha=123123 HTTP/1.1
Host: localhost:8080
需要先实现必须的配置接口
前端先调用微信授权登录接口获取openid
:
POST /miniapp/preauth?clientId=wxxda23234&jsCode=051A23234ZHa1tZ5yj3AOlFr HTTP/1.1
Host: localhost:8080
响应:
{
"code": 200,
"data": {
"errcode": null,
"errmsg": null,
"sessionKey": null,
"openid": "oWmZj5QBrZxxxxx8OUxRrZJi4",
"unionid": "oS-dxxxxxx4w_x7dA-h9MIuA"
},
"msg": "",
"identifier": true
}
然后调用小程序登录接口:
POST /login/miniapp HTTP/1.1
Host: localhost:8080
Content-Type: application/json
{
"clientId": "wxd14qr6",
"openId": "oWmZj5QBrZIBks0xx8OUxRrZJi4",
"unionId": "oS-dK520tgW8xxxx7dA-h9MIuA",
"iv":"LQUOt8BSTa7xxxpe1Q==",
"encryptedData": "10hn3o4xxxxxrO/Ag5nRD3QkLSzduKnWuzN9B/H4Y0G5mDPR8siA7T8yaaqZsrMycLAoe2qrd1J75yYetYuWifiq3jUrcceRZHVxxl9LnQdW8f5+pMTnQtCYiMJ7Jm9paCw2Bh+5Lowkyqkx1q0fALvCQ9LXPPLAbLOB9CavRfKoenAmyyHQjZ/6lz0njzA=="
}
利用Keytool工具生成,采用RSA算法,以前文章有介绍,自己找找。