Compare commits
31 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| e64e9def63 | |||
| 25f99f7560 | |||
| 0433f54564 | |||
| 423d9f45b6 | |||
| 7a9e6214de | |||
| 3753e3b9bc | |||
| bc3af96328 | |||
| b700902c04 | |||
| 2d0ae7cc27 | |||
| 3e4faa75fe | |||
| 6a36ad6af2 | |||
| 13514d6a92 | |||
| 6a479d9c1d | |||
| 2e64fb9693 | |||
| 0e8308e6c9 | |||
| 3933b3b7ee | |||
| a99b818810 | |||
| cd324cc7c1 | |||
| 3e890f2c2a | |||
| ba56f5ab5a | |||
| 132a7f4338 | |||
| c79b97a0d0 | |||
| 66df3ac027 | |||
| 11df93ad44 | |||
| e3f5f49ec8 | |||
| 23eb2cfcc8 | |||
| 30461e62f9 | |||
| dfbbd9ae0d | |||
| 05b7746f26 | |||
| 21422b02aa | |||
| 10e445e87c |
@@ -10,7 +10,7 @@ assignees: ''
|
||||
|
||||
- [ ] I have searched the relevant information in the existing list of Issues.
|
||||
- [ ] I have searched the developer documentation for that information: https://justauth.wiki
|
||||
- [ ] I have read the relevant Q&A: https://justauth.wiki/#/Q&A
|
||||
- [ ] I have read the relevant Q&A: https://justauth.wiki
|
||||
|
||||
## Issue description
|
||||
|
||||
|
||||
+25
-3
@@ -1,3 +1,25 @@
|
||||
## 1.16.0
|
||||
|
||||
### 2021/4/7
|
||||
|
||||
- 发布 v1.16.0
|
||||
- 新增
|
||||
- 集成 Amazon 平台登录
|
||||
- 集成 Slack 平台登录
|
||||
- 集成 LINE 平台登录
|
||||
- 集成 Okta 平台登录
|
||||
- 集成钉钉账号登录
|
||||
- 修改
|
||||
- 【**重要**】 `AuthConfig`中的`codingGroupName`参数更名为`domainPrefix`,针对此类平台提供通用的配置。
|
||||
- 修改 `AuthFacebookScope` 中的默认 scope,解决 justauth-demo 项目中使用 facebook 报错的问题
|
||||
- 升级 facebook 的 api 到 v10.0 版本
|
||||
- 优化部分代码
|
||||
- 优化 Map 声明时的初始容量,避免频繁扩容
|
||||
- 更新 README 文档
|
||||
- PR
|
||||
- 合并 [Github #110](https://github.com/justauth/JustAuth/pull/110)
|
||||
- 合并 [Gitee #22](https://gitee.com/yadong.zhang/JustAuth/pulls/22)
|
||||
|
||||
## 1.15.9
|
||||
|
||||
### 2021/1/1
|
||||
@@ -7,9 +29,9 @@
|
||||
- 修复并正式启用 飞书 平台的第三方登录
|
||||
- AuthToken 类中新增 `refreshTokenExpireIn` 记录 refresh token 的有效期
|
||||
- PR
|
||||
- 合并 [Github #101](https://gitee.com/yadong.zhang/JustAuth/pulls/101):支持喜马拉雅登录
|
||||
- 合并 [Github #105](https://gitee.com/yadong.zhang/JustAuth/pulls/105):支持企业微信网页授权登录
|
||||
- 合并 [Github #107](https://gitee.com/yadong.zhang/JustAuth/pulls/107):添加AuthAlipayRequest网络代理构造器,解决 Github Issue [#102](https://github.com/justauth/JustAuth/issues/102)
|
||||
- 合并 [Github #101](https://github.com/justauth/JustAuth/pull/101) :支持喜马拉雅登录
|
||||
- 合并 [Github #105](https://github.com/justauth/JustAuth/pull/105) :支持企业微信网页授权登录
|
||||
- 合并 [Github #107](https://github.com/justauth/JustAuth/pull/107) :添加AuthAlipayRequest网络代理构造器,解决 Github Issue [#102](https://github.com/justauth/JustAuth/issues/102)
|
||||
- 修改
|
||||
- 修改喜马拉雅配置参数,将`ClientOsType`参数提到 AuthConfig 中
|
||||
- AuthChecker 中增加对喜马拉雅平台的校验
|
||||
|
||||
+12
-50
@@ -6,7 +6,7 @@
|
||||
</p>
|
||||
<p align="center">
|
||||
<a target="_blank" href="https://search.maven.org/search?q=JustAuth">
|
||||
<img src="https://img.shields.io/badge/Maven%20Central-1.15.9-blue" ></img>
|
||||
<img src="https://img.shields.io/badge/Maven%20Central-1.16.0-blue" ></img>
|
||||
</a>
|
||||
<a target="_blank" href="https://gitee.com/yadong.zhang/JustAuth/blob/master/LICENSE">
|
||||
<img src="https://img.shields.io/apm/l/vim-mode.svg?color=yellow" ></img>
|
||||
@@ -15,64 +15,26 @@
|
||||
<img src="https://img.shields.io/badge/JDK-1.8+-green.svg" ></img>
|
||||
</a>
|
||||
<a target="_blank" href="https://apidoc.gitee.com/yadong.zhang/JustAuth/" title="API文档">
|
||||
<img src="https://img.shields.io/badge/Api%20Docs-1.15.9-orange" ></img>
|
||||
<img src="https://img.shields.io/badge/Api%20Docs-1.16.0-orange" ></img>
|
||||
</a>
|
||||
<a target="_blank" href="https://justauth.wiki" title="参考文档">
|
||||
<img src="https://img.shields.io/badge/Docs-latest-blueviolet.svg" ></img>
|
||||
</a>
|
||||
<a href="https://codecov.io/gh/zhangyd-c/JustAuth">
|
||||
<img src="https://codecov.io/gh/zhangyd-c/JustAuth/branch/master/graph/badge.svg" />
|
||||
<a href="https://codecov.io/gh/justauth/JustAuth">
|
||||
<img src="https://codecov.io/gh/justauth/JustAuth/branch/master/graph/badge.svg?token=zYiAqd9aFz" />
|
||||
</a>
|
||||
<a href='https://gitee.com/yadong.zhang/JustAuth/stargazers'>
|
||||
<img src='https://gitee.com/yadong.zhang/JustAuth/badge/star.svg?theme=white' alt='star'></img>
|
||||
<img src='https://gitee.com/yadong.zhang/JustAuth/badge/star.svg?theme=gvp' alt='star'></img>
|
||||
</a>
|
||||
<a target="_blank" href='https://github.com/zhangyd-c/JustAuth'>
|
||||
<img src="https://img.shields.io/github/stars/zhangyd-c/JustAuth.svg?style=social" alt="github star"></img>
|
||||
</a>
|
||||
</p>
|
||||
|
||||
<center>
|
||||
<table>
|
||||
<tr>
|
||||
<td align="center" width="200"><img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/gitee.png" width="20"></td>
|
||||
<td align="center" width="200"><img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/github.png" width="20"></td>
|
||||
<td align="center" width="200"><img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/weibo.png" width="20"></td>
|
||||
<td align="center" width="200"><img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/dingtalk.png" width="20"></td>
|
||||
<td align="center" width="200"><img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/baidu.png" width="20"></td>
|
||||
<td align="center" width="200"><img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/coding.png" width="20"></td>
|
||||
<td align="center" width="200"><img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/tencentCloud.png" width="20"></td>
|
||||
<td align="center" width="200"><img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/oschina.png" width="20"></td>
|
||||
<td align="center" width="200"><img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/alipay.png" width="20"></td>
|
||||
<td align="center" width="200"><img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/qq.png" width="20"></td>
|
||||
<td align="center" width="200"><img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/wechat.png" width="20" title="微信开放平台"></td>
|
||||
<td align="center" width="200"><img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/taobao.png" width="20"></td>
|
||||
<td align="center" width="200"><img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/google.png" width="20"></td>
|
||||
<td align="center" width="200"><img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/facebook.png" width="20"></td>
|
||||
<td align="center" width="200"><img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/douyin.png" width="20"></td>
|
||||
</tr>
|
||||
</table>
|
||||
<table>
|
||||
<tr>
|
||||
<td align="center" width="200"><img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/linkedin.png" width="20"></td>
|
||||
<td align="center" width="200"><img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/microsoft.png" width="20"></td>
|
||||
<td align="center" width="200"><img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/mi.png" width="20"></td>
|
||||
<td align="center" width="200"><img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/toutiao.png" width="20"></td>
|
||||
<td align="center" width="200"><img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/teambition.png" width="20"></td>
|
||||
<td align="center" width="200"><img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/renren.png" width="20"></td>
|
||||
<td align="center" width="200"><img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/pinterest.png" width="20"></td>
|
||||
<td align="center" width="200"><img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/stackoverflow.png" width="20"></td>
|
||||
<td align="center" width="200"><img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/huawei.png" width="20"></td>
|
||||
<td align="center" width="200"><img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/wechat.png" width="20" title="微信企业版"></td>
|
||||
<td align="center" width="200"><img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/csdn.png" width="20"></td>
|
||||
<td align="center" width="200"><img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/kujiale.png" width="20"></td>
|
||||
<td align="center" width="200"><img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/gitlab.png" width="20"></td>
|
||||
<td align="center" width="200"><img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/meituan.png" width="20"></td>
|
||||
<td align="center" width="200"><img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/eleme.png" width="20"></td>
|
||||
<td align="center" width="200"><img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/twitter.png" width="20"></td>
|
||||
</tr>
|
||||
</table>
|
||||
<center><a href="https://justauth.wiki/#/?id=%E5%B7%B2%E9%9B%86%E6%88%90%E7%9A%84%E5%B9%B3%E5%8F%B0" target="_blank">查看更多</a></center>
|
||||
</center>
|
||||
-------------------------------------------------------------------------------
|
||||
<p align="center">
|
||||
<img src='./docs/media/75a3c076.png' alt='star'></img>
|
||||
</p>
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
@@ -97,7 +59,7 @@ These artifacts are available from Maven Central:
|
||||
<dependency>
|
||||
<groupId>me.zhyd.oauth</groupId>
|
||||
<artifactId>JustAuth</artifactId>
|
||||
<version>1.15.9</version>
|
||||
<version>1.16.0</version>
|
||||
</dependency>
|
||||
```
|
||||
- Using JustAuth
|
||||
@@ -162,11 +124,11 @@ I look forward to your joining us.
|
||||
|
||||
## Contributors
|
||||
|
||||
[contributors](https://justauth.wiki/#/contributors)
|
||||
[contributors](https://justauth.wiki/contributors.html)
|
||||
|
||||
## Change Logs
|
||||
|
||||
[CHANGELOGS](https://justauth.wiki/#/update)
|
||||
[CHANGELOGS](https://justauth.wiki/update.html)
|
||||
|
||||
## Recommend
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
</p>
|
||||
<p align="center">
|
||||
<a target="_blank" href="https://search.maven.org/search?q=JustAuth">
|
||||
<img src="https://img.shields.io/badge/Maven%20Central-1.15.9-blue" ></img>
|
||||
<img src="https://img.shields.io/badge/Maven%20Central-1.16.0-blue" ></img>
|
||||
</a>
|
||||
<a target="_blank" href="https://gitee.com/yadong.zhang/JustAuth/blob/master/LICENSE">
|
||||
<img src="https://img.shields.io/apm/l/vim-mode.svg?color=yellow" ></img>
|
||||
@@ -15,64 +15,26 @@
|
||||
<img src="https://img.shields.io/badge/JDK-1.8+-green.svg" ></img>
|
||||
</a>
|
||||
<a target="_blank" href="https://apidoc.gitee.com/yadong.zhang/JustAuth/" title="API文档">
|
||||
<img src="https://img.shields.io/badge/Api%20Docs-1.15.9-orange" ></img>
|
||||
<img src="https://img.shields.io/badge/Api%20Docs-1.16.0-orange" ></img>
|
||||
</a>
|
||||
<a target="_blank" href="https://justauth.wiki" title="参考文档">
|
||||
<img src="https://img.shields.io/badge/Docs-latest-blueviolet.svg" ></img>
|
||||
</a>
|
||||
<a href="https://codecov.io/gh/zhangyd-c/JustAuth">
|
||||
<img src="https://codecov.io/gh/zhangyd-c/JustAuth/branch/master/graph/badge.svg" />
|
||||
<a href="https://codecov.io/gh/justauth/JustAuth">
|
||||
<img src="https://codecov.io/gh/justauth/JustAuth/branch/master/graph/badge.svg?token=zYiAqd9aFz" />
|
||||
</a>
|
||||
<a href='https://gitee.com/yadong.zhang/JustAuth/stargazers'>
|
||||
<img src='https://gitee.com/yadong.zhang/JustAuth/badge/star.svg?theme=white' alt='star'></img>
|
||||
<img src='https://gitee.com/yadong.zhang/JustAuth/badge/star.svg?theme=gvp' alt='star'></img>
|
||||
</a>
|
||||
<a target="_blank" href='https://github.com/zhangyd-c/JustAuth'>
|
||||
<img src="https://img.shields.io/github/stars/zhangyd-c/JustAuth.svg?style=social" alt="github star"></img>
|
||||
</a>
|
||||
</p>
|
||||
|
||||
<center>
|
||||
<table>
|
||||
<tr>
|
||||
<td align="center" width="200"><img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/gitee.png" width="20"></td>
|
||||
<td align="center" width="200"><img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/github.png" width="20"></td>
|
||||
<td align="center" width="200"><img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/weibo.png" width="20"></td>
|
||||
<td align="center" width="200"><img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/dingtalk.png" width="20"></td>
|
||||
<td align="center" width="200"><img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/baidu.png" width="20"></td>
|
||||
<td align="center" width="200"><img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/coding.png" width="20"></td>
|
||||
<td align="center" width="200"><img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/tencentCloud.png" width="20"></td>
|
||||
<td align="center" width="200"><img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/oschina.png" width="20"></td>
|
||||
<td align="center" width="200"><img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/alipay.png" width="20"></td>
|
||||
<td align="center" width="200"><img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/qq.png" width="20"></td>
|
||||
<td align="center" width="200"><img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/wechat.png" width="20" title="微信开放平台"></td>
|
||||
<td align="center" width="200"><img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/taobao.png" width="20"></td>
|
||||
<td align="center" width="200"><img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/google.png" width="20"></td>
|
||||
<td align="center" width="200"><img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/facebook.png" width="20"></td>
|
||||
<td align="center" width="200"><img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/douyin.png" width="20"></td>
|
||||
</tr>
|
||||
</table>
|
||||
<table>
|
||||
<tr>
|
||||
<td align="center" width="200"><img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/linkedin.png" width="20"></td>
|
||||
<td align="center" width="200"><img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/microsoft.png" width="20"></td>
|
||||
<td align="center" width="200"><img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/mi.png" width="20"></td>
|
||||
<td align="center" width="200"><img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/toutiao.png" width="20"></td>
|
||||
<td align="center" width="200"><img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/teambition.png" width="20"></td>
|
||||
<td align="center" width="200"><img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/renren.png" width="20"></td>
|
||||
<td align="center" width="200"><img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/pinterest.png" width="20"></td>
|
||||
<td align="center" width="200"><img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/stackoverflow.png" width="20"></td>
|
||||
<td align="center" width="200"><img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/huawei.png" width="20"></td>
|
||||
<td align="center" width="200"><img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/wechat.png" width="20" title="微信企业版"></td>
|
||||
<td align="center" width="200"><img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/csdn.png" width="20"></td>
|
||||
<td align="center" width="200"><img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/kujiale.png" width="20"></td>
|
||||
<td align="center" width="200"><img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/gitlab.png" width="20"></td>
|
||||
<td align="center" width="200"><img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/meituan.png" width="20"></td>
|
||||
<td align="center" width="200"><img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/eleme.png" width="20"></td>
|
||||
<td align="center" width="200"><img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/twitter.png" width="20"></td>
|
||||
</tr>
|
||||
</table>
|
||||
<center><a href="https://justauth.wiki/#/?id=%E5%B7%B2%E9%9B%86%E6%88%90%E7%9A%84%E5%B9%B3%E5%8F%B0" target="_blank">查看更多</a></center>
|
||||
</center>
|
||||
-------------------------------------------------------------------------------
|
||||
<p align="center">
|
||||
<img src='./docs/media/75a3c076.png' alt='star'></img>
|
||||
</p>
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
@@ -84,7 +46,7 @@ QQ 群:230017570
|
||||
|
||||
JustAuth,如你所见,它仅仅是一个**第三方授权登录**的**工具类库**,它可以让我们脱离繁琐的第三方登录 SDK,让登录变得**So easy!**
|
||||
|
||||
JustAuth 集成了诸如:Github、Gitee、支付宝、新浪微博、微信、Google、Facebook、Twitter、StackOverflow等国内外数十家第三方平台。更多请参考<a href="https://justauth.wiki/#/?id=%E5%B7%B2%E9%9B%86%E6%88%90%E7%9A%84%E5%B9%B3%E5%8F%B0" target="_blank">已集成的平台</a>
|
||||
JustAuth 集成了诸如:Github、Gitee、支付宝、新浪微博、微信、Google、Facebook、Twitter、StackOverflow等国内外数十家第三方平台。更多请参考<a href="https://justauth.wiki" target="_blank">已集成的平台</a>
|
||||
|
||||
## 有哪些特点?
|
||||
|
||||
@@ -93,11 +55,11 @@ JustAuth 集成了诸如:Github、Gitee、支付宝、新浪微博、微信、
|
||||
|
||||
## 有哪些功能?
|
||||
|
||||
- 集成国内外数十家第三方平台,实现快速接入。<a href="https://justauth.wiki/#/?id=%E5%B7%B2%E9%9B%86%E6%88%90%E7%9A%84%E5%B9%B3%E5%8F%B0" target="_blank">参考文档</a>
|
||||
- 自定义 State 缓存,支持各种分布式缓存组件。<a href="https://justauth.wiki/#/customize-the-state-cache" target="_blank">参考文档</a>
|
||||
- 自定义 OAuth 平台,更容易适配自有的 OAuth 服务。<a href="https://justauth.wiki/#/customize-the-oauth" target="_blank">参考文档</a>
|
||||
- 自定义 Http 实现,选择权完全交给开发者,不会单独依赖某一具体实现。<a href="https://justauth.wiki/#/customize-the-oauth" target="_blank">参考文档</a>
|
||||
- 自定义 Scope,支持更完善的授权体系。<a href="https://justauth.wiki" target="_blank">参考文档</a>
|
||||
- 集成国内外数十家第三方平台,实现快速接入。<a href="https://justauth.wiki/quickstart/how-to-use.html" target="_blank">参考文档</a>
|
||||
- 自定义 State 缓存,支持各种分布式缓存组件。<a href="https://justauth.wiki/features/customize-the-state-cache.html" target="_blank">参考文档</a>
|
||||
- 自定义 OAuth 平台,更容易适配自有的 OAuth 服务。<a href="https://justauth.wiki/features/customize-the-oauth.html" target="_blank">参考文档</a>
|
||||
- 自定义 Http 实现,选择权完全交给开发者,不会单独依赖某一具体实现。<a href="https://justauth.wiki/quickstart/how-to-use.html#%E4%BD%BF%E7%94%A8%E6%96%B9%E5%BC%8F" target="_blank">参考文档</a>
|
||||
- 自定义 Scope,支持更完善的授权体系。<a href="https://justauth.wiki/features/customize-scopes.html" target="_blank">参考文档</a>
|
||||
- 更多...<a href="https://justauth.wiki" target="_blank">参考文档</a>
|
||||
|
||||
## 快速开始
|
||||
@@ -107,7 +69,7 @@ JustAuth 集成了诸如:Github、Gitee、支付宝、新浪微博、微信、
|
||||
<dependency>
|
||||
<groupId>me.zhyd.oauth</groupId>
|
||||
<artifactId>JustAuth</artifactId>
|
||||
<version>1.15.9</version>
|
||||
<version>1.16.0</version>
|
||||
</dependency>
|
||||
```
|
||||
- 调用api
|
||||
@@ -185,6 +147,21 @@ authRequest.login(callback);
|
||||
<a href="https://www.producthunt.com/posts/justauth?utm_source=badge-featured&utm_medium=badge&utm_souce=badge-justauth" target="_blank"><img src="https://api.producthunt.com/widgets/embed-image/v1/featured.svg?post_id=196886&theme=dark" alt="JustAuth - Login, so easy! | Product Hunt Embed" style="width: 250px; height: 54px;" width="250px" height="54px" /></a>
|
||||
|
||||
## 其他
|
||||
- [CONTRIBUTORS](https://justauth.wiki/#/contributors)
|
||||
- [CHANGELOGS](https://justauth.wiki/#/update)
|
||||
- [PLAN](https://gitee.com/yadong.zhang/JustAuth/issues/IUGRK)
|
||||
- [CONTRIBUTORS](https://justauth.wiki/contributors.html)
|
||||
- [CHANGELOGS](https://justauth.wiki/update.html)
|
||||
- [PLAN](https://gitee.com/yadong.zhang/JustAuth/issues/IUGRK)
|
||||
|
||||
## 贡献者列表
|
||||
|
||||
[](https://whnb.wang)
|
||||
|
||||
## Stars 趋势
|
||||
|
||||
### Gitee
|
||||
|
||||
[](https://whnb.wang/yadong.zhang/JustAuth?e=604800)
|
||||
|
||||
### Github
|
||||
|
||||
[](https://starchart.cc/justauth/JustAuth)
|
||||
|
||||
|
||||
+1
-1
@@ -1 +1 @@
|
||||
1.15.9
|
||||
1.16.0
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 49 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 53 KiB After Width: | Height: | Size: 100 KiB |
@@ -15,6 +15,15 @@ case "$1" in
|
||||
'updv')
|
||||
bin/updVersion.sh $2
|
||||
;;
|
||||
'pd')
|
||||
bin/push-dev.sh
|
||||
;;
|
||||
'p')
|
||||
bin/push.sh
|
||||
;;
|
||||
'd')
|
||||
bin/deploy.sh
|
||||
;;
|
||||
*)
|
||||
help
|
||||
esac
|
||||
|
||||
@@ -6,12 +6,12 @@
|
||||
|
||||
<groupId>me.zhyd.oauth</groupId>
|
||||
<artifactId>JustAuth</artifactId>
|
||||
<version>1.15.9</version>
|
||||
<version>1.16.0</version>
|
||||
|
||||
<name>JustAuth</name>
|
||||
<url>https://gitee.com/yadong.zhang/JustAuth</url>
|
||||
<description>
|
||||
小而全而美的第三方登录开源组件。目前已支持Github、Gitee、微博、钉钉、百度、Coding、腾讯云开发者平台、OSChina、支付宝、QQ、微信、淘宝、Google、Facebook、抖音、领英、小米、微软、今日头条、Teambition、StackOverflow、Pinterest、人人、华为、企业微信、酷家乐、Gitlab、美团、饿了么和推特等第三方平台的授权登录。 Login, so easy!
|
||||
小而全而美的第三方登录开源组件。目前已支持Github、Gitee、微博、钉钉、百度、Coding、腾讯云开发者平台、OSChina、支付宝、QQ、微信、淘宝、Google、Facebook、抖音、领英、小米、微软、今日头条、Teambition、StackOverflow、Pinterest、人人、华为、企业微信、酷家乐、Gitlab、美团、饿了么、推特、飞书、京东、阿里云、喜马拉雅、Amazon、Slack和Line等第三方平台的授权登录。 Login, so easy!
|
||||
</description>
|
||||
|
||||
<licenses>
|
||||
@@ -135,6 +135,9 @@
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<additionalparam>${javadoc.opts}</additionalparam>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
@@ -260,5 +263,15 @@
|
||||
</snapshotRepository>
|
||||
</distributionManagement>
|
||||
</profile>
|
||||
<!-- 禁用 Javadoc 注释检查 -->
|
||||
<profile>
|
||||
<id>disable-javadoc-doclint</id>
|
||||
<activation>
|
||||
<jdk>[1.8,)</jdk>
|
||||
</activation>
|
||||
<properties>
|
||||
<javadoc.opts>-Xdoclint:none</javadoc.opts>
|
||||
</properties>
|
||||
</profile>
|
||||
</profiles>
|
||||
</project>
|
||||
|
||||
@@ -2,8 +2,8 @@ package me.zhyd.oauth.config;
|
||||
|
||||
import com.xkcoding.http.config.HttpConfig;
|
||||
import lombok.*;
|
||||
import me.zhyd.oauth.enums.scope.AuthScope;
|
||||
import me.zhyd.oauth.model.AuthCallback;
|
||||
import me.zhyd.oauth.utils.StringUtils;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -66,13 +66,17 @@ public class AuthConfig {
|
||||
private String agentId;
|
||||
|
||||
/**
|
||||
* 使用 Coding 登录时,需要传该值。
|
||||
* 域名前缀。
|
||||
* <p>
|
||||
* 团队域名前缀,比如以“ https://justauth.coding.net/ ”为例,{@code codingGroupName} = justauth
|
||||
* 使用 Coding 登录和 Okta 登录时,需要传该值。
|
||||
* <p>
|
||||
* Coding 登录:团队域名前缀,比如以“ https://justauth.coding.net ”为例,{@code domainPrefix} = justauth
|
||||
* <p>
|
||||
* Okta 登录:Okta 账号域名前缀,比如以“ https://justauth.okta.com ”为例,{@code domainPrefix} = justauth
|
||||
*
|
||||
* @since 1.15.5
|
||||
* @since 1.16.0
|
||||
*/
|
||||
private String codingGroupName;
|
||||
private String domainPrefix;
|
||||
|
||||
/**
|
||||
* 针对国外服务可以单独设置代理
|
||||
@@ -131,4 +135,33 @@ public class AuthConfig {
|
||||
* @since 1.15.9
|
||||
*/
|
||||
private String packId;
|
||||
|
||||
/**
|
||||
* 是否开启 PKCE 模式,该配置仅用于支持 PKCE 模式的平台,针对无服务应用,不推荐使用隐式授权,推荐使用 PKCE 模式
|
||||
*
|
||||
* @since 1.15.9
|
||||
*/
|
||||
private boolean pkce;
|
||||
|
||||
/**
|
||||
* Okta 授权服务器的 ID, 默认为 default。如果要使用自定义授权服务,此处传实际的授权服务器 ID(一个随机串)
|
||||
* <p>
|
||||
* 创建自定义授权服务器,请参考:
|
||||
* <p>
|
||||
* ① https://developer.okta.com/docs/concepts/auth-servers
|
||||
* <p>
|
||||
* ② https://developer.okta.com/docs/guides/customize-authz-server
|
||||
*
|
||||
* @since 1.16.0
|
||||
*/
|
||||
private String authServerId;
|
||||
|
||||
/**
|
||||
* 适配 builder 模式 set 值的情况
|
||||
*
|
||||
* @return authServerId
|
||||
*/
|
||||
public String getAuthServerId() {
|
||||
return StringUtils.isEmpty(authServerId) ? "default" : authServerId;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,7 +73,7 @@ public enum AuthDefaultSource implements AuthSource {
|
||||
}
|
||||
},
|
||||
/**
|
||||
* 钉钉
|
||||
* 钉钉扫码登录
|
||||
*/
|
||||
DINGTALK {
|
||||
@Override
|
||||
@@ -91,6 +91,25 @@ public enum AuthDefaultSource implements AuthSource {
|
||||
return "https://oapi.dingtalk.com/sns/getuserinfo_bycode";
|
||||
}
|
||||
},
|
||||
/**
|
||||
* 钉钉账号登录
|
||||
*/
|
||||
DINGTALK_ACCOUNT {
|
||||
@Override
|
||||
public String authorize() {
|
||||
return "https://oapi.dingtalk.com/connect/oauth2/sns_authorize";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String accessToken() {
|
||||
return DINGTALK.accessToken();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String userInfo() {
|
||||
return DINGTALK.userInfo();
|
||||
}
|
||||
},
|
||||
/**
|
||||
* 百度
|
||||
*/
|
||||
@@ -315,17 +334,17 @@ public enum AuthDefaultSource implements AuthSource {
|
||||
FACEBOOK {
|
||||
@Override
|
||||
public String authorize() {
|
||||
return "https://www.facebook.com/v9.0/dialog/oauth";
|
||||
return "https://www.facebook.com/v10.0/dialog/oauth";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String accessToken() {
|
||||
return "https://graph.facebook.com/v9.0/oauth/access_token";
|
||||
return "https://graph.facebook.com/v10.0/oauth/access_token";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String userInfo() {
|
||||
return "https://graph.facebook.com/v9.0/me";
|
||||
return "https://graph.facebook.com/v10.0/me";
|
||||
}
|
||||
},
|
||||
/**
|
||||
@@ -832,5 +851,129 @@ public enum AuthDefaultSource implements AuthSource {
|
||||
public String refresh() {
|
||||
return "https://oauth.aliyun.com/v1/token";
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Amazon
|
||||
*
|
||||
* @since 1.16.0
|
||||
*/
|
||||
AMAZON {
|
||||
@Override
|
||||
public String authorize() {
|
||||
return "https://www.amazon.com/ap/oa";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String accessToken() {
|
||||
return "https://api.amazon.com/auth/o2/token";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String userInfo() {
|
||||
return "https://api.amazon.com/user/profile";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String refresh() {
|
||||
return "https://api.amazon.com/auth/o2/token";
|
||||
}
|
||||
},
|
||||
/**
|
||||
* Slack
|
||||
*
|
||||
* @since 1.16.0
|
||||
*/
|
||||
SLACK {
|
||||
@Override
|
||||
public String authorize() {
|
||||
return "https://slack.com/oauth/v2/authorize";
|
||||
}
|
||||
|
||||
/**
|
||||
* 该 API 获取到的是 access token
|
||||
*
|
||||
* https://slack.com/api/oauth.token 获取到的是 workspace token
|
||||
*
|
||||
* @return String
|
||||
*/
|
||||
@Override
|
||||
public String accessToken() {
|
||||
return "https://slack.com/api/oauth.v2.access";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String userInfo() {
|
||||
return "https://slack.com/api/users.info";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String revoke() {
|
||||
return "https://slack.com/api/auth.revoke";
|
||||
}
|
||||
},
|
||||
/**
|
||||
* line
|
||||
*
|
||||
* @since 1.16.0
|
||||
*/
|
||||
LINE {
|
||||
@Override
|
||||
public String authorize() {
|
||||
return "https://access.line.me/oauth2/v2.1/authorize";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String accessToken() {
|
||||
return "https://api.line.me/oauth2/v2.1/token";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String userInfo() {
|
||||
return "https://api.line.me/v2/profile";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String refresh() {
|
||||
return "https://api.line.me/oauth2/v2.1/token";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String revoke() {
|
||||
return "https://api.line.me/oauth2/v2.1/revoke";
|
||||
}
|
||||
},
|
||||
/**
|
||||
* Okta,
|
||||
* <p>
|
||||
* 团队/组织的域名不同,此处通过配置动态组装
|
||||
*
|
||||
* @since 1.16.0
|
||||
*/
|
||||
OKTA {
|
||||
@Override
|
||||
public String authorize() {
|
||||
return "https://%s.okta.com/oauth2/%s/v1/authorize";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String accessToken() {
|
||||
return "https://%s.okta.com/oauth2/%s/v1/token";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String refresh() {
|
||||
return "https://%s.okta.com/oauth2/%s/v1/token";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String userInfo() {
|
||||
return "https://%s.okta.com/oauth2/%s/v1/userinfo";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String revoke() {
|
||||
return "https://%s.okta.com/oauth2/%s/v1/revoke";
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
package me.zhyd.oauth.config;
|
||||
|
||||
import me.zhyd.oauth.log.Log;
|
||||
|
||||
/**
|
||||
* JustAuth 日志配置类
|
||||
*
|
||||
* @author HeJin
|
||||
*/
|
||||
public class JustAuthLogConfig {
|
||||
|
||||
/**
|
||||
* 设置日志级别
|
||||
*
|
||||
* @param level 日志级别
|
||||
*/
|
||||
public static void setLevel(Log.Level level) {
|
||||
Log.Config.level = level;
|
||||
}
|
||||
|
||||
/**
|
||||
* 关闭日志
|
||||
*/
|
||||
public static void disable() {
|
||||
Log.Config.enable = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 开启日志
|
||||
*/
|
||||
public static void enable() {
|
||||
Log.Config.enable = true;
|
||||
}
|
||||
}
|
||||
@@ -28,9 +28,10 @@ public enum AuthResponseStatus {
|
||||
ILLEGAL_CODE(5008, "Illegal code"),
|
||||
ILLEGAL_STATUS(5009, "Illegal state"),
|
||||
REQUIRED_REFRESH_TOKEN(5010, "The refresh token is required; it must not be null"),
|
||||
ILLEGAL_TOKEN(5011, "Invalid token"),
|
||||
;
|
||||
|
||||
private int code;
|
||||
private String msg;
|
||||
private final int code;
|
||||
private final String msg;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
package me.zhyd.oauth.enums.scope;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* Amazon平台 OAuth 授权范围
|
||||
*
|
||||
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
|
||||
* @version 1.0.0
|
||||
* @since 1.16.0
|
||||
*/
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum AuthAmazonScope implements AuthScope {
|
||||
|
||||
/**
|
||||
* {@code scope} 含义,以{@code description} 为准
|
||||
*/
|
||||
R_LITEPROFILE("profile", "The profile scope includes a user's name and email address", true),
|
||||
R_EMAILADDRESS("profile:user_id", "The profile:user_id scope only includes the user_id field of the profile", true),
|
||||
W_MEMBER_SOCIAL("postal_code", "This includes the user's zip/postal code number from their primary shipping address", true);
|
||||
|
||||
private final String scope;
|
||||
private final String description;
|
||||
private final boolean isDefault;
|
||||
|
||||
}
|
||||
@@ -23,8 +23,8 @@ public enum AuthBaiduScope implements AuthScope {
|
||||
PUBLIC("public", "可以访问公共的开放API。", false),
|
||||
HAO123("hao123", "可以访问Hao123 提供的开放API接口。该权限需要申请开通,请将具体的理由和用途发邮件给tuangou@baidu.com。", false);
|
||||
|
||||
private String scope;
|
||||
private String description;
|
||||
private boolean isDefault;
|
||||
private final String scope;
|
||||
private final String description;
|
||||
private final boolean isDefault;
|
||||
|
||||
}
|
||||
|
||||
@@ -24,8 +24,8 @@ public enum AuthCodingScope implements AuthScope {
|
||||
PROJECT_DEPOT("project:depot", "完整的仓库控制权限", false),
|
||||
PROJECT_WIKI("project:wiki", "授权读取与操作 wiki", false),
|
||||
;
|
||||
private String scope;
|
||||
private String description;
|
||||
private boolean isDefault;
|
||||
private final String scope;
|
||||
private final String description;
|
||||
private final boolean isDefault;
|
||||
|
||||
}
|
||||
|
||||
@@ -17,24 +17,24 @@ public enum AuthFacebookScope implements AuthScope {
|
||||
/**
|
||||
* {@code scope} 含义,以{@code description} 为准
|
||||
*/
|
||||
EMAIL("email", "获取用户的邮箱", false),
|
||||
USER_AGE_RANGE("user_age_range", "允许应用程序访问用户的年龄范围", false),
|
||||
USER_BIRTHDAY("user_birthday", "获取用户的生日", false),
|
||||
USER_FRIENDS("user_friends", "获取用户的好友列表", false),
|
||||
USER_GENDER("user_gender", "获取用户的性别", false),
|
||||
USER_HOMETOWN("user_hometown", "获取用户的家乡信息", false),
|
||||
USER_LIKES("user_likes", "获取用户的喜欢列表", false),
|
||||
USER_LINK("user_link", "获取用户的个人链接", false),
|
||||
USER_LOCATION("user_location", "获取用户的位置信息", false),
|
||||
USER_PHOTOS("user_photos", "获取用户的相册信息", false),
|
||||
USER_POSTS("user_posts", "获取用户发布的内容", false),
|
||||
USER_VIDEOS("user_videos", "获取用户上传的视频信息", false),
|
||||
EMAIL("email", "获取用户的邮箱", true),
|
||||
USER_AGE_RANGE("user_age_range", "允许应用程序访问用户的年龄范围", true),
|
||||
USER_BIRTHDAY("user_birthday", "获取用户的生日", true),
|
||||
USER_FRIENDS("user_friends", "获取用户的好友列表", true),
|
||||
USER_GENDER("user_gender", "获取用户的性别", true),
|
||||
USER_HOMETOWN("user_hometown", "获取用户的家乡信息", true),
|
||||
USER_LIKES("user_likes", "获取用户的喜欢列表", true),
|
||||
USER_LINK("user_link", "获取用户的个人链接", true),
|
||||
USER_LOCATION("user_location", "获取用户的位置信息", true),
|
||||
USER_PHOTOS("user_photos", "获取用户的相册信息", true),
|
||||
USER_POSTS("user_posts", "获取用户发布的内容", true),
|
||||
USER_VIDEOS("user_videos", "获取用户上传的视频信息", true),
|
||||
GROUPS_ACCESS_MEMBER_INFO("groups_access_member_info", "获取公开的群组成员信息", false),
|
||||
PUBLISH_TO_GROUPS("publish_to_groups", "授权您的应用程序代表某人将内容发布到组中,前提是他们已经授予您的应用程序访问权限", false),
|
||||
;
|
||||
|
||||
private String scope;
|
||||
private String description;
|
||||
private boolean isDefault;
|
||||
private final String scope;
|
||||
private final String description;
|
||||
private final boolean isDefault;
|
||||
|
||||
}
|
||||
|
||||
@@ -29,8 +29,8 @@ public enum AuthGiteeScope implements AuthScope {
|
||||
ENTERPRISES("enterprises", "查看、管理用户的企业以及成员", false),
|
||||
EMAILS("emails", "查看用户的个人邮箱信息", false);
|
||||
|
||||
private String scope;
|
||||
private String description;
|
||||
private boolean isDefault;
|
||||
private final String scope;
|
||||
private final String description;
|
||||
private final boolean isDefault;
|
||||
|
||||
}
|
||||
|
||||
@@ -47,8 +47,8 @@ public enum AuthGithubScope implements AuthScope {
|
||||
READ_GPG_KEY("read:gpg_key", "List and view details for GPG keys.", false),
|
||||
WORKFLOW("workflow", "Grants the ability to add and update GitHub Actions workflow files. Workflow files can be committed without this scope if the same file (with both the same path and contents) exists on another branch in the same repository.", false),
|
||||
;
|
||||
private String scope;
|
||||
private String description;
|
||||
private boolean isDefault;
|
||||
private final String scope;
|
||||
private final String description;
|
||||
private final boolean isDefault;
|
||||
|
||||
}
|
||||
|
||||
@@ -30,8 +30,8 @@ public enum AuthGitlabScope implements AuthScope {
|
||||
API("api", "Grants complete read/write access to the API, including all groups and projects, the container registry, and the package registry.", false),
|
||||
;
|
||||
|
||||
private String scope;
|
||||
private String description;
|
||||
private boolean isDefault;
|
||||
private final String scope;
|
||||
private final String description;
|
||||
private final boolean isDefault;
|
||||
|
||||
}
|
||||
|
||||
@@ -281,9 +281,9 @@ public enum AuthGoogleScope implements AuthScope {
|
||||
ADEXCHANGE_BUYER("https://www.googleapis.com/auth/adexchange.buyer", "Manage your Ad Exchange buyer account configuration", false),
|
||||
;
|
||||
|
||||
private String scope;
|
||||
private String description;
|
||||
private boolean isDefault;
|
||||
private final String scope;
|
||||
private final String description;
|
||||
private final boolean isDefault;
|
||||
|
||||
|
||||
public static List<String> getAdminDirectoryScopes() {
|
||||
|
||||
@@ -39,8 +39,8 @@ public enum AuthHuaweiScope implements AuthScope {
|
||||
|
||||
;
|
||||
|
||||
private String scope;
|
||||
private String description;
|
||||
private boolean isDefault;
|
||||
private final String scope;
|
||||
private final String description;
|
||||
private final boolean isDefault;
|
||||
|
||||
}
|
||||
|
||||
@@ -19,8 +19,8 @@ public enum AuthJdScope implements AuthScope {
|
||||
*/
|
||||
SNSAPI_BASE("snsapi_base", "基础授权", true);
|
||||
|
||||
private String scope;
|
||||
private String description;
|
||||
private boolean isDefault;
|
||||
private final String scope;
|
||||
private final String description;
|
||||
private final boolean isDefault;
|
||||
|
||||
}
|
||||
|
||||
@@ -21,8 +21,8 @@ public enum AuthKujialeScope implements AuthScope {
|
||||
GET_DESIGN("get_design", "获取指定方案详情", false),
|
||||
GET_BUDGET_LIST("get_budget_list", "获取清单预算概览数据", false);
|
||||
|
||||
private String scope;
|
||||
private String description;
|
||||
private boolean isDefault;
|
||||
private final String scope;
|
||||
private final String description;
|
||||
private final boolean isDefault;
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
package me.zhyd.oauth.enums.scope;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* Line 平台 OAuth 授权范围
|
||||
*
|
||||
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
|
||||
* @since 1.16.0
|
||||
*/
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum AuthLineScope implements AuthScope {
|
||||
|
||||
/**
|
||||
* {@code scope} 含义,以{@code description} 为准
|
||||
*/
|
||||
|
||||
PROFILE("profile", "Get profile details", true),
|
||||
OPENID("openid", "Get id token", true),
|
||||
EMAIL("email", "Get email (separate authorization required)", false);
|
||||
|
||||
private final String scope;
|
||||
private final String description;
|
||||
private final boolean isDefault;
|
||||
|
||||
}
|
||||
@@ -36,8 +36,8 @@ public enum AuthLinkedinScope implements AuthScope {
|
||||
W_ORGANIZATION_SOCIAL("w_organization_social", "Post, comment and like posts on your organization's behalf", false),
|
||||
W_SHARE("w_share", "Post updates to LinkedIn as you", false);
|
||||
|
||||
private String scope;
|
||||
private String description;
|
||||
private boolean isDefault;
|
||||
private final String scope;
|
||||
private final String description;
|
||||
private final boolean isDefault;
|
||||
|
||||
}
|
||||
|
||||
@@ -21,8 +21,8 @@ public enum AuthMiScope implements AuthScope {
|
||||
OPENID("user/openIdV2", "获取用户的OpenID", true),
|
||||
PHONE_EMAIL("user/phoneAndEmail", "获取用户的手机号和邮箱", true);
|
||||
|
||||
private String scope;
|
||||
private String description;
|
||||
private boolean isDefault;
|
||||
private final String scope;
|
||||
private final String description;
|
||||
private final boolean isDefault;
|
||||
|
||||
}
|
||||
|
||||
@@ -60,8 +60,8 @@ public enum AuthMicrosoftScope implements AuthScope {
|
||||
NOTES_READWRITE_ALL("Notes.ReadWrite.All", "允许应用读取、共享和修改已登录用户在组织中有权访问的 OneNote 笔记本", false),
|
||||
;
|
||||
|
||||
private String scope;
|
||||
private String description;
|
||||
private boolean isDefault;
|
||||
private final String scope;
|
||||
private final String description;
|
||||
private final boolean isDefault;
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
package me.zhyd.oauth.enums.scope;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* Okta 平台 OAuth 授权范围
|
||||
*
|
||||
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
|
||||
* @since 1.16.0
|
||||
*/
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum AuthOktaScope implements AuthScope {
|
||||
|
||||
/**
|
||||
* {@code scope} 含义,以{@code description} 为准
|
||||
*/
|
||||
OPENID("openid", "Signals that a request is an OpenID request.", true),
|
||||
PROFILE("profile", "The exact data varies based on what profile information you have provided, such as: name, time zone, picture, or birthday.", true),
|
||||
EMAIL("email", "This allows the app to view your email address.", true),
|
||||
ADDRESS("address", "This allows the app to view your address, such as: street address, city, state, and zip code.", true),
|
||||
PHONE("phone", "This allows the app to view your phone number.", true),
|
||||
OFFLINE_ACCESS("offline_access", "This keeps you signed in to the app, even when you are not using it.", true),
|
||||
OKTA_USERS_MANAGE("okta.users.manage", "Allows the app to create and manage users and read all profile and credential information for users", false),
|
||||
OKTA_USERS_READ("okta.users.read", "Allows the app to read any user's profile and credential information", false),
|
||||
OKTA_USERS_MANAGE_SELF("okta.users.manage.self", "Allows the app to manage the currently signed-in user's profile. Currently only supports user profile attribute updates.", false),
|
||||
OKTA_USERS_READ_SELF("okta.users.read.self", "Allows the app to read the currently signed-in user's profile and credential information", false),
|
||||
OKTA_APPS_MANAGE("okta.apps.manage", "Allows the app to create and manage Apps in your Okta organization", false),
|
||||
OKTA_APPS_READ("okta.apps.read", "Allows the app to read information about Apps in your Okta organization", false),
|
||||
OKTA_AUTHORIZATIONSERVERS_MANAGE("okta.authorizationServers.manage", "Allows the app to manage authorization servers", false),
|
||||
OKTA_AUTHORIZATIONSERVERS_READ("okta.authorizationServers.read", "Allows the app to read authorization server information", false),
|
||||
OKTA_CLIENTS_MANAGE("okta.clients.manage", "Allows the app to manage all OAuth/OIDC clients and to create new clients", false),
|
||||
OKTA_CLIENTS_READ("okta.clients.read", "Allows the app to read information for all OAuth/OIDC clients", false),
|
||||
OKTA_CLIENTS_REGISTER("okta.clients.register", "Allows the app to register (create) new OAuth/OIDC clients (but not read information about existing clients)", false),
|
||||
OKTA_EVENTHOOKS_MANAGE("okta.eventHooks.manage", "Allows the app to create and manage Event Hooks in your Okta organization", false),
|
||||
OKTA_EVENTHOOKS_READ("okta.eventHooks.read", "Allows the app to read information about Event Hooks in your Okta organization", false),
|
||||
OKTA_FACTORS_MANAGE("okta.factors.manage", "Allows the app to manage all admin operations for org factors (for example, activate, deactive, read)", false),
|
||||
OKTA_FACTORS_READ("okta.factors.read", "Allows the app to read org factors information", false),
|
||||
OKTA_GROUPS_MANAGE("okta.groups.manage", "Allows the app to manage groups in your Okta organization", false),
|
||||
OKTA_GROUPS_READ("okta.groups.read", "Allows the app to read information about groups and their members in your Okta organization", false),
|
||||
OKTA_IDPS_MANAGE("okta.idps.manage", "Allows the app to create and manage Identity Providers in your Okta organization", false),
|
||||
OKTA_IDPS_READ("okta.idps.read", "Allows the app to read information about Identity Providers in your Okta organization", false),
|
||||
OKTA_INLINEHOOKS_MANAGE("okta.inlineHooks.manage", "Allows the app to create and manage Inline Hooks in your Okta organization.", false),
|
||||
OKTA_INLINEHOOKS_READ("okta.inlineHooks.read", "Allows the app to read information about Inline Hooks in your Okta organization.", false),
|
||||
OKTA_LINKEDOBJECTS_MANAGE("okta.linkedObjects.manage", "Allows the app to manage Linked Object definitions in your Okta organization.", false),
|
||||
OKTA_LINKEDOBJECTS_READ("okta.linkedObjects.read", "Allows the app to read Linked Object definitions in your Okta organization.", false),
|
||||
OKTA_LOGS_READ("okta.logs.read", "Allows the app to read information about System Log entries in your Okta organization", false),
|
||||
OKTA_ROLES_MANAGE("okta.roles.manage", "Allows the app to create and manage Administrator Roles in your Okta organization", false),
|
||||
OKTA_ROLES_READ("okta.roles.read", "Allows the app to read information about Administrator Roles in your Okta organization", false),
|
||||
OKTA_SCHEMAS_MANAGE("okta.schemas.manage", "Allows the app to create and manage Schemas in your Okta organization", false),
|
||||
OKTA_SCHEMAS_READ("okta.schemas.read", "Allows the app to read information about Schemas in your Okta organization", false),
|
||||
OKTA_SESSIONS_MANAGE("okta.sessions.manage", "Allows the app to manage all sessions in your Okta organization", false),
|
||||
OKTA_SESSIONS_READ("okta.sessions.read", "Allows the app to read all sessions in your Okta organization", false),
|
||||
OKTA_TEMPLATES_MANAGE("okta.templates.manage", "Allows the app to manage all custom templates in your Okta organization", false),
|
||||
OKTA_TEMPLATES_READ("okta.templates.read", "Allows the app to read all custom templates in your Okta organization", false),
|
||||
OKTA_TRUSTEDORIGINS_MANAGE("okta.trustedOrigins.manage", "Allows the app to manage all Trusted Origins in your Okta organization", false),
|
||||
OKTA_TRUSTEDORIGINS_READ("okta.trustedOrigins.read", "Allows the app to read all Trusted Origins in your Okta organization", false),
|
||||
OKTA_POLICIES_MANAGE("okta.policies.manage", "Allows the app to manage Policies in your Okta organization", false),
|
||||
OKTA_POLICIES_READ("okta.policies.read", "Allows the app to read information about Policies in your Okta organization", false),;
|
||||
|
||||
private final String scope;
|
||||
private final String description;
|
||||
private final boolean isDefault;
|
||||
|
||||
}
|
||||
@@ -23,8 +23,8 @@ public enum AuthPinterestScope implements AuthScope {
|
||||
WRITE_RELATIONSHIPS("write_relationships", "Use PATCH, POST and DELETE methods on a user’s follows and followers (on boards, users and interests).", false),
|
||||
;
|
||||
|
||||
private String scope;
|
||||
private String description;
|
||||
private boolean isDefault;
|
||||
private final String scope;
|
||||
private final String description;
|
||||
private final boolean isDefault;
|
||||
|
||||
}
|
||||
|
||||
@@ -28,8 +28,8 @@ public enum AuthQqScope implements AuthScope {
|
||||
ADD_ALBUM("add_album", "在用户的空间相册里,创建一个新的个人相册", false),
|
||||
LIST_PHOTO("list_photo", "获取用户QQ空间相册中的照片列表", false);
|
||||
|
||||
private String scope;
|
||||
private String description;
|
||||
private boolean isDefault;
|
||||
private final String scope;
|
||||
private final String description;
|
||||
private final boolean isDefault;
|
||||
|
||||
}
|
||||
|
||||
@@ -48,8 +48,8 @@ public enum AuthRenrenScope implements AuthScope {
|
||||
ADMIN_PAGE("admin_page", "以用户的身份,管理其可以管理的公共主页的权限。", false),
|
||||
;
|
||||
|
||||
private String scope;
|
||||
private String description;
|
||||
private boolean isDefault;
|
||||
private final String scope;
|
||||
private final String description;
|
||||
private final boolean isDefault;
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,116 @@
|
||||
package me.zhyd.oauth.enums.scope;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* Slack 平台 OAuth 授权范围
|
||||
*
|
||||
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
|
||||
* @since 1.16.0
|
||||
*/
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum AuthSlackScope implements AuthScope {
|
||||
|
||||
/**
|
||||
* {@code scope} 含义,以{@code description} 为准
|
||||
*/
|
||||
USERS_PROFILE_READ("users.profile:read", "View profile details about people in a workspace", true),
|
||||
USERS_READ("users:read", "View people in a workspace", true),
|
||||
USERS_READ_EMAIL("users:read.email", "View email addresses of people in a workspace", true),
|
||||
USERS_PROFILE_WRITE("users.profile:write", "Edit a user’s profile information and status", false),
|
||||
USERS_PROFILE_WRITE_USER("users.profile:write:user", "Change the user's profile fields", false),
|
||||
USERS_WRITE("users:write", "Set presence for your slack app", false),
|
||||
ADMIN("admin", "Administer a workspace", false),
|
||||
ADMIN_ANALYTICS_READ("admin.analytics:read", "Access analytics data about the organization", false),
|
||||
ADMIN_APPS_READ("admin.apps:read", "View apps and app requests in a workspace", false),
|
||||
ADMIN_APPS_WRITE("admin.apps:write", "Manage apps in a workspace", false),
|
||||
ADMIN_BARRIERS_READ("admin.barriers:read", "Read information barriers in the organization", false),
|
||||
ADMIN_BARRIERS_WRITE("admin.barriers:write", "Manage information barriers in the organization", false),
|
||||
ADMIN_CONVERSATIONS_READ("admin.conversations:read", "View the channel’s member list, topic, purpose and channel name", false),
|
||||
ADMIN_CONVERSATIONS_WRITE("admin.conversations:write", "Start a new conversation, modify a conversation and modify channel details", false),
|
||||
ADMIN_INVITES_READ("admin.invites:read", "Gain information about invite requests in a Grid organization.", false),
|
||||
ADMIN_INVITES_WRITE("admin.invites:write", "Approve or deny invite requests in a Grid organization.", false),
|
||||
ADMIN_TEAMS_READ("admin.teams:read", "Access information about a workspace", false),
|
||||
ADMIN_TEAMS_WRITE("admin.teams:write", "Make changes to a workspace", false),
|
||||
ADMIN_USERGROUPS_READ("admin.usergroups:read", "Access information about user groups", false),
|
||||
ADMIN_USERGROUPS_WRITE("admin.usergroups:write", "Make changes to your usergroups", false),
|
||||
ADMIN_USERS_READ("admin.users:read", "Access a workspace’s profile information", false),
|
||||
ADMIN_USERS_WRITE("admin.users:write", "Modify account information", false),
|
||||
APP_MENTIONS_READ("app_mentions:read", "View messages that directly mention @your_slack_app in conversations that the app is in", false),
|
||||
AUDITLOGS_READ("auditlogs:read", "View events from all workspaces, channels and users (Enterprise Grid only)", false),
|
||||
BOT("bot", "Add the ability for people to direct message or mention @your_slack_app", false),
|
||||
CALLS_READ("calls:read", "View information about ongoing and past calls", false),
|
||||
CALLS_WRITE("calls:write", "Start and manage calls in a workspace", false),
|
||||
CHANNELS_HISTORY("channels:history", "View messages and other content in public channels that your slack app has been added to", false),
|
||||
CHANNELS_JOIN("channels:join", "Join public channels in a workspace", false),
|
||||
CHANNELS_MANAGE("channels:manage", "Manage public channels that your slack app has been added to and create new ones", false),
|
||||
CHANNELS_READ("channels:read", "View basic information about public channels in a workspace", false),
|
||||
CHANNELS_WRITE("channels:write", "Manage a user’s public channels and create new ones on a user’s behalf", false),
|
||||
CHAT_WRITE("chat:write", "Post messages in approved channels & conversations", false),
|
||||
CHAT_WRITE_CUSTOMIZE("chat:write.customize", "Send messages as @your_slack_app with a customized username and avatar", false),
|
||||
CHAT_WRITE_PUBLIC("chat:write.public", "Send messages to channels @your_slack_app isn't a member of", false),
|
||||
CHAT_WRITE_BOT("chat:write:bot", "Send messages as your slack app", false),
|
||||
CHAT_WRITE_USER("chat:write:user", "Send messages on a user’s behalf", false),
|
||||
CLIENT("client", "Receive all events from a workspace in real time", false),
|
||||
COMMANDS("commands", "Add shortcuts and/or slash commands that people can use", false),
|
||||
CONVERSATIONS_HISTORY("conversations:history", "Deprecated: Retrieve conversation history for legacy workspace apps", false),
|
||||
CONVERSATIONS_READ("conversations:read", "Deprecated: Retrieve information on conversations for legacy workspace apps", false),
|
||||
CONVERSATIONS_WRITE("conversations:write", "Deprecated: Edit conversation attributes for legacy workspace apps", false),
|
||||
DND_READ("dnd:read", "View Do Not Disturb settings for people in a workspace", false),
|
||||
DND_WRITE("dnd:write", "Edit a user’s Do Not Disturb settings", false),
|
||||
DND_WRITE_USER("dnd:write:user", "Change the user's Do Not Disturb settings", false),
|
||||
EMOJI_READ("emoji:read", "View custom emoji in a workspace", false),
|
||||
FILES_READ("files:read", "View files shared in channels and conversations that your slack app has been added to", false),
|
||||
FILES_WRITE("files:write", "Upload, edit, and delete files as your slack app", false),
|
||||
FILES_WRITE_USER("files:write:user", "Upload, edit, and delete files as your slack app", false),
|
||||
GROUPS_HISTORY("groups:history", "View messages and other content in private channels that your slack app has been added to", false),
|
||||
GROUPS_READ("groups:read", "View basic information about private channels that your slack app has been added to", false),
|
||||
GROUPS_WRITE("groups:write", "Manage private channels that your slack app has been added to and create new ones", false),
|
||||
IDENTIFY("identify", "View information about a user’s identity", false),
|
||||
IDENTITY_AVATAR("identity.avatar", "View a user’s Slack avatar", false),
|
||||
IDENTITY_AVATAR_READ_USER("identity.avatar:read:user", "View the user's profile picture", false),
|
||||
IDENTITY_BASIC("identity.basic", "View information about a user’s identity", false),
|
||||
IDENTITY_EMAIL("identity.email", "View a user’s email address", false),
|
||||
IDENTITY_EMAIL_READ_USER("identity.email:read:user", "This scope is not yet described.", false),
|
||||
IDENTITY_TEAM("identity.team", "View a user’s Slack workspace name", false),
|
||||
IDENTITY_TEAM_READ_USER("identity.team:read:user", "View the workspace's name, domain, and icon", false),
|
||||
IDENTITY_READ_USER("identity:read:user", "This scope is not yet described.", false),
|
||||
IM_HISTORY("im:history", "View messages and other content in direct messages that your slack app has been added to", false),
|
||||
IM_READ("im:read", "View basic information about direct messages that your slack app has been added to", false),
|
||||
IM_WRITE("im:write", "Start direct messages with people", false),
|
||||
INCOMING_WEBHOOK("incoming-webhook", "Create one-way webhooks to post messages to a specific channel", false),
|
||||
LINKS_READ("links:read", "View URLs in messages", false),
|
||||
LINKS_WRITE("links:write", "Show previews of URLs in messages", false),
|
||||
MPIM_HISTORY("mpim:history", "View messages and other content in group direct messages that your slack app has been added to", false),
|
||||
MPIM_READ("mpim:read", "View basic information about group direct messages that your slack app has been added to", false),
|
||||
MPIM_WRITE("mpim:write", "Start group direct messages with people", false),
|
||||
NONE("none", "Execute methods without needing a scope", false),
|
||||
PINS_READ("pins:read", "View pinned content in channels and conversations that your slack app has been added to", false),
|
||||
PINS_WRITE("pins:write", "Add and remove pinned messages and files", false),
|
||||
POST("post", "Post messages to a workspace", false),
|
||||
REACTIONS_READ("reactions:read", "View emoji reactions and their associated content in channels and conversations that your slack app has been added to", false),
|
||||
REACTIONS_WRITE("reactions:write", "Add and edit emoji reactions", false),
|
||||
READ("read", "View all content in a workspace", false),
|
||||
REMINDERS_READ("reminders:read", "View reminders created by your slack app", false),
|
||||
REMINDERS_READ_USER("reminders:read:user", "Access reminders created by a user or for a user", false),
|
||||
REMINDERS_WRITE("reminders:write", "Add, remove, or mark reminders as complete", false),
|
||||
REMINDERS_WRITE_USER("reminders:write:user", "Add, remove, or complete reminders for the user", false),
|
||||
REMOTE_FILES_READ("remote_files:read", "View remote files added by the app in a workspace", false),
|
||||
REMOTE_FILES_SHARE("remote_files:share", "Share remote files on a user’s behalf", false),
|
||||
REMOTE_FILES_WRITE("remote_files:write", "Add, edit, and delete remote files on a user’s behalf", false),
|
||||
SEARCH_READ("search:read", "Search a workspace’s content", false),
|
||||
STARS_READ("stars:read", "View messages and files that your slack app has starred", false),
|
||||
STARS_WRITE("stars:write", "Add or remove stars", false),
|
||||
TEAM_READ("team:read", "View the name, email domain, and icon for workspaces your slack app is connected to", false),
|
||||
TOKENS_BASIC("tokens.basic", "Execute methods without needing a scope", false),
|
||||
USERGROUPS_READ("usergroups:read", "View user groups in a workspace", false),
|
||||
USERGROUPS_WRITE("usergroups:write", "Create and manage user groups", false),
|
||||
WORKFLOW_STEPS_EXECUTE("workflow.steps:execute", "Add steps that people can use in Workflow Builder", false);
|
||||
|
||||
private final String scope;
|
||||
private final String description;
|
||||
private final boolean isDefault;
|
||||
|
||||
}
|
||||
@@ -22,8 +22,8 @@ public enum AuthStackoverflowScope implements AuthScope {
|
||||
WRITE_ACCESS("write_access", "perform write operations as a user", false),
|
||||
PRIVATE_INFO("private_info", "access full history of a user's private actions on the site", false);
|
||||
|
||||
private String scope;
|
||||
private String description;
|
||||
private boolean isDefault;
|
||||
private final String scope;
|
||||
private final String description;
|
||||
private final boolean isDefault;
|
||||
|
||||
}
|
||||
|
||||
@@ -17,8 +17,8 @@ public enum AuthWeChatEnterpriseWebScope implements AuthScope {
|
||||
*/
|
||||
SNSAPI_BASE("snsapi_base", "应用授权作用域。企业自建应用固定填写:snsapi_base", true);
|
||||
|
||||
private String scope;
|
||||
private String description;
|
||||
private boolean isDefault;
|
||||
private final String scope;
|
||||
private final String description;
|
||||
private final boolean isDefault;
|
||||
|
||||
}
|
||||
|
||||
@@ -19,8 +19,8 @@ public enum AuthWechatMpScope implements AuthScope {
|
||||
SNSAPI_USERINFO("snsapi_userinfo", "弹出授权页面,可通过openid拿到昵称、性别、所在地。并且, 即使在未关注的情况下,只要用户授权,也能获取其信息", true),
|
||||
SNSAPI_BASE("snsapi_base", "不弹出授权页面,直接跳转,只能获取用户openid", false);
|
||||
|
||||
private String scope;
|
||||
private String description;
|
||||
private boolean isDefault;
|
||||
private final String scope;
|
||||
private final String description;
|
||||
private final boolean isDefault;
|
||||
|
||||
}
|
||||
|
||||
@@ -27,8 +27,8 @@ public enum AuthWeiboScope implements AuthScope {
|
||||
STATUSES_TO_ME_READ("statuses_to_me_read", "定向微博读取接口组,<a rel=\"nofollow\" href=\"http://open.weibo.com/wiki/API%E6%96%87%E6%A1%A3_V2#.E5.BE.AE.E5.8D.9A\">接口文档</a>", false),
|
||||
FOLLOW_APP_OFFICIAL_MICROBLOG("follow_app_official_microblog", "关注应用官方微博,该参数不对应具体接口,只需在应用控制台填写官方帐号即可。填写的路径:我的应用-选择自己的应用-应用信息-基本信息-官方运营账号(默认值是应用开发者帐号)", false);
|
||||
|
||||
private String scope;
|
||||
private String description;
|
||||
private boolean isDefault;
|
||||
private final String scope;
|
||||
private final String description;
|
||||
private final boolean isDefault;
|
||||
|
||||
}
|
||||
|
||||
@@ -136,15 +136,15 @@ public class Log {
|
||||
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
|
||||
* @since 1.10.0
|
||||
*/
|
||||
static class Config {
|
||||
public static class Config {
|
||||
|
||||
/**
|
||||
* 需要打印的日志级别
|
||||
*/
|
||||
static Level level = Level.DEBUG;
|
||||
public static Level level = Level.DEBUG;
|
||||
/**
|
||||
* 是否启用日志打印功能,默认启用
|
||||
*/
|
||||
static boolean enable = true;
|
||||
public static boolean enable = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/**
|
||||
* 针对JustAuth简单封装的日志打印工具,可用过{@link me.zhyd.oauth.log.Log.Config}开关日志和指定日志级别
|
||||
* 针对JustAuth简单封装的日志打印工具,可用过{@link me.zhyd.oauth.config.JustAuthLogConfig}开关日志和指定日志级别
|
||||
*/
|
||||
package me.zhyd.oauth.log;
|
||||
|
||||
@@ -0,0 +1,104 @@
|
||||
package me.zhyd.oauth.request;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import me.zhyd.oauth.cache.AuthStateCache;
|
||||
import me.zhyd.oauth.config.AuthConfig;
|
||||
import me.zhyd.oauth.config.AuthSource;
|
||||
import me.zhyd.oauth.enums.AuthUserGender;
|
||||
import me.zhyd.oauth.exception.AuthException;
|
||||
import me.zhyd.oauth.model.AuthCallback;
|
||||
import me.zhyd.oauth.model.AuthToken;
|
||||
import me.zhyd.oauth.model.AuthUser;
|
||||
import me.zhyd.oauth.utils.GlobalAuthUtils;
|
||||
import me.zhyd.oauth.utils.HttpUtils;
|
||||
import me.zhyd.oauth.utils.UrlBuilder;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 钉钉登录抽象类,负责处理使用钉钉账号登录第三方网站和扫码登录第三方网站两种钉钉的登录方式
|
||||
* </p>
|
||||
*
|
||||
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
|
||||
* @since 1.16.0
|
||||
*/
|
||||
public abstract class AbstractAuthDingtalkRequest extends AuthDefaultRequest {
|
||||
|
||||
public AbstractAuthDingtalkRequest(AuthConfig config, AuthSource source) {
|
||||
super(config, source);
|
||||
}
|
||||
|
||||
|
||||
public AbstractAuthDingtalkRequest(AuthConfig config, AuthSource source, AuthStateCache authStateCache) {
|
||||
super(config, source, authStateCache);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AuthToken getAccessToken(AuthCallback authCallback) {
|
||||
return AuthToken.builder().accessCode(authCallback.getCode()).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AuthUser getUserInfo(AuthToken authToken) {
|
||||
String code = authToken.getAccessCode();
|
||||
JSONObject param = new JSONObject();
|
||||
param.put("tmp_auth_code", code);
|
||||
String response = new HttpUtils(config.getHttpConfig()).post(userInfoUrl(authToken), param.toJSONString());
|
||||
JSONObject object = JSON.parseObject(response);
|
||||
if (object.getIntValue("errcode") != 0) {
|
||||
throw new AuthException(object.getString("errmsg"));
|
||||
}
|
||||
object = object.getJSONObject("user_info");
|
||||
AuthToken token = AuthToken.builder()
|
||||
.openId(object.getString("openid"))
|
||||
.unionId(object.getString("unionid"))
|
||||
.build();
|
||||
return AuthUser.builder()
|
||||
.rawUserInfo(object)
|
||||
.uuid(object.getString("unionid"))
|
||||
.nickname(object.getString("nick"))
|
||||
.username(object.getString("nick"))
|
||||
.gender(AuthUserGender.UNKNOWN)
|
||||
.source(source.toString())
|
||||
.token(token)
|
||||
.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回带{@code state}参数的授权url,授权回调时会带上这个{@code state}
|
||||
*
|
||||
* @param state state 验证授权流程的参数,可以防止csrf
|
||||
* @return 返回授权地址
|
||||
* @since 1.9.3
|
||||
*/
|
||||
@Override
|
||||
public String authorize(String state) {
|
||||
return UrlBuilder.fromBaseUrl(source.authorize())
|
||||
.queryParam("response_type", "code")
|
||||
.queryParam("appid", config.getClientId())
|
||||
.queryParam("scope", "snsapi_login")
|
||||
.queryParam("redirect_uri", config.getRedirectUri())
|
||||
.queryParam("state", getRealState(state))
|
||||
.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回获取userInfo的url
|
||||
*
|
||||
* @param authToken 用户授权后的token
|
||||
* @return 返回获取userInfo的url
|
||||
*/
|
||||
@Override
|
||||
protected String userInfoUrl(AuthToken authToken) {
|
||||
// 根据timestamp, appSecret计算签名值
|
||||
String timestamp = System.currentTimeMillis() + "";
|
||||
String urlEncodeSignature = GlobalAuthUtils.generateDingTalkSignature(config.getClientSecret(), timestamp);
|
||||
|
||||
return UrlBuilder.fromBaseUrl(source.userInfo())
|
||||
.queryParam("signature", urlEncodeSignature)
|
||||
.queryParam("timestamp", timestamp)
|
||||
.queryParam("accessKey", config.getClientId())
|
||||
.build();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -8,7 +8,6 @@ import me.zhyd.oauth.enums.AuthUserGender;
|
||||
import me.zhyd.oauth.model.AuthCallback;
|
||||
import me.zhyd.oauth.model.AuthToken;
|
||||
import me.zhyd.oauth.model.AuthUser;
|
||||
import me.zhyd.oauth.utils.UrlBuilder;
|
||||
|
||||
/**
|
||||
* 阿里云登录
|
||||
@@ -31,12 +30,12 @@ public class AuthAliyunRequest extends AuthDefaultRequest {
|
||||
String response = doPostAuthorizationCode(authCallback.getCode());
|
||||
JSONObject accessTokenObject = JSONObject.parseObject(response);
|
||||
return AuthToken.builder()
|
||||
.accessToken(accessTokenObject.getString("access_token"))
|
||||
.expireIn(accessTokenObject.getIntValue("expires_in"))
|
||||
.tokenType(accessTokenObject.getString("token_type"))
|
||||
.idToken(accessTokenObject.getString("id_token"))
|
||||
.refreshToken(accessTokenObject.getString("refresh_token"))
|
||||
.build();
|
||||
.accessToken(accessTokenObject.getString("access_token"))
|
||||
.expireIn(accessTokenObject.getIntValue("expires_in"))
|
||||
.tokenType(accessTokenObject.getString("token_type"))
|
||||
.idToken(accessTokenObject.getString("id_token"))
|
||||
.refreshToken(accessTokenObject.getString("refresh_token"))
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,182 @@
|
||||
package me.zhyd.oauth.request;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.xkcoding.http.constants.Constants;
|
||||
import com.xkcoding.http.support.HttpHeader;
|
||||
import com.xkcoding.http.util.UrlUtil;
|
||||
import me.zhyd.oauth.cache.AuthStateCache;
|
||||
import me.zhyd.oauth.config.AuthConfig;
|
||||
import me.zhyd.oauth.config.AuthDefaultSource;
|
||||
import me.zhyd.oauth.enums.AuthResponseStatus;
|
||||
import me.zhyd.oauth.enums.AuthUserGender;
|
||||
import me.zhyd.oauth.enums.scope.AuthAmazonScope;
|
||||
import me.zhyd.oauth.exception.AuthException;
|
||||
import me.zhyd.oauth.model.AuthCallback;
|
||||
import me.zhyd.oauth.model.AuthResponse;
|
||||
import me.zhyd.oauth.model.AuthToken;
|
||||
import me.zhyd.oauth.model.AuthUser;
|
||||
import me.zhyd.oauth.utils.AuthScopeUtils;
|
||||
import me.zhyd.oauth.utils.HttpUtils;
|
||||
import me.zhyd.oauth.utils.PkceUtil;
|
||||
import me.zhyd.oauth.utils.UrlBuilder;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* Amazon登录
|
||||
* Login with Amazon for Websites Overview: https://developer.amazon.com/zh/docs/login-with-amazon/register-web.html
|
||||
* Login with Amazon SDK for JavaScript Reference Guide:https://developer.amazon.com/zh/docs/login-with-amazon/javascript-sdk-reference.html
|
||||
*
|
||||
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
|
||||
* @since 1.16.0
|
||||
*/
|
||||
public class AuthAmazonRequest extends AuthDefaultRequest {
|
||||
|
||||
public AuthAmazonRequest(AuthConfig config) {
|
||||
super(config, AuthDefaultSource.AMAZON);
|
||||
}
|
||||
|
||||
public AuthAmazonRequest(AuthConfig config, AuthStateCache authStateCache) {
|
||||
super(config, AuthDefaultSource.AMAZON, authStateCache);
|
||||
}
|
||||
|
||||
/**
|
||||
* https://developer.amazon.com/zh/docs/login-with-amazon/authorization-code-grant.html#authorization-request
|
||||
*
|
||||
* @param state state 验证授权流程的参数,可以防止csrf
|
||||
* @return String
|
||||
*/
|
||||
@Override
|
||||
public String authorize(String state) {
|
||||
UrlBuilder builder = UrlBuilder.fromBaseUrl(source.authorize())
|
||||
.queryParam("client_id", config.getClientId())
|
||||
.queryParam("scope", this.getScopes(" ", true, AuthScopeUtils.getDefaultScopes(AuthAmazonScope.values())))
|
||||
.queryParam("redirect_uri", config.getRedirectUri())
|
||||
.queryParam("response_type", "code")
|
||||
.queryParam("state", getRealState(state));
|
||||
|
||||
if (config.isPkce()) {
|
||||
String cacheKey = this.source.getName().concat(":code_verifier:").concat(config.getClientId());
|
||||
String codeVerifier = PkceUtil.generateCodeVerifier();
|
||||
String codeChallengeMethod = "S256";
|
||||
String codeChallenge = PkceUtil.generateCodeChallenge(codeChallengeMethod, codeVerifier);
|
||||
builder.queryParam("code_challenge", codeChallenge)
|
||||
.queryParam("code_challenge_method", codeChallengeMethod);
|
||||
// 缓存 codeVerifier 十分钟
|
||||
this.authStateCache.cache(cacheKey, codeVerifier, TimeUnit.MINUTES.toMillis(10));
|
||||
}
|
||||
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* https://developer.amazon.com/zh/docs/login-with-amazon/authorization-code-grant.html#access-token-request
|
||||
*
|
||||
* @return access token
|
||||
*/
|
||||
@Override
|
||||
protected AuthToken getAccessToken(AuthCallback authCallback) {
|
||||
Map<String, String> form = new HashMap<>(9);
|
||||
form.put("grant_type", "authorization_code");
|
||||
form.put("code", authCallback.getCode());
|
||||
form.put("redirect_uri", config.getRedirectUri());
|
||||
form.put("client_id", config.getClientId());
|
||||
form.put("client_secret", config.getClientSecret());
|
||||
|
||||
if (config.isPkce()) {
|
||||
String cacheKey = this.source.getName().concat(":code_verifier:").concat(config.getClientId());
|
||||
String codeVerifier = this.authStateCache.get(cacheKey);
|
||||
form.put("code_verifier", codeVerifier);
|
||||
}
|
||||
return getToken(form, this.source.accessToken());
|
||||
}
|
||||
|
||||
@Override
|
||||
public AuthResponse refresh(AuthToken authToken) {
|
||||
Map<String, String> form = new HashMap<>(7);
|
||||
form.put("grant_type", "refresh_token");
|
||||
form.put("refresh_token", authToken.getRefreshToken());
|
||||
form.put("client_id", config.getClientId());
|
||||
form.put("client_secret", config.getClientSecret());
|
||||
return AuthResponse.builder()
|
||||
.code(AuthResponseStatus.SUCCESS.getCode())
|
||||
.data(getToken(form, this.source.refresh()))
|
||||
.build();
|
||||
|
||||
}
|
||||
|
||||
private AuthToken getToken(Map<String, String> param, String url) {
|
||||
HttpHeader httpHeader = new HttpHeader();
|
||||
httpHeader.add("Host", "api.amazon.com");
|
||||
httpHeader.add(Constants.CONTENT_TYPE, "application/x-www-form-urlencoded;charset=UTF-8");
|
||||
String response = new HttpUtils(config.getHttpConfig()).post(url, param, httpHeader, false);
|
||||
JSONObject jsonObject = JSONObject.parseObject(response);
|
||||
this.checkResponse(jsonObject);
|
||||
return AuthToken.builder()
|
||||
.accessToken(jsonObject.getString("access_token"))
|
||||
.tokenType(jsonObject.getString("token_type"))
|
||||
.expireIn(jsonObject.getIntValue("expires_in"))
|
||||
.refreshToken(jsonObject.getString("refresh_token"))
|
||||
.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验响应内容是否正确
|
||||
*
|
||||
* @param jsonObject 响应内容
|
||||
*/
|
||||
private void checkResponse(JSONObject jsonObject) {
|
||||
if (jsonObject.containsKey("error")) {
|
||||
throw new AuthException(jsonObject.getString("error_description").concat(" ") + jsonObject.getString("error_description"));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* https://developer.amazon.com/zh/docs/login-with-amazon/obtain-customer-profile.html#call-profile-endpoint
|
||||
*
|
||||
* @param authToken token信息
|
||||
* @return AuthUser
|
||||
*/
|
||||
@Override
|
||||
protected AuthUser getUserInfo(AuthToken authToken) {
|
||||
String accessToken = authToken.getAccessToken();
|
||||
this.checkToken(accessToken);
|
||||
|
||||
HttpHeader httpHeader = new HttpHeader();
|
||||
httpHeader.add("Host", "api.amazon.com");
|
||||
httpHeader.add("Authorization", "bearer " + accessToken);
|
||||
String userInfo = new HttpUtils(config.getHttpConfig()).get(this.source.userInfo(), new HashMap<>(0), httpHeader, false);
|
||||
JSONObject jsonObject = JSONObject.parseObject(userInfo);
|
||||
this.checkResponse(jsonObject);
|
||||
|
||||
return AuthUser.builder()
|
||||
.rawUserInfo(jsonObject)
|
||||
.uuid(jsonObject.getString("user_id"))
|
||||
.username(jsonObject.getString("name"))
|
||||
.nickname(jsonObject.getString("name"))
|
||||
.email(jsonObject.getString("email"))
|
||||
.gender(AuthUserGender.UNKNOWN)
|
||||
.source(source.toString())
|
||||
.token(authToken)
|
||||
.build();
|
||||
}
|
||||
|
||||
private void checkToken(String accessToken) {
|
||||
String tokenInfo = new HttpUtils(config.getHttpConfig()).get("https://api.amazon.com/auth/o2/tokeninfo?access_token=" + UrlUtil.urlEncode(accessToken));
|
||||
JSONObject jsonObject = JSONObject.parseObject(tokenInfo);
|
||||
if (!config.getClientId().equals(jsonObject.getString("aud"))) {
|
||||
throw new AuthException(AuthResponseStatus.ILLEGAL_TOKEN);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String userInfoUrl(AuthToken authToken) {
|
||||
return UrlBuilder.fromBaseUrl(source.userInfo())
|
||||
.queryParam("user_id", authToken.getUserId())
|
||||
.queryParam("screen_name", authToken.getScreenName())
|
||||
.queryParam("include_entities", true)
|
||||
.build();
|
||||
}
|
||||
}
|
||||
@@ -85,7 +85,7 @@ public class AuthCodingRequest extends AuthDefaultRequest {
|
||||
*/
|
||||
@Override
|
||||
public String authorize(String state) {
|
||||
return UrlBuilder.fromBaseUrl(String.format(source.authorize(), config.getCodingGroupName()))
|
||||
return UrlBuilder.fromBaseUrl(String.format(source.authorize(), config.getDomainPrefix()))
|
||||
.queryParam("response_type", "code")
|
||||
.queryParam("client_id", config.getClientId())
|
||||
.queryParam("redirect_uri", config.getRedirectUri())
|
||||
@@ -102,7 +102,7 @@ public class AuthCodingRequest extends AuthDefaultRequest {
|
||||
*/
|
||||
@Override
|
||||
public String accessTokenUrl(String code) {
|
||||
return UrlBuilder.fromBaseUrl(String.format(source.accessToken(), config.getCodingGroupName()))
|
||||
return UrlBuilder.fromBaseUrl(String.format(source.accessToken(), config.getDomainPrefix()))
|
||||
.queryParam("code", code)
|
||||
.queryParam("client_id", config.getClientId())
|
||||
.queryParam("client_secret", config.getClientSecret())
|
||||
@@ -119,7 +119,7 @@ public class AuthCodingRequest extends AuthDefaultRequest {
|
||||
*/
|
||||
@Override
|
||||
public String userInfoUrl(AuthToken authToken) {
|
||||
return UrlBuilder.fromBaseUrl(String.format(source.userInfo(), config.getCodingGroupName()))
|
||||
return UrlBuilder.fromBaseUrl(String.format(source.userInfo(), config.getDomainPrefix()))
|
||||
.queryParam("access_token", authToken.getAccessToken())
|
||||
.build();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
package me.zhyd.oauth.request;
|
||||
|
||||
import me.zhyd.oauth.cache.AuthStateCache;
|
||||
import me.zhyd.oauth.config.AuthConfig;
|
||||
import me.zhyd.oauth.config.AuthDefaultSource;
|
||||
|
||||
/**
|
||||
* 钉钉账号登录
|
||||
*
|
||||
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public class AuthDingTalkAccountRequest extends AbstractAuthDingtalkRequest {
|
||||
|
||||
public AuthDingTalkAccountRequest(AuthConfig config) {
|
||||
super(config, AuthDefaultSource.DINGTALK_ACCOUNT);
|
||||
}
|
||||
|
||||
public AuthDingTalkAccountRequest(AuthConfig config, AuthStateCache authStateCache) {
|
||||
super(config, AuthDefaultSource.DINGTALK_ACCOUNT, authStateCache);
|
||||
}
|
||||
}
|
||||
@@ -1,26 +1,16 @@
|
||||
package me.zhyd.oauth.request;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import me.zhyd.oauth.utils.HttpUtils;
|
||||
import me.zhyd.oauth.cache.AuthStateCache;
|
||||
import me.zhyd.oauth.config.AuthConfig;
|
||||
import me.zhyd.oauth.config.AuthDefaultSource;
|
||||
import me.zhyd.oauth.enums.AuthUserGender;
|
||||
import me.zhyd.oauth.exception.AuthException;
|
||||
import me.zhyd.oauth.model.AuthCallback;
|
||||
import me.zhyd.oauth.model.AuthToken;
|
||||
import me.zhyd.oauth.model.AuthUser;
|
||||
import me.zhyd.oauth.utils.GlobalAuthUtils;
|
||||
import me.zhyd.oauth.utils.UrlBuilder;
|
||||
|
||||
/**
|
||||
* 钉钉登录
|
||||
* 钉钉二维码登录
|
||||
*
|
||||
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public class AuthDingTalkRequest extends AuthDefaultRequest {
|
||||
public class AuthDingTalkRequest extends AbstractAuthDingtalkRequest {
|
||||
|
||||
public AuthDingTalkRequest(AuthConfig config) {
|
||||
super(config, AuthDefaultSource.DINGTALK);
|
||||
@@ -29,72 +19,4 @@ public class AuthDingTalkRequest extends AuthDefaultRequest {
|
||||
public AuthDingTalkRequest(AuthConfig config, AuthStateCache authStateCache) {
|
||||
super(config, AuthDefaultSource.DINGTALK, authStateCache);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AuthToken getAccessToken(AuthCallback authCallback) {
|
||||
return AuthToken.builder().accessCode(authCallback.getCode()).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AuthUser getUserInfo(AuthToken authToken) {
|
||||
String code = authToken.getAccessCode();
|
||||
JSONObject param = new JSONObject();
|
||||
param.put("tmp_auth_code", code);
|
||||
String response = new HttpUtils(config.getHttpConfig()).post(userInfoUrl(authToken), param.toJSONString());
|
||||
JSONObject object = JSON.parseObject(response);
|
||||
if (object.getIntValue("errcode") != 0) {
|
||||
throw new AuthException(object.getString("errmsg"));
|
||||
}
|
||||
object = object.getJSONObject("user_info");
|
||||
AuthToken token = AuthToken.builder()
|
||||
.openId(object.getString("openid"))
|
||||
.unionId(object.getString("unionid"))
|
||||
.build();
|
||||
return AuthUser.builder()
|
||||
.rawUserInfo(object)
|
||||
.uuid(object.getString("unionid"))
|
||||
.nickname(object.getString("nick"))
|
||||
.username(object.getString("nick"))
|
||||
.gender(AuthUserGender.UNKNOWN)
|
||||
.source(source.toString())
|
||||
.token(token)
|
||||
.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回带{@code state}参数的授权url,授权回调时会带上这个{@code state}
|
||||
*
|
||||
* @param state state 验证授权流程的参数,可以防止csrf
|
||||
* @return 返回授权地址
|
||||
* @since 1.9.3
|
||||
*/
|
||||
@Override
|
||||
public String authorize(String state) {
|
||||
return UrlBuilder.fromBaseUrl(source.authorize())
|
||||
.queryParam("response_type", "code")
|
||||
.queryParam("appid", config.getClientId())
|
||||
.queryParam("scope", "snsapi_login")
|
||||
.queryParam("redirect_uri", config.getRedirectUri())
|
||||
.queryParam("state", getRealState(state))
|
||||
.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回获取userInfo的url
|
||||
*
|
||||
* @param authToken 用户授权后的token
|
||||
* @return 返回获取userInfo的url
|
||||
*/
|
||||
@Override
|
||||
protected String userInfoUrl(AuthToken authToken) {
|
||||
// 根据timestamp, appSecret计算签名值
|
||||
String timestamp = System.currentTimeMillis() + "";
|
||||
String urlEncodeSignature = GlobalAuthUtils.generateDingTalkSignature(config.getClientSecret(), timestamp);
|
||||
|
||||
return UrlBuilder.fromBaseUrl(source.userInfo())
|
||||
.queryParam("signature", urlEncodeSignature)
|
||||
.queryParam("timestamp", timestamp)
|
||||
.queryParam("accessKey", config.getClientId())
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ public class AuthElemeRequest extends AuthDefaultRequest {
|
||||
|
||||
@Override
|
||||
protected AuthToken getAccessToken(AuthCallback authCallback) {
|
||||
Map<String, String> form = new HashMap<>(4);
|
||||
Map<String, String> form = new HashMap<>(7);
|
||||
form.put("client_id", config.getClientId());
|
||||
form.put("redirect_uri", config.getRedirectUri());
|
||||
form.put("code", authCallback.getCode());
|
||||
@@ -67,13 +67,13 @@ public class AuthElemeRequest extends AuthDefaultRequest {
|
||||
|
||||
@Override
|
||||
protected AuthUser getUserInfo(AuthToken authToken) {
|
||||
Map<String, Object> parameters = new HashMap<>();
|
||||
Map<String, Object> parameters = new HashMap<>(4);
|
||||
// 获取商户账号信息的API接口名称
|
||||
String action = "eleme.user.getUser";
|
||||
// 时间戳,单位秒。API服务端允许客户端请求最大时间误差为正负5分钟。
|
||||
final long timestamp = System.currentTimeMillis();
|
||||
// 公共参数
|
||||
Map<String, Object> metasHashMap = new HashMap<>();
|
||||
Map<String, Object> metasHashMap = new HashMap<>(4);
|
||||
metasHashMap.put("app_key", config.getClientId());
|
||||
metasHashMap.put("timestamp", timestamp);
|
||||
String signature = GlobalAuthUtils.generateElemeSignature(config.getClientId(), config.getClientSecret(), timestamp, action, authToken
|
||||
@@ -118,7 +118,7 @@ public class AuthElemeRequest extends AuthDefaultRequest {
|
||||
|
||||
@Override
|
||||
public AuthResponse refresh(AuthToken oldToken) {
|
||||
Map<String, String> form = new HashMap<>(2);
|
||||
Map<String, String> form = new HashMap<>(4);
|
||||
form.put("refresh_token", oldToken.getRefreshToken());
|
||||
form.put("grant_type", "refresh_token");
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ public class AuthHuaweiRequest extends AuthDefaultRequest {
|
||||
*/
|
||||
@Override
|
||||
protected AuthToken getAccessToken(AuthCallback authCallback) {
|
||||
Map<String, String> form = new HashMap<>(5);
|
||||
Map<String, String> form = new HashMap<>(8);
|
||||
form.put("grant_type", "authorization_code");
|
||||
form.put("code", authCallback.getAuthorization_code());
|
||||
form.put("client_id", config.getClientId());
|
||||
@@ -67,7 +67,7 @@ public class AuthHuaweiRequest extends AuthDefaultRequest {
|
||||
*/
|
||||
@Override
|
||||
protected AuthUser getUserInfo(AuthToken authToken) {
|
||||
Map<String, String> form = new HashMap<>(4);
|
||||
Map<String, String> form = new HashMap<>(7);
|
||||
form.put("nsp_ts", System.currentTimeMillis() + "");
|
||||
form.put("access_token", authToken.getAccessToken());
|
||||
form.put("nsp_fmt", "JS");
|
||||
@@ -100,7 +100,7 @@ public class AuthHuaweiRequest extends AuthDefaultRequest {
|
||||
*/
|
||||
@Override
|
||||
public AuthResponse refresh(AuthToken authToken) {
|
||||
Map<String, String> form = new HashMap<>(4);
|
||||
Map<String, String> form = new HashMap<>(7);
|
||||
form.put("client_id", config.getClientId());
|
||||
form.put("client_secret", config.getClientSecret());
|
||||
form.put("refresh_token", authToken.getRefreshToken());
|
||||
|
||||
@@ -41,7 +41,7 @@ public class AuthJdRequest extends AuthDefaultRequest {
|
||||
@Override
|
||||
protected AuthToken getAccessToken(AuthCallback authCallback) {
|
||||
|
||||
Map<String, String> params = new HashMap<>(5);
|
||||
Map<String, String> params = new HashMap<>(7);
|
||||
params.put("app_key", config.getClientId());
|
||||
params.put("app_secret", config.getClientSecret());
|
||||
params.put("grant_type", "authorization_code");
|
||||
@@ -104,7 +104,7 @@ public class AuthJdRequest extends AuthDefaultRequest {
|
||||
|
||||
@Override
|
||||
public AuthResponse refresh(AuthToken oldToken) {
|
||||
Map<String, String> params = new HashMap<>(5);
|
||||
Map<String, String> params = new HashMap<>(7);
|
||||
params.put("app_key", config.getClientId());
|
||||
params.put("app_secret", config.getClientSecret());
|
||||
params.put("grant_type", "refresh_token");
|
||||
|
||||
@@ -0,0 +1,116 @@
|
||||
package me.zhyd.oauth.request;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.xkcoding.http.support.HttpHeader;
|
||||
import me.zhyd.oauth.cache.AuthStateCache;
|
||||
import me.zhyd.oauth.config.AuthConfig;
|
||||
import me.zhyd.oauth.config.AuthDefaultSource;
|
||||
import me.zhyd.oauth.enums.AuthResponseStatus;
|
||||
import me.zhyd.oauth.enums.AuthUserGender;
|
||||
import me.zhyd.oauth.enums.scope.AuthLineScope;
|
||||
import me.zhyd.oauth.model.AuthCallback;
|
||||
import me.zhyd.oauth.model.AuthResponse;
|
||||
import me.zhyd.oauth.model.AuthToken;
|
||||
import me.zhyd.oauth.model.AuthUser;
|
||||
import me.zhyd.oauth.utils.AuthScopeUtils;
|
||||
import me.zhyd.oauth.utils.HttpUtils;
|
||||
import me.zhyd.oauth.utils.UrlBuilder;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* LINE 登录, line.biz
|
||||
*
|
||||
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
|
||||
* @since 1.16.0
|
||||
*/
|
||||
public class AuthLineRequest extends AuthDefaultRequest {
|
||||
|
||||
public AuthLineRequest(AuthConfig config) {
|
||||
super(config, AuthDefaultSource.LINE);
|
||||
}
|
||||
|
||||
public AuthLineRequest(AuthConfig config, AuthStateCache authStateCache) {
|
||||
super(config, AuthDefaultSource.LINE, authStateCache);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AuthToken getAccessToken(AuthCallback authCallback) {
|
||||
return this.getToken(accessTokenUrl(authCallback.getCode()));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AuthUser getUserInfo(AuthToken authToken) {
|
||||
String userInfo = new HttpUtils(config.getHttpConfig()).get(source.userInfo(), null, new HttpHeader()
|
||||
.add("Content-Type", "application/x-www-form-urlencoded")
|
||||
.add("Authorization", "Bearer ".concat(authToken.getAccessToken())), false);
|
||||
JSONObject object = JSONObject.parseObject(userInfo);
|
||||
return AuthUser.builder()
|
||||
.rawUserInfo(object)
|
||||
.uuid(object.getString("userId"))
|
||||
.username(object.getString("displayName"))
|
||||
.nickname(object.getString("displayName"))
|
||||
.avatar(object.getString("pictureUrl"))
|
||||
.remark(object.getString("statusMessage"))
|
||||
.gender(AuthUserGender.UNKNOWN)
|
||||
.token(authToken)
|
||||
.source(source.toString())
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public AuthResponse revoke(AuthToken authToken) {
|
||||
Map<String, String> params = new HashMap<>(5);
|
||||
params.put("access_token", authToken.getAccessToken());
|
||||
params.put("client_id", config.getClientId());
|
||||
params.put("client_secret", config.getClientSecret());
|
||||
String userInfo = new HttpUtils(config.getHttpConfig()).post(source.revoke(), params, false);
|
||||
JSONObject object = JSONObject.parseObject(userInfo);
|
||||
// 返回1表示取消授权成功,否则失败
|
||||
AuthResponseStatus status = object.getBooleanValue("revoked") ? AuthResponseStatus.SUCCESS : AuthResponseStatus.FAILURE;
|
||||
return AuthResponse.builder().code(status.getCode()).msg(status.getMsg()).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public AuthResponse refresh(AuthToken oldToken) {
|
||||
return AuthResponse.builder()
|
||||
.code(AuthResponseStatus.SUCCESS.getCode())
|
||||
.data(this.getToken(refreshTokenUrl(oldToken.getRefreshToken())))
|
||||
.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取token,适用于获取access_token和刷新token
|
||||
*
|
||||
* @param accessTokenUrl 实际请求token的地址
|
||||
* @return token对象
|
||||
*/
|
||||
private AuthToken getToken(String accessTokenUrl) {
|
||||
String response = new HttpUtils(config.getHttpConfig()).post(accessTokenUrl);
|
||||
JSONObject accessTokenObject = JSONObject.parseObject(response);
|
||||
return AuthToken.builder()
|
||||
.accessToken(accessTokenObject.getString("access_token"))
|
||||
.refreshToken(accessTokenObject.getString("refresh_token"))
|
||||
.expireIn(accessTokenObject.getIntValue("expires_in"))
|
||||
.idToken(accessTokenObject.getString("id_token"))
|
||||
.scope(accessTokenObject.getString("scope"))
|
||||
.tokenType(accessTokenObject.getString("token_type"))
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String userInfoUrl(AuthToken authToken) {
|
||||
return UrlBuilder.fromBaseUrl(source.userInfo())
|
||||
.queryParam("user", authToken.getUid())
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String authorize(String state) {
|
||||
return UrlBuilder.fromBaseUrl(super.authorize(state))
|
||||
.queryParam("nonce", state)
|
||||
.queryParam("scope", this.getScopes(" ", true, AuthScopeUtils.getDefaultScopes(AuthLineScope.values())))
|
||||
.build();
|
||||
}
|
||||
}
|
||||
@@ -35,7 +35,7 @@ public class AuthMeituanRequest extends AuthDefaultRequest {
|
||||
|
||||
@Override
|
||||
protected AuthToken getAccessToken(AuthCallback authCallback) {
|
||||
Map<String, String> form = new HashMap<>(4);
|
||||
Map<String, String> form = new HashMap<>(7);
|
||||
form.put("app_id", config.getClientId());
|
||||
form.put("secret", config.getClientSecret());
|
||||
form.put("code", authCallback.getCode());
|
||||
@@ -55,7 +55,7 @@ public class AuthMeituanRequest extends AuthDefaultRequest {
|
||||
|
||||
@Override
|
||||
protected AuthUser getUserInfo(AuthToken authToken) {
|
||||
Map<String, String> form = new HashMap<>(3);
|
||||
Map<String, String> form = new HashMap<>(5);
|
||||
form.put("app_id", config.getClientId());
|
||||
form.put("secret", config.getClientSecret());
|
||||
form.put("access_token", authToken.getAccessToken());
|
||||
@@ -79,7 +79,7 @@ public class AuthMeituanRequest extends AuthDefaultRequest {
|
||||
|
||||
@Override
|
||||
public AuthResponse refresh(AuthToken oldToken) {
|
||||
Map<String, String> form = new HashMap<>(4);
|
||||
Map<String, String> form = new HashMap<>(7);
|
||||
form.put("app_id", config.getClientId());
|
||||
form.put("secret", config.getClientSecret());
|
||||
form.put("refresh_token", oldToken.getRefreshToken());
|
||||
|
||||
@@ -0,0 +1,159 @@
|
||||
package me.zhyd.oauth.request;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.xkcoding.http.support.HttpHeader;
|
||||
import me.zhyd.oauth.cache.AuthStateCache;
|
||||
import me.zhyd.oauth.config.AuthConfig;
|
||||
import me.zhyd.oauth.config.AuthDefaultSource;
|
||||
import me.zhyd.oauth.enums.AuthResponseStatus;
|
||||
import me.zhyd.oauth.enums.AuthUserGender;
|
||||
import me.zhyd.oauth.enums.scope.AuthOktaScope;
|
||||
import me.zhyd.oauth.exception.AuthException;
|
||||
import me.zhyd.oauth.model.AuthCallback;
|
||||
import me.zhyd.oauth.model.AuthResponse;
|
||||
import me.zhyd.oauth.model.AuthToken;
|
||||
import me.zhyd.oauth.model.AuthUser;
|
||||
import me.zhyd.oauth.utils.AuthScopeUtils;
|
||||
import me.zhyd.oauth.utils.Base64Utils;
|
||||
import me.zhyd.oauth.utils.HttpUtils;
|
||||
import me.zhyd.oauth.utils.UrlBuilder;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Okta 登录
|
||||
* <p>
|
||||
* https://{domainPrefix}.okta.com/oauth2/default/.well-known/oauth-authorization-server
|
||||
*
|
||||
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
|
||||
* @since 1.16.0
|
||||
*/
|
||||
public class AuthOktaRequest extends AuthDefaultRequest {
|
||||
|
||||
public AuthOktaRequest(AuthConfig config) {
|
||||
super(config, AuthDefaultSource.OKTA);
|
||||
}
|
||||
|
||||
public AuthOktaRequest(AuthConfig config, AuthStateCache authStateCache) {
|
||||
super(config, AuthDefaultSource.OKTA, authStateCache);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AuthToken getAccessToken(AuthCallback authCallback) {
|
||||
String tokenUrl = accessTokenUrl(authCallback.getCode());
|
||||
return getAuthToken(tokenUrl);
|
||||
}
|
||||
|
||||
private AuthToken getAuthToken(String tokenUrl) {
|
||||
HttpHeader header = new HttpHeader()
|
||||
.add("accept", "application/json")
|
||||
.add("content-type", "application/x-www-form-urlencoded")
|
||||
.add("Authorization", "Basic " + Base64Utils.encode(config.getClientId().concat(":").concat(config.getClientSecret())));
|
||||
String response = new HttpUtils(config.getHttpConfig()).post(tokenUrl, null, header, false);
|
||||
JSONObject accessTokenObject = JSONObject.parseObject(response);
|
||||
this.checkResponse(accessTokenObject);
|
||||
return AuthToken.builder()
|
||||
.accessToken(accessTokenObject.getString("access_token"))
|
||||
.tokenType(accessTokenObject.getString("token_type"))
|
||||
.expireIn(accessTokenObject.getIntValue("expires_in"))
|
||||
.scope(accessTokenObject.getString("scope"))
|
||||
.refreshToken(accessTokenObject.getString("refresh_token"))
|
||||
.idToken(accessTokenObject.getString("id_token"))
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public AuthResponse refresh(AuthToken authToken) {
|
||||
if (null == authToken.getRefreshToken()) {
|
||||
return AuthResponse.builder()
|
||||
.code(AuthResponseStatus.ILLEGAL_TOKEN.getCode())
|
||||
.msg(AuthResponseStatus.ILLEGAL_TOKEN.getMsg())
|
||||
.build();
|
||||
}
|
||||
String refreshUrl = refreshTokenUrl(authToken.getRefreshToken());
|
||||
return AuthResponse.builder()
|
||||
.code(AuthResponseStatus.SUCCESS.getCode())
|
||||
.data(this.getAuthToken(refreshUrl))
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AuthUser getUserInfo(AuthToken authToken) {
|
||||
HttpHeader header = new HttpHeader()
|
||||
.add("Authorization", "Bearer " + authToken.getAccessToken());
|
||||
String response = new HttpUtils(config.getHttpConfig()).post(userInfoUrl(authToken), null, header, false);
|
||||
JSONObject object = JSONObject.parseObject(response);
|
||||
this.checkResponse(object);
|
||||
JSONObject address = object.getJSONObject("address");
|
||||
return AuthUser.builder()
|
||||
.rawUserInfo(object)
|
||||
.uuid(object.getString("sub"))
|
||||
.username(object.getString("name"))
|
||||
.nickname(object.getString("nickname"))
|
||||
.email(object.getString("email"))
|
||||
.location(null == address ? null : address.getString("street_address"))
|
||||
.gender(AuthUserGender.getRealGender(object.getString("sex")))
|
||||
.token(authToken)
|
||||
.source(source.toString())
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public AuthResponse revoke(AuthToken authToken) {
|
||||
Map<String, String> params = new HashMap<>(4);
|
||||
params.put("token", authToken.getAccessToken());
|
||||
params.put("token_type_hint", "access_token");
|
||||
|
||||
HttpHeader header = new HttpHeader()
|
||||
.add("Authorization", "Basic " + Base64Utils.encode(config.getClientId().concat(":").concat(config.getClientSecret())));
|
||||
new HttpUtils(config.getHttpConfig()).post(revokeUrl(authToken), params, header, false);
|
||||
AuthResponseStatus status = AuthResponseStatus.SUCCESS;
|
||||
return AuthResponse.builder().code(status.getCode()).msg(status.getMsg()).build();
|
||||
}
|
||||
|
||||
private void checkResponse(JSONObject object) {
|
||||
if (object.containsKey("error")) {
|
||||
throw new AuthException(object.getString("error_description"));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String authorize(String state) {
|
||||
return UrlBuilder.fromBaseUrl(String.format(source.authorize(), config.getDomainPrefix(), config.getAuthServerId()))
|
||||
.queryParam("response_type", "code")
|
||||
.queryParam("prompt", "consent")
|
||||
.queryParam("client_id", config.getClientId())
|
||||
.queryParam("redirect_uri", config.getRedirectUri())
|
||||
.queryParam("scope", this.getScopes(" ", true, AuthScopeUtils.getDefaultScopes(AuthOktaScope.values())))
|
||||
.queryParam("state", getRealState(state))
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String accessTokenUrl(String code) {
|
||||
return UrlBuilder.fromBaseUrl(String.format(source.accessToken(), config.getDomainPrefix(), config.getAuthServerId()))
|
||||
.queryParam("code", code)
|
||||
.queryParam("grant_type", "authorization_code")
|
||||
.queryParam("redirect_uri", config.getRedirectUri())
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String refreshTokenUrl(String refreshToken) {
|
||||
return UrlBuilder.fromBaseUrl(String.format(source.refresh(), config.getDomainPrefix(), config.getAuthServerId()))
|
||||
.queryParam("refresh_token", refreshToken)
|
||||
.queryParam("grant_type", "refresh_token")
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String revokeUrl(AuthToken authToken) {
|
||||
return String.format(source.revoke(), config.getDomainPrefix(), config.getAuthServerId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String userInfoUrl(AuthToken authToken) {
|
||||
return String.format(source.userInfo(), config.getDomainPrefix(), config.getAuthServerId());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,139 @@
|
||||
package me.zhyd.oauth.request;
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.xkcoding.http.support.HttpHeader;
|
||||
import me.zhyd.oauth.cache.AuthStateCache;
|
||||
import me.zhyd.oauth.config.AuthConfig;
|
||||
import me.zhyd.oauth.config.AuthDefaultSource;
|
||||
import me.zhyd.oauth.enums.AuthResponseStatus;
|
||||
import me.zhyd.oauth.enums.AuthUserGender;
|
||||
import me.zhyd.oauth.enums.scope.AuthSlackScope;
|
||||
import me.zhyd.oauth.exception.AuthException;
|
||||
import me.zhyd.oauth.model.AuthCallback;
|
||||
import me.zhyd.oauth.model.AuthResponse;
|
||||
import me.zhyd.oauth.model.AuthToken;
|
||||
import me.zhyd.oauth.model.AuthUser;
|
||||
import me.zhyd.oauth.utils.AuthScopeUtils;
|
||||
import me.zhyd.oauth.utils.HttpUtils;
|
||||
import me.zhyd.oauth.utils.UrlBuilder;
|
||||
|
||||
/**
|
||||
* slack登录, slack.com
|
||||
*
|
||||
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
|
||||
* @since 1.16.0
|
||||
*/
|
||||
public class AuthSlackRequest extends AuthDefaultRequest {
|
||||
|
||||
public AuthSlackRequest(AuthConfig config) {
|
||||
super(config, AuthDefaultSource.SLACK);
|
||||
}
|
||||
|
||||
public AuthSlackRequest(AuthConfig config, AuthStateCache authStateCache) {
|
||||
super(config, AuthDefaultSource.SLACK, authStateCache);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AuthToken getAccessToken(AuthCallback authCallback) {
|
||||
HttpHeader header = new HttpHeader()
|
||||
.add("Content-Type", "application/x-www-form-urlencoded");
|
||||
String response = new HttpUtils(config.getHttpConfig()).get(accessTokenUrl(authCallback.getCode()), null, header, false);
|
||||
JSONObject accessTokenObject = JSONObject.parseObject(response);
|
||||
this.checkResponse(accessTokenObject);
|
||||
return AuthToken.builder()
|
||||
.accessToken(accessTokenObject.getString("access_token"))
|
||||
.scope(accessTokenObject.getString("scope"))
|
||||
.tokenType(accessTokenObject.getString("token_type"))
|
||||
.uid(accessTokenObject.getJSONObject("authed_user").getString("id"))
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AuthUser getUserInfo(AuthToken authToken) {
|
||||
HttpHeader header = new HttpHeader()
|
||||
.add("Content-Type", "application/x-www-form-urlencoded")
|
||||
.add("Authorization", "Bearer ".concat(authToken.getAccessToken()));
|
||||
String userInfo = new HttpUtils(config.getHttpConfig()).get(userInfoUrl(authToken), null, header, false);
|
||||
JSONObject object = JSONObject.parseObject(userInfo);
|
||||
this.checkResponse(object);
|
||||
JSONObject user = object.getJSONObject("user");
|
||||
JSONObject profile = user.getJSONObject("profile");
|
||||
return AuthUser.builder()
|
||||
.rawUserInfo(user)
|
||||
.uuid(user.getString("id"))
|
||||
.username(user.getString("name"))
|
||||
.nickname(user.getString("real_name"))
|
||||
.avatar(profile.getString("image_original"))
|
||||
.email(profile.getString("email"))
|
||||
.gender(AuthUserGender.UNKNOWN)
|
||||
.token(authToken)
|
||||
.source(source.toString())
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public AuthResponse revoke(AuthToken authToken) {
|
||||
HttpHeader header = new HttpHeader()
|
||||
.add("Content-Type", "application/x-www-form-urlencoded")
|
||||
.add("Authorization", "Bearer ".concat(authToken.getAccessToken()));
|
||||
String userInfo = new HttpUtils(config.getHttpConfig()).get(source.revoke(), null, header, false);
|
||||
JSONObject object = JSONObject.parseObject(userInfo);
|
||||
this.checkResponse(object);
|
||||
// 返回1表示取消授权成功,否则失败
|
||||
AuthResponseStatus status = object.getBooleanValue("revoked") ? AuthResponseStatus.SUCCESS : AuthResponseStatus.FAILURE;
|
||||
return AuthResponse.builder().code(status.getCode()).msg(status.getMsg()).build();
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查响应内容是否正确
|
||||
*
|
||||
* @param object 请求响应内容
|
||||
*/
|
||||
private void checkResponse(JSONObject object) {
|
||||
if (!object.getBooleanValue("ok")) {
|
||||
String errorMsg = object.getString("error");
|
||||
if (object.containsKey("response_metadata")) {
|
||||
JSONArray array = object.getJSONObject("response_metadata").getJSONArray("messages");
|
||||
if (null != array && array.size() > 0) {
|
||||
errorMsg += "; " + String.join(",", array.toArray(new String[0]));
|
||||
}
|
||||
}
|
||||
|
||||
throw new AuthException(errorMsg);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String userInfoUrl(AuthToken authToken) {
|
||||
return UrlBuilder.fromBaseUrl(source.userInfo())
|
||||
.queryParam("user", authToken.getUid())
|
||||
.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回带{@code state}参数的授权url,授权回调时会带上这个{@code state}
|
||||
*
|
||||
* @param state state 验证授权流程的参数,可以防止csrf
|
||||
* @return 返回授权地址
|
||||
*/
|
||||
@Override
|
||||
public String authorize(String state) {
|
||||
return UrlBuilder.fromBaseUrl(source.authorize())
|
||||
.queryParam("client_id", config.getClientId())
|
||||
.queryParam("state", getRealState(state))
|
||||
.queryParam("redirect_uri", config.getRedirectUri())
|
||||
.queryParam("scope", this.getScopes(",", true, AuthScopeUtils.getDefaultScopes(AuthSlackScope.values())))
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String accessTokenUrl(String code) {
|
||||
return UrlBuilder.fromBaseUrl(source.accessToken())
|
||||
.queryParam("code", code)
|
||||
.queryParam("client_id", config.getClientId())
|
||||
.queryParam("client_secret", config.getClientSecret())
|
||||
.queryParam("redirect_uri", config.getRedirectUri())
|
||||
.build();
|
||||
}
|
||||
}
|
||||
@@ -39,7 +39,7 @@ public class AuthTeambitionRequest extends AuthDefaultRequest {
|
||||
*/
|
||||
@Override
|
||||
protected AuthToken getAccessToken(AuthCallback authCallback) {
|
||||
Map<String, String> form = new HashMap<>(4);
|
||||
Map<String, String> form = new HashMap<>(7);
|
||||
form.put("client_id", config.getClientId());
|
||||
form.put("client_secret", config.getClientSecret());
|
||||
form.put("code", authCallback.getCode());
|
||||
@@ -90,7 +90,7 @@ public class AuthTeambitionRequest extends AuthDefaultRequest {
|
||||
String uid = oldToken.getUid();
|
||||
String refreshToken = oldToken.getRefreshToken();
|
||||
|
||||
Map<String, String> form = new HashMap<>(2);
|
||||
Map<String, String> form = new HashMap<>(4);
|
||||
form.put("_userId", uid);
|
||||
form.put("refresh_token", refreshToken);
|
||||
String response = new HttpUtils(config.getHttpConfig()).post(source.refresh(), form, false);
|
||||
|
||||
@@ -102,7 +102,7 @@ public class AuthTwitterRequest extends AuthDefaultRequest {
|
||||
httpHeader.add("Authorization", header);
|
||||
httpHeader.add(Constants.CONTENT_TYPE, "application/x-www-form-urlencoded");
|
||||
|
||||
Map<String, String> form = new HashMap<>(1);
|
||||
Map<String, String> form = new HashMap<>(3);
|
||||
form.put("oauth_verifier", authCallback.getOauth_verifier());
|
||||
String response = new HttpUtils(config.getHttpConfig()).post(source.accessToken(), form, httpHeader, false);
|
||||
|
||||
@@ -118,7 +118,7 @@ public class AuthTwitterRequest extends AuthDefaultRequest {
|
||||
|
||||
@Override
|
||||
protected AuthUser getUserInfo(AuthToken authToken) {
|
||||
Map<String, String> queryParams = new HashMap<>();
|
||||
Map<String, String> queryParams = new HashMap<>(5);
|
||||
queryParams.put("user_id", authToken.getUserId());
|
||||
queryParams.put("screen_name", authToken.getScreenName());
|
||||
queryParams.put("include_entities", Boolean.toString(true));
|
||||
@@ -162,7 +162,7 @@ public class AuthTwitterRequest extends AuthDefaultRequest {
|
||||
}
|
||||
|
||||
private Map<String, String> buildOauthParams() {
|
||||
Map<String, String> params = new HashMap<>(5);
|
||||
Map<String, String> params = new HashMap<>(12);
|
||||
params.put("oauth_consumer_key", config.getClientId());
|
||||
params.put("oauth_nonce", GlobalAuthUtils.generateNonce(32));
|
||||
params.put("oauth_signature_method", "HMAC-SHA1");
|
||||
|
||||
@@ -43,7 +43,7 @@ public class AuthXmlyRequest extends AuthDefaultRequest {
|
||||
*/
|
||||
@Override
|
||||
protected AuthToken getAccessToken(AuthCallback authCallback) {
|
||||
Map<String, String> map = new HashMap<>(6);
|
||||
Map<String, String> map = new HashMap<>(9);
|
||||
map.put("code", authCallback.getCode());
|
||||
map.put("client_id", config.getClientId());
|
||||
map.put("client_secret", config.getClientSecret());
|
||||
|
||||
@@ -35,8 +35,8 @@ public class AuthChecker {
|
||||
if (isSupported && AuthDefaultSource.WECHAT_ENTERPRISE == source) {
|
||||
isSupported = StringUtils.isNotEmpty(config.getAgentId());
|
||||
}
|
||||
if (isSupported && AuthDefaultSource.CODING == source) {
|
||||
isSupported = StringUtils.isNotEmpty(config.getCodingGroupName());
|
||||
if (isSupported && (AuthDefaultSource.CODING == source || AuthDefaultSource.OKTA == source)) {
|
||||
isSupported = StringUtils.isNotEmpty(config.getDomainPrefix());
|
||||
}
|
||||
if (isSupported && AuthDefaultSource.XMLY == source) {
|
||||
isSupported = StringUtils.isNotEmpty(config.getDeviceId()) && null != config.getClientOsType();
|
||||
|
||||
@@ -101,15 +101,18 @@ public class GlobalAuthUtils {
|
||||
* @return map
|
||||
*/
|
||||
public static Map<String, String> parseStringToMap(String accessTokenStr) {
|
||||
Map<String, String> res = new HashMap<>(6);
|
||||
Map<String, String> res = null;
|
||||
if (accessTokenStr.contains("&")) {
|
||||
String[] fields = accessTokenStr.split("&");
|
||||
res = new HashMap<>((int) (fields.length / 0.75 + 1));
|
||||
for (String field : fields) {
|
||||
if (field.contains("=")) {
|
||||
String[] keyValue = field.split("=");
|
||||
res.put(GlobalAuthUtils.urlDecode(keyValue[0]), keyValue.length == 2 ? GlobalAuthUtils.urlDecode(keyValue[1]) : null);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
res = new HashMap<>(0);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
package me.zhyd.oauth.utils;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
/**
|
||||
* 该配置仅用于支持 PKCE 模式的平台,针对无服务应用,不推荐使用隐式授权,推荐使用 PKCE 模式
|
||||
*
|
||||
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
|
||||
* @version 1.0.0
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public class PkceUtil {
|
||||
|
||||
public static String generateCodeVerifier() {
|
||||
String randomStr = RandomUtil.randomString(50);
|
||||
return Base64Utils.encodeUrlSafe(randomStr);
|
||||
}
|
||||
|
||||
/**
|
||||
* 适用于 OAuth 2.0 PKCE 增强协议
|
||||
*
|
||||
* @param codeChallengeMethod s256 / plain
|
||||
* @param codeVerifier 客户端生产的校验码
|
||||
* @return code challenge
|
||||
*/
|
||||
public static String generateCodeChallenge(String codeChallengeMethod, String codeVerifier) {
|
||||
if ("S256".equalsIgnoreCase(codeChallengeMethod)) {
|
||||
// https://tools.ietf.org/html/rfc7636#section-4.2
|
||||
// code_challenge = BASE64URL-ENCODE(SHA256(ASCII(code_verifier)))
|
||||
return newStringUsAscii(Base64Utils.encodeUrlSafe(Sha256.digest(codeVerifier), true));
|
||||
} else {
|
||||
return codeVerifier;
|
||||
}
|
||||
}
|
||||
|
||||
public static String newStringUsAscii(byte[] bytes) {
|
||||
return new String(bytes, StandardCharsets.US_ASCII);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package me.zhyd.oauth.utils;
|
||||
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
/**
|
||||
* 生成随机字符串
|
||||
*
|
||||
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
|
||||
* @version 1.0.0
|
||||
* @since 1.16.0
|
||||
*/
|
||||
public class RandomUtil {
|
||||
|
||||
/**
|
||||
* 用于随机选的字符和数字
|
||||
*/
|
||||
public static final String BASE_CHAR_NUMBER = "abcdefghijklmnopqrstuvwxyz0123456789";
|
||||
|
||||
/**
|
||||
* 获得一个随机的字符串
|
||||
*
|
||||
* @param length 字符串的长度
|
||||
* @return 指定长度的随机字符串
|
||||
*/
|
||||
public static String randomString(int length) {
|
||||
final StringBuilder sb = new StringBuilder(length);
|
||||
|
||||
if (length < 1) {
|
||||
length = 1;
|
||||
}
|
||||
int baseLength = BASE_CHAR_NUMBER.length();
|
||||
for (int i = 0; i < length; i++) {
|
||||
int number = ThreadLocalRandom.current().nextInt(baseLength);
|
||||
sb.append(BASE_CHAR_NUMBER.charAt(number));
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package me.zhyd.oauth.utils;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
|
||||
/**
|
||||
* SHA256 加密
|
||||
*
|
||||
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
|
||||
* @version 1.0.0
|
||||
* @since 1.16.0
|
||||
*/
|
||||
public class Sha256 {
|
||||
|
||||
public static byte[] digest(String str) {
|
||||
MessageDigest messageDigest;
|
||||
try {
|
||||
messageDigest = MessageDigest.getInstance("SHA-256");
|
||||
messageDigest.update(str.getBytes(StandardCharsets.UTF_8));
|
||||
return messageDigest.digest();
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user