diff --git a/.gitee/PULL_REQUEST_TEMPLATE.zh-CN.md b/.gitee/PULL_REQUEST_TEMPLATE.zh-CN.md index 55b740b56ad88c291c99e42ad4bc4f028b34638c..9077e2240c40d4445b07132e5c255e0ca4aa1076 100644 --- a/.gitee/PULL_REQUEST_TEMPLATE.zh-CN.md +++ b/.gitee/PULL_REQUEST_TEMPLATE.zh-CN.md @@ -18,9 +18,12 @@ - [ ] 否,还没做测试,需要作者自测 注:测试demo可以使用: -- [Springboot版](https://github.com/justauth/JustAuth-demo) +- [simple版](https://github.com/justauth/JustAuth-demo) - [jFinal版](https://github.com/xkcoding/jfinal-justauth-demo) - [ActFramework版](https://github.com/xkcoding/act-justauth-demo) +- [Nutzboot版](https://github.com/EggsBlue/nutzboot-justauth-demo) +- [Blade版](https://github.com/justauth/blade-justauth-demo) + diff --git a/README.en-US.md b/README.en-US.md index bb037cd6f4870ce40f235a84491b6cac515fcb3e..b0ca4c3c917b645bfc992ced734976a15332f560 100644 --- a/README.en-US.md +++ b/README.en-US.md @@ -6,7 +6,7 @@
- + @@ -15,7 +15,7 @@ - + @@ -68,8 +68,14 @@
+ |
- + @@ -15,7 +15,7 @@ - + @@ -68,6 +68,12 @@
-
+
@@ -18,7 +18,7 @@
-
+
@@ -91,6 +91,7 @@ JustAuth,如你所见,它仅仅是一个**第三方授权登录**的**工具
| | [AuthGitlabRequest](https://gitee.com/yadong.zhang/JustAuth/blob/master/src/main/java/me/zhyd/oauth/request/AuthGitlabRequest.java) | 参考文档 |
| | [AuthMeituanRequest](https://gitee.com/yadong.zhang/JustAuth/blob/master/src/main/java/me/zhyd/oauth/request/AuthMeituanRequest.java) | 参考文档 |
| | [AuthElemeRequest](https://gitee.com/yadong.zhang/JustAuth/blob/master/src/main/java/me/zhyd/oauth/request/AuthElemeRequest.java) | 参考文档 |
+| | [AuthTwitterRequest](https://gitee.com/yadong.zhang/JustAuth/blob/master/src/main/java/me/zhyd/oauth/request/AuthTwitterRequest.java) | 参考文档 |
| | [AuthCsdnRequest](https://gitee.com/yadong.zhang/JustAuth/blob/master/src/main/java/me/zhyd/oauth/request/AuthCsdnRequest.java) | 无 |
diff --git a/docs/_coverpage.md b/docs/_coverpage.md
index d3f43875d4f056650f2fa2502d9c46b2d3e469b6..372bb568acc0c4dd0285de3e854cd80464bdb2f2 100644
--- a/docs/_coverpage.md
+++ b/docs/_coverpage.md
@@ -1,6 +1,6 @@
![](_media/logo.png)
-# JustAuth 1.12.0
+# JustAuth 1.13.0
史上最全的整合第三方登录的开源库
diff --git a/docs/_media/custom/gitlab.png b/docs/_media/custom/gitlab.png
new file mode 100644
index 0000000000000000000000000000000000000000..567f6fcd0850cf2ca54bc127b050d410b2699b25
Binary files /dev/null and b/docs/_media/custom/gitlab.png differ
diff --git a/docs/_media/custom/gitlab2.png b/docs/_media/custom/gitlab2.png
new file mode 100644
index 0000000000000000000000000000000000000000..26b904d13493196a9f345487339989f56b20e823
Binary files /dev/null and b/docs/_media/custom/gitlab2.png differ
diff --git a/docs/_media/custom/gitlab3.png b/docs/_media/custom/gitlab3.png
new file mode 100644
index 0000000000000000000000000000000000000000..679930a2a1394ba5e40830bc1cc064794699dfe0
Binary files /dev/null and b/docs/_media/custom/gitlab3.png differ
diff --git a/docs/_media/custom/gitlab4.png b/docs/_media/custom/gitlab4.png
new file mode 100644
index 0000000000000000000000000000000000000000..4049d38efe3829f820e9b7f189edc3a5e452c2c0
Binary files /dev/null and b/docs/_media/custom/gitlab4.png differ
diff --git a/docs/_media/oauth/gitee_01.png b/docs/_media/oauth/gitee_01.png
new file mode 100644
index 0000000000000000000000000000000000000000..3c8d6edd6b6fec39a2b4fa684d355ac961dcf05e
Binary files /dev/null and b/docs/_media/oauth/gitee_01.png differ
diff --git a/docs/_media/oauth/gitee_02.png b/docs/_media/oauth/gitee_02.png
new file mode 100644
index 0000000000000000000000000000000000000000..03e6778adc4075aa37988a85c668c9f68d072f0b
Binary files /dev/null and b/docs/_media/oauth/gitee_02.png differ
diff --git a/docs/_media/oauth/gitee_03.png b/docs/_media/oauth/gitee_03.png
new file mode 100644
index 0000000000000000000000000000000000000000..6987ab9a22c394a19bdaaf900c409e37fcd6844c
Binary files /dev/null and b/docs/_media/oauth/gitee_03.png differ
diff --git a/docs/_media/oauth/gitee_04.png b/docs/_media/oauth/gitee_04.png
new file mode 100644
index 0000000000000000000000000000000000000000..4d1e91eaecb1b46ae816db5a83b6e87eee816025
Binary files /dev/null and b/docs/_media/oauth/gitee_04.png differ
diff --git a/docs/_media/oauth/github_01.png b/docs/_media/oauth/github_01.png
new file mode 100644
index 0000000000000000000000000000000000000000..d664cfca253ff52c2a090162bf1f1d974bcf201f
Binary files /dev/null and b/docs/_media/oauth/github_01.png differ
diff --git a/docs/_media/oauth/github_02.png b/docs/_media/oauth/github_02.png
new file mode 100644
index 0000000000000000000000000000000000000000..8514bbd99082869a55edad8672331fd2f3d4f824
Binary files /dev/null and b/docs/_media/oauth/github_02.png differ
diff --git a/docs/_media/oauth/github_03.png b/docs/_media/oauth/github_03.png
new file mode 100644
index 0000000000000000000000000000000000000000..1bdc1ec02dba01670036526eea01dfefd1a5923f
Binary files /dev/null and b/docs/_media/oauth/github_03.png differ
diff --git a/docs/_media/oauth/github_04.png b/docs/_media/oauth/github_04.png
new file mode 100644
index 0000000000000000000000000000000000000000..14548fb3c65fc909dc0c06a35c3834e8e3c3a187
Binary files /dev/null and b/docs/_media/oauth/github_04.png differ
diff --git a/docs/_media/oauth/github_05.png b/docs/_media/oauth/github_05.png
new file mode 100644
index 0000000000000000000000000000000000000000..e7ccb53b5ab0df7337bd9ea60db4a153eed59304
Binary files /dev/null and b/docs/_media/oauth/github_05.png differ
diff --git a/docs/_media/oauth/github_06.png b/docs/_media/oauth/github_06.png
new file mode 100644
index 0000000000000000000000000000000000000000..06cd6a7cee00f790ec7dd9dde276bbe9f9a2b62b
Binary files /dev/null and b/docs/_media/oauth/github_06.png differ
diff --git a/docs/_media/oauth/kujiale_1.png b/docs/_media/oauth/kujiale_1.png
new file mode 100644
index 0000000000000000000000000000000000000000..02eb4626367e0919baa6455465919212c120dce4
Binary files /dev/null and b/docs/_media/oauth/kujiale_1.png differ
diff --git a/docs/_media/oauth/kujiale_2.png b/docs/_media/oauth/kujiale_2.png
new file mode 100644
index 0000000000000000000000000000000000000000..dac82e0be86417772c41f31cc47f2d4ce8d56847
Binary files /dev/null and b/docs/_media/oauth/kujiale_2.png differ
diff --git a/docs/_media/oauth/kujiale_3.png b/docs/_media/oauth/kujiale_3.png
new file mode 100644
index 0000000000000000000000000000000000000000..71552ff005f90a025a4e652715a97e7e32dec024
Binary files /dev/null and b/docs/_media/oauth/kujiale_3.png differ
diff --git a/docs/_media/oauth/kujiale_4.png b/docs/_media/oauth/kujiale_4.png
new file mode 100644
index 0000000000000000000000000000000000000000..5dc48a1fdf88af297bb8305a90294b2509d95967
Binary files /dev/null and b/docs/_media/oauth/kujiale_4.png differ
diff --git a/docs/_media/oauth/kujiale_5.png b/docs/_media/oauth/kujiale_5.png
new file mode 100644
index 0000000000000000000000000000000000000000..1dd25bfe743adb4a88fa285d89cf9c619ad313e1
Binary files /dev/null and b/docs/_media/oauth/kujiale_5.png differ
diff --git a/docs/_media/oauth/kujiale_6.png b/docs/_media/oauth/kujiale_6.png
new file mode 100644
index 0000000000000000000000000000000000000000..5af409b772882ee2042d65edb65bf02c6498087d
Binary files /dev/null and b/docs/_media/oauth/kujiale_6.png differ
diff --git a/docs/_media/scope_error.png b/docs/_media/scope_error.png
new file mode 100644
index 0000000000000000000000000000000000000000..33f4b8717df38bf8cd49744fdc1dd5c1609e0b96
Binary files /dev/null and b/docs/_media/scope_error.png differ
diff --git a/docs/_media/scope_error2.png b/docs/_media/scope_error2.png
new file mode 100644
index 0000000000000000000000000000000000000000..db50aae6b1027ea44bc5152f1da42885e2c9059c
Binary files /dev/null and b/docs/_media/scope_error2.png differ
diff --git a/docs/_sidebar.md b/docs/_sidebar.md
index deb1e5c112203556770b0592a51dda1308f47722..bec5bab07e99e1b5daea9549a5888b840728dfcc 100644
--- a/docs/_sidebar.md
+++ b/docs/_sidebar.md
@@ -4,11 +4,43 @@
- [名词解释](explain.md)
- [OAuth流程](oauth.md)
- [如何使用](how-to-use.md)
-- 其他特性
+- [Q&A](Q&A.md)
+- 集成第三方
+ - [√ Gitee登录](oauth/gitee.md)
+ - [Github登录](oauth/github.md)
+ - [qq登录](oauth/qq.md)
+ - [微信登录](oauth/wechat.md)
+ - [微博登录](oauth/weibo.md)
+ - [支付宝登录](oauth/alipay.md)
+ - [百度登录](oauth/baidu.md)
+ - [Coding登录](oauth/coding.md)
+ - [钉钉登录](oauth/dingtalk.md)
+ - [开源中国登录](oauth/oschina.md)
+ - [淘宝登录](oauth/taobao.md)
+ - [腾讯云登录](oauth/tenchentCloud.md)
+ - [Google登录](oauth/google.md)
+ - [Facebook登录](oauth/facebook.md)
+ - [抖音登录](oauth/douyin.md)
+ - [领英登录](oauth/linkedin.md)
+ - [微软登录](oauth/microsoft.md)
+ - [小米登录](oauth/mi.md)
+ - [头条登录](oauth/toutiao.md)
+ - [Teambition登录](oauth/teambition.md)
+ - [人人登录](oauth/renren.md)
+ - [Pinterest登录](oauth/pinterest.md)
+ - [Stackoverflow登录](oauth/stackoverflow.md)
+ - [华为登录](oauth/huawei.md)
+ - [微信企业版登录](oauth/wechatEnterprise.md)
+ - [√ 酷家乐登录](oauth/kujiale.md)
+ - [Gitlab登录](oauth/gitlab.md)
+ - [美团登录](oauth/meituan.md)
+ - [饿了么登录](oauth/eleme.md)
+ - [CSDN登录](oauth/csdn.md)
+- 高级特性
- [使用State](using-state.md)
- [自定义state缓存](customize-the-state-cache.md)
+ - [自定义第三方平台的OAuth](customize-the-oauth.md)
- [配套项目](supporting.md)
-- [Q&A](Q&A.md)
- [Who is using](users.md)
- [致谢](thx.md)
- [更新记录](update.md)
diff --git a/docs/contributors.md b/docs/contributors.md
index 8393a50b766109be8e5c6f21fe3d31755b24ac99..ad11a9e87e9b8bfe35de90e82d8539738c4ce960 100644
--- a/docs/contributors.md
+++ b/docs/contributors.md
@@ -10,7 +10,7 @@
- 提供ActFramework版demo
- 提供SpringBoot快速集成的justauth-spring-boot-starter
- · pengisgood : [Github] | [个人网站]
- - 集成人人登录、Pinterest登录、StackOverflow登录
+ - 集成人人登录、Pinterest登录、StackOverflow登录、Twitter登录
- · skqing : [Gitee] | [个人网站]
- 修复钉钉登录的部分问题
- 优化微博登录
diff --git a/docs/customize-the-oauth.md b/docs/customize-the-oauth.md
new file mode 100644
index 0000000000000000000000000000000000000000..5926c1291190c3314cf34bc6175602e70276834f
--- /dev/null
+++ b/docs/customize-the-oauth.md
@@ -0,0 +1,209 @@
+# 自定义第三方平台的OAuth
+
+[JustAuth](https://github.com/justauth/JustAuth)发展到现在,基本上已经涵盖了国内外大多数知名的网站。[JustAuth](https://github.com/justauth/JustAuth)也一直以它的**全**和**简**,备受各位朋友的厚爱、支持。
+
+但现在OAuth技术越来越成熟,越来越多的个人站长或者企业都开始搭建自己的OAuth授权平台,那么针对这种情况,[JustAuth](https://github.com/justauth/JustAuth)并不能做到面面俱到,无法去集成所有支持OAuth的网站(这也是不现实的)。
+
+既然考虑到有这种需求,那么就要想办法解决,想办法填补漏洞,不为了自己,也为了陪伴[JustAuth](https://github.com/justauth/JustAuth)一路走来的所有朋友们。
+
+[JustAuth](https://github.com/justauth/JustAuth)开发团队也在[v1.12.0](https://github.com/justauth/JustAuth/releases/tag/v1.12.0)版本中新加入了一大特性,就是可以支持任意支持OAuth的网站通过JustAuth实现便捷的OAuth登录!
+
+下面我们会通过一个小例子,讲解如何使用JustAuth集成自己搭建的GitLab服务。
+
+> 注:本节将会使用[JustAuth-demo](https://github.com/justauth/JustAuth-demo)Demo项目进行演示
+
+## 搭建Gitlab服务
+
+请自行解决,如果已有搭建好的Gitlab私服,请直接进入下面的步骤
+
+## 创建应用
+
+![gitlab私服创建应用](./_media/custom/gitlab.png)
+![gitlab私服应用详情](./_media/custom/gitlab2.png)
+
+## 实现AuthSource接口
+
+`AuthSource.java`是为了提供OAuth平台的API地址的统一接口,提供以下方法供实现:
+- `AuthSource#authorize()`: 获取授权url. 必须实现
+- `AuthSource#accessToken()`: 获取accessToken的url. 必须实现
+- `AuthSource#userInfo()`: 获取用户信息的url. 必须实现
+- `AuthSource#revoke()`: 获取取消授权的url. 非必须实现接口(部分平台不支持)
+- `AuthSource#refresh()`: 获取刷新授权的url. 非必须实现接口(部分平台不支持)
+
+**注:**
+- 当通过JustAuth扩展实现第三方授权时,请参考`AuthDefaultSource`自行创建对应的枚举类并实现`AuthSource`接口
+- 如果不是使用的枚举类,那么在授权成功后获取用户信息时,需要**单独处理source字段**的赋值
+- 如果扩展了对应枚举类时,在`me.zhyd.oauth.request.AuthRequest#login(AuthCallback)`中可以通过`xx.toString()`获取对应的source
+
+```java
+package me.zhyd.justauth;
+
+import me.zhyd.oauth.config.AuthSource;
+
+/**
+ * @author yadong.zhang (yadong.zhang0415(a)gmail.com)
+ * @version 1.0
+ * @website https://www.zhyd.me
+ * @date 2019/10/26 16:54
+ * @since 1.8
+ */
+public enum AuthCustomSource implements AuthSource {
+
+ /**
+ * 自己搭建的gitlab私服
+ */
+ MYGITLAB {
+ /**
+ * 授权的api
+ *
+ * @return url
+ */
+ @Override
+ public String authorize() {
+ return "http://gitlab.xxx.com/oauth/authorize";
+ }
+
+ /**
+ * 获取accessToken的api
+ *
+ * @return url
+ */
+ @Override
+ public String accessToken() {
+ return "http://gitlab.xxx.com/oauth/token";
+ }
+
+ /**
+ * 获取用户信息的api
+ *
+ * @return url
+ */
+ @Override
+ public String userInfo() {
+ return "http://gitlab.xxx.com/api/v4/user";
+ }
+ }
+}
+```
+
+## 创建自定义的Request
+
+```java
+package me.zhyd.justauth;
+
+import cn.hutool.http.HttpResponse;
+import com.alibaba.fastjson.JSONObject;
+import me.zhyd.oauth.cache.AuthStateCache;
+import me.zhyd.oauth.config.AuthConfig;
+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.request.AuthDefaultRequest;
+import me.zhyd.oauth.utils.UrlBuilder;
+
+/**
+ * @author yadong.zhang (yadong.zhang0415(a)gmail.com)
+ * @version 1.0
+ * @website https://www.zhyd.me
+ * @date 2019/10/26 17:00
+ * @since 1.8
+ */
+public class AuthMyGitlabRequest extends AuthDefaultRequest {
+
+
+ public AuthMyGitlabRequest(AuthConfig config) {
+ super(config, AuthCustomSource.MYGITLAB);
+ }
+
+ public AuthMyGitlabRequest(AuthConfig config, AuthStateCache authStateCache) {
+ super(config, AuthCustomSource.MYGITLAB, authStateCache);
+ }
+
+ @Override
+ protected AuthToken getAccessToken(AuthCallback authCallback) {
+ HttpResponse response = doPostAuthorizationCode(authCallback.getCode());
+ JSONObject object = JSONObject.parseObject(response.body());
+
+ this.checkResponse(object);
+
+ return AuthToken.builder()
+ .accessToken(object.getString("access_token"))
+ .refreshToken(object.getString("refresh_token"))
+ .idToken(object.getString("id_token"))
+ .tokenType(object.getString("token_type"))
+ .scope(object.getString("scope"))
+ .build();
+ }
+
+ @Override
+ protected AuthUser getUserInfo(AuthToken authToken) {
+ HttpResponse response = doGetUserInfo(authToken);
+ JSONObject object = JSONObject.parseObject(response.body());
+
+ this.checkResponse(object);
+
+ return AuthUser.builder()
+ .uuid(object.getString("id"))
+ .username(object.getString("username"))
+ .nickname(object.getString("name"))
+ .avatar(object.getString("avatar_url"))
+ .blog(object.getString("web_url"))
+ .company(object.getString("organization"))
+ .location(object.getString("location"))
+ .email(object.getString("email"))
+ .remark(object.getString("bio"))
+ .gender(AuthUserGender.UNKNOWN)
+ .token(authToken)
+ .source(source.toString())
+ .build();
+ }
+
+ private void checkResponse(JSONObject object) {
+ // oauth/token 验证异常
+ if (object.containsKey("error")) {
+ throw new AuthException(object.getString("error_description"));
+ }
+ // user 验证异常
+ if (object.containsKey("message")) {
+ throw new AuthException(object.getString("message"));
+ }
+ }
+
+ /**
+ * 返回带{@code state}参数的授权url,授权回调时会带上这个{@code state}
+ *
+ * @param state state 验证授权流程的参数,可以防止csrf
+ * @return 返回授权地址
+ * @since 1.11.0
+ */
+ @Override
+ public String authorize(String state) {
+ return UrlBuilder.fromBaseUrl(super.authorize(state))
+ .queryParam("scope", "read_user+openid")
+ .build();
+ }
+}
+```
+
+## 测试效果
+
+创建`AuthMyGitlabRequest`
+```java
+AuthRequest authRequest = new AuthMyGitlabRequest(AuthConfig.builder()
+ .clientId("63398e403231d4aa7e856cf5413620d536a876cb94e8d10ced0d3191b5d1d246")
+ .clientSecret("65b0eba68fff019e682e6755882a24dfdbf0a61be55de119cb8970320186c8eb")
+ .redirectUri("http://127.0.0.1:8443/oauth/callback/mygitlab")
+ .build());
+```
+
+> 注:完整代码都在[JustAuth-demo](https://github.com/justauth/JustAuth-demo)Demo项目中,本节只讲解关键代码
+
+登录后的效果为
+
+![gitlab私服验证授权](./_media/custom/gitlab3.png)
+![gitlab私服登录完成](./_media/custom/gitlab4.png)
+
+
+
diff --git a/docs/customize-the-state-cache.md b/docs/customize-the-state-cache.md
index 4f1fc91b18f280e4d377f6eb5f1ec1d2aa7e3773..af8e532ef0f76e4212b52d4030052e46f2c5028e 100644
--- a/docs/customize-the-state-cache.md
+++ b/docs/customize-the-state-cache.md
@@ -1,3 +1,123 @@
# 自定义state缓存
+> starter 内置了2种缓存实现,一种是上一节演示的默认实现,另一种是用户自定义的扩展实现。
+本节将会使用[JustAuth-demo](https://github.com/justauth/JustAuth-demo)Demo进行演示扩展Redis缓存的方式,当然了,你也可以自定义实现你自己的缓存。
-待补充
+## 添加 Redis 依赖
+```xml
+