From 3589878b369779598c94f577c4b0b7877350ec0a Mon Sep 17 00:00:00 2001
From: "yadong.zhang"
Date: Mon, 18 Feb 2019 13:39:43 +0800
Subject: [PATCH] =?UTF-8?q?:alien:=20=E6=9B=B4=E6=96=B0api=E8=B0=83?=
=?UTF-8?q?=E7=94=A8=E6=96=B9=E5=BC=8F=E3=80=81=E6=9B=B4=E6=96=B0=E6=96=87?=
=?UTF-8?q?=E6=A1=A3?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
README.md | 63 ++++++++++++++++++-
.../me/zhyd/oauth/config/GiteeConfig.java | 16 -----
.../me/zhyd/oauth/config/GithubConfig.java | 16 -----
.../java/me/zhyd/oauth/config/QqConfig.java | 17 -----
.../me/zhyd/oauth/config/WechatConfig.java | 17 -----
.../me/zhyd/oauth/config/WeiboConfig.java | 16 -----
.../zhyd/oauth/request/AuthGiteeRequest.java | 12 ++--
.../zhyd/oauth/request/AuthGithubRequest.java | 12 ++--
.../me/zhyd/oauth/request/AuthRequest.java | 13 ++--
.../zhyd/oauth/request/AuthWeiboRequest.java | 12 ++--
.../zhyd/oauth/request/BaseAuthRequest.java | 20 ++++++
.../java/me/zhyd/oauth/AuthRequestTest.java | 59 +++++++++++++++++
12 files changed, 169 insertions(+), 104 deletions(-)
delete mode 100644 src/main/java/me/zhyd/oauth/config/GiteeConfig.java
delete mode 100644 src/main/java/me/zhyd/oauth/config/GithubConfig.java
delete mode 100644 src/main/java/me/zhyd/oauth/config/QqConfig.java
delete mode 100644 src/main/java/me/zhyd/oauth/config/WechatConfig.java
delete mode 100644 src/main/java/me/zhyd/oauth/config/WeiboConfig.java
create mode 100644 src/main/java/me/zhyd/oauth/request/BaseAuthRequest.java
create mode 100644 src/test/java/me/zhyd/oauth/AuthRequestTest.java
diff --git a/README.md b/README.md
index f694277..876f33b 100644
--- a/README.md
+++ b/README.md
@@ -16,6 +16,67 @@
+
+
+
-------------------------------------------------------------------------------
-JustAuth,如你所见,它仅仅是一个**第三方授权登录**的**工具类库**,它可以让我们脱离繁琐的第三方登录SDK,让登录变得**So easy!**
\ No newline at end of file
+
+
+JustAuth,如你所见,它仅仅是一个**第三方授权登录**的**工具类库**,它可以让我们脱离繁琐的第三方登录SDK,让登录变得**So easy!**
+
+## 快速使用
+- 引入依赖
+```xml
+
+ me.zhyd.oauth
+ JustAuth
+ 1.0.0
+
+```
+- 调用api
+```java
+AuthRequest authRequest = new AuthGiteeRequest(AuthConfig.builder()
+ .clientId("clientId")
+ .clientSecret("clientSecret")
+ .redirectUri("redirectUri")
+ .build());
+// 自动跳转到授权页面
+authRequest.authorize(response);
+// 返回授权页面,可自行调整
+authRequest.authorize();
+```
+
+#### API列表
+| :computer: 平台 | :coffee: API类 | :page_facing_up: SDK |
+|:------:|:-------:|:-------:|
+| | [AuthGiteeRequest](https://gitee.com/yadong.zhang/JustAuth/blob/master/src/main/java/me/zhyd/oauth/request/AuthGiteeRequest.java) | [https://github.com/settings/developers](https://github.com/settings/developers) |
+| | [AuthGithubRequest](https://gitee.com/yadong.zhang/JustAuth/blob/master/src/main/java/me/zhyd/oauth/request/AuthGiteeRequest.java) | [https://gitee.com/api/v5/oauth_doc#list_1](https://gitee.com/api/v5/oauth_doc#list_1) |
+| | [AuthWeiboRequest](https://gitee.com/yadong.zhang/JustAuth/blob/master/src/main/java/me/zhyd/oauth/request/AuthGiteeRequest.java) | [https://open.weibo.com/apps](https://open.weibo.com/apps) |
+| | AuthCsdnRequest | [https://connect.qq.com/](https://connect.qq.com/) |
+| | AuthDingTalkRequest | 待续 |
+| | AuthQqRequest | 待续 |
+| | AuthWechatRequest | 待续 |
diff --git a/src/main/java/me/zhyd/oauth/config/GiteeConfig.java b/src/main/java/me/zhyd/oauth/config/GiteeConfig.java
deleted file mode 100644
index f5ad3fd..0000000
--- a/src/main/java/me/zhyd/oauth/config/GiteeConfig.java
+++ /dev/null
@@ -1,16 +0,0 @@
-package me.zhyd.oauth.config;
-
-import lombok.Builder;
-import lombok.Getter;
-
-/**
- * @author yadong.zhang (yadong.zhang0415(a)gmail.com)
- * @version 1.0
- * @website https://www.zhyd.me
- * @date 2019/2/14 13:34
- * @since 1.8
- */
-@Getter
-@Builder
-public class GiteeConfig extends AuthConfig {
-}
diff --git a/src/main/java/me/zhyd/oauth/config/GithubConfig.java b/src/main/java/me/zhyd/oauth/config/GithubConfig.java
deleted file mode 100644
index 73de971..0000000
--- a/src/main/java/me/zhyd/oauth/config/GithubConfig.java
+++ /dev/null
@@ -1,16 +0,0 @@
-package me.zhyd.oauth.config;
-
-import lombok.Builder;
-import lombok.Getter;
-
-/**
- * @author yadong.zhang (yadong.zhang0415(a)gmail.com)
- * @version 1.0
- * @website https://www.zhyd.me
- * @date 2019/2/14 13:34
- * @since 1.8
- */
-@Getter
-@Builder
-public class GithubConfig extends AuthConfig {
-}
diff --git a/src/main/java/me/zhyd/oauth/config/QqConfig.java b/src/main/java/me/zhyd/oauth/config/QqConfig.java
deleted file mode 100644
index d1057b1..0000000
--- a/src/main/java/me/zhyd/oauth/config/QqConfig.java
+++ /dev/null
@@ -1,17 +0,0 @@
-package me.zhyd.oauth.config;
-
-import lombok.Builder;
-import lombok.Getter;
-
-/**
- * @author yadong.zhang (yadong.zhang0415(a)gmail.com)
- * @version 1.0
- * @website https://www.zhyd.me
- * @date 2019/2/14 13:34
- * @since 1.8
- */
-@Getter
-@Builder
-@Deprecated
-public class QqConfig extends AuthConfig {
-}
diff --git a/src/main/java/me/zhyd/oauth/config/WechatConfig.java b/src/main/java/me/zhyd/oauth/config/WechatConfig.java
deleted file mode 100644
index 9625067..0000000
--- a/src/main/java/me/zhyd/oauth/config/WechatConfig.java
+++ /dev/null
@@ -1,17 +0,0 @@
-package me.zhyd.oauth.config;
-
-import lombok.Builder;
-import lombok.Getter;
-
-/**
- * @author yadong.zhang (yadong.zhang0415(a)gmail.com)
- * @version 1.0
- * @website https://www.zhyd.me
- * @date 2019/2/14 13:34
- * @since 1.8
- */
-@Getter
-@Builder
-@Deprecated
-public class WechatConfig extends AuthConfig {
-}
diff --git a/src/main/java/me/zhyd/oauth/config/WeiboConfig.java b/src/main/java/me/zhyd/oauth/config/WeiboConfig.java
deleted file mode 100644
index 8ea0984..0000000
--- a/src/main/java/me/zhyd/oauth/config/WeiboConfig.java
+++ /dev/null
@@ -1,16 +0,0 @@
-package me.zhyd.oauth.config;
-
-import lombok.Builder;
-import lombok.Getter;
-
-/**
- * @author yadong.zhang (yadong.zhang0415(a)gmail.com)
- * @version 1.0
- * @website https://www.zhyd.me
- * @date 2019/2/14 13:34
- * @since 1.8
- */
-@Getter
-@Builder
-public class WeiboConfig extends AuthConfig {
-}
diff --git a/src/main/java/me/zhyd/oauth/request/AuthGiteeRequest.java b/src/main/java/me/zhyd/oauth/request/AuthGiteeRequest.java
index 9f23061..aee139c 100644
--- a/src/main/java/me/zhyd/oauth/request/AuthGiteeRequest.java
+++ b/src/main/java/me/zhyd/oauth/request/AuthGiteeRequest.java
@@ -21,10 +21,14 @@ import java.io.IOException;
* @date 2019/1/31 16:31
* @since 1.8
*/
-public class AuthGiteeRequest implements AuthRequest {
+public class AuthGiteeRequest extends BaseAuthRequest implements AuthRequest {
+
+ public AuthGiteeRequest(AuthConfig config) {
+ super(config);
+ }
@Override
- public void authorize(AuthConfig config, HttpServletResponse response) {
+ public void authorize(HttpServletResponse response) {
if (!AuthConfigChecker.isSupportedGitee()) {
throw new AuthException(ResponseStatus.UNSUPPORTED);
}
@@ -37,7 +41,7 @@ public class AuthGiteeRequest implements AuthRequest {
}
@Override
- public String authorize(AuthConfig config) {
+ public String authorize() {
if (!AuthConfigChecker.isSupportedGitee()) {
throw new AuthException(ResponseStatus.UNSUPPORTED);
}
@@ -45,7 +49,7 @@ public class AuthGiteeRequest implements AuthRequest {
}
@Override
- public AuthResponse login(AuthConfig config, String code) {
+ public AuthResponse login(String code) {
if (!AuthConfigChecker.isSupportedGitee()) {
return AuthResponse.builder()
.code(ResponseStatus.UNSUPPORTED.getCode())
diff --git a/src/main/java/me/zhyd/oauth/request/AuthGithubRequest.java b/src/main/java/me/zhyd/oauth/request/AuthGithubRequest.java
index 97da27b..5483838 100644
--- a/src/main/java/me/zhyd/oauth/request/AuthGithubRequest.java
+++ b/src/main/java/me/zhyd/oauth/request/AuthGithubRequest.java
@@ -21,10 +21,14 @@ import java.io.IOException;
* @date 2019/1/31 16:31
* @since 1.8
*/
-public class AuthGithubRequest implements AuthRequest {
+public class AuthGithubRequest extends BaseAuthRequest implements AuthRequest {
+
+ public AuthGithubRequest(AuthConfig config) {
+ super(config);
+ }
@Override
- public void authorize(AuthConfig config, HttpServletResponse response) {
+ public void authorize(HttpServletResponse response) {
if (!AuthConfigChecker.isSupportedGithub()) {
throw new AuthException(ResponseStatus.UNSUPPORTED);
}
@@ -37,7 +41,7 @@ public class AuthGithubRequest implements AuthRequest {
}
@Override
- public String authorize(AuthConfig config) {
+ public String authorize() {
if (!AuthConfigChecker.isSupportedGithub()) {
throw new AuthException(ResponseStatus.UNSUPPORTED);
}
@@ -45,7 +49,7 @@ public class AuthGithubRequest implements AuthRequest {
}
@Override
- public AuthResponse login(AuthConfig config, String code) {
+ public AuthResponse login(String code) {
if (!AuthConfigChecker.isSupportedGithub()) {
return AuthResponse.builder()
.code(ResponseStatus.UNSUPPORTED.getCode())
diff --git a/src/main/java/me/zhyd/oauth/request/AuthRequest.java b/src/main/java/me/zhyd/oauth/request/AuthRequest.java
index eb9d3d0..76d10fa 100644
--- a/src/main/java/me/zhyd/oauth/request/AuthRequest.java
+++ b/src/main/java/me/zhyd/oauth/request/AuthRequest.java
@@ -1,6 +1,5 @@
package me.zhyd.oauth.request;
-import me.zhyd.oauth.config.AuthConfig;
import me.zhyd.oauth.exception.AuthException;
import me.zhyd.oauth.model.AuthResponse;
@@ -18,30 +17,26 @@ public interface AuthRequest {
/**
* 自动跳转到认证页面
*
- * @param config 授权的配置,对应不同平台
* @param response response
*/
- default void authorize(AuthConfig config, HttpServletResponse response) {
+ default void authorize(HttpServletResponse response) {
throw new AuthException(ResponseStatus.NOT_IMPLEMENTED);
}
/**
* 返回认证url,可自行跳转页面
- *
- * @param config 授权的配置,对应不同平台
*/
- default String authorize(AuthConfig config) {
+ default String authorize() {
throw new AuthException(ResponseStatus.NOT_IMPLEMENTED);
}
/**
* 第三方登录
*
- * @param config 授权的配置,对应不同平台
- * @param code 通过authorize换回的code
+ * @param code 通过authorize换回的code
* @return 返回登陆成功后的用户信息
*/
- default AuthResponse login(AuthConfig config, String code) {
+ default AuthResponse login(String code) {
throw new AuthException(ResponseStatus.NOT_IMPLEMENTED);
}
}
diff --git a/src/main/java/me/zhyd/oauth/request/AuthWeiboRequest.java b/src/main/java/me/zhyd/oauth/request/AuthWeiboRequest.java
index cc2a8c1..9dd0edf 100644
--- a/src/main/java/me/zhyd/oauth/request/AuthWeiboRequest.java
+++ b/src/main/java/me/zhyd/oauth/request/AuthWeiboRequest.java
@@ -24,10 +24,14 @@ import java.io.IOException;
* @date 2019/1/31 16:31
* @since 1.8
*/
-public class AuthWeiboRequest implements AuthRequest {
+public class AuthWeiboRequest extends BaseAuthRequest implements AuthRequest {
+
+ public AuthWeiboRequest(AuthConfig config) {
+ super(config);
+ }
@Override
- public void authorize(AuthConfig config, HttpServletResponse response) {
+ public void authorize(HttpServletResponse response) {
if (!AuthConfigChecker.isSupportedWeibo()) {
throw new AuthException(ResponseStatus.UNSUPPORTED);
}
@@ -40,7 +44,7 @@ public class AuthWeiboRequest implements AuthRequest {
}
@Override
- public String authorize(AuthConfig config) {
+ public String authorize() {
if (!AuthConfigChecker.isSupportedWeibo()) {
throw new AuthException(ResponseStatus.UNSUPPORTED);
}
@@ -48,7 +52,7 @@ public class AuthWeiboRequest implements AuthRequest {
}
@Override
- public AuthResponse login(AuthConfig config, String code) {
+ public AuthResponse login(String code) {
if (!AuthConfigChecker.isSupportedWeibo()) {
return AuthResponse.builder()
.code(ResponseStatus.UNSUPPORTED.getCode())
diff --git a/src/main/java/me/zhyd/oauth/request/BaseAuthRequest.java b/src/main/java/me/zhyd/oauth/request/BaseAuthRequest.java
new file mode 100644
index 0000000..03b7b95
--- /dev/null
+++ b/src/main/java/me/zhyd/oauth/request/BaseAuthRequest.java
@@ -0,0 +1,20 @@
+package me.zhyd.oauth.request;
+
+import lombok.Data;
+import me.zhyd.oauth.config.AuthConfig;
+
+/**
+ * @author yadong.zhang (yadong.zhang0415(a)gmail.com)
+ * @version 1.0
+ * @website https://www.zhyd.me
+ * @date 2019/2/18 13:11
+ * @since 1.8
+ */
+@Data
+public abstract class BaseAuthRequest {
+ protected AuthConfig config;
+
+ public BaseAuthRequest(AuthConfig config) {
+ this.config = config;
+ }
+}
diff --git a/src/test/java/me/zhyd/oauth/AuthRequestTest.java b/src/test/java/me/zhyd/oauth/AuthRequestTest.java
new file mode 100644
index 0000000..f01b82a
--- /dev/null
+++ b/src/test/java/me/zhyd/oauth/AuthRequestTest.java
@@ -0,0 +1,59 @@
+package me.zhyd.oauth;
+
+import me.zhyd.oauth.config.AuthConfig;
+import me.zhyd.oauth.request.AuthGiteeRequest;
+import me.zhyd.oauth.request.AuthGithubRequest;
+import me.zhyd.oauth.request.AuthRequest;
+import me.zhyd.oauth.request.AuthWeiboRequest;
+import org.junit.Test;
+
+import javax.servlet.http.HttpServletResponse;
+
+/**
+ * @author yadong.zhang (yadong.zhang0415(a)gmail.com)
+ * @version 1.0
+ * @website https://www.zhyd.me
+ * @date 2019/2/18 13:10
+ * @since 1.8
+ */
+public class AuthRequestTest {
+
+ @Test
+ public void giteeTest(HttpServletResponse response) {
+ AuthRequest authRequest = new AuthGiteeRequest(AuthConfig.builder()
+ .clientId("clientId")
+ .clientSecret("clientSecret")
+ .redirectUri("redirectUri")
+ .build());
+ // 自动跳转到授权页面
+ authRequest.authorize(response);
+ // 返回授权页面,可自行调整
+ authRequest.authorize();
+ }
+
+ @Test
+ public void githubTest(HttpServletResponse response) {
+ AuthRequest authRequest = new AuthGithubRequest(AuthConfig.builder()
+ .clientId("clientId")
+ .clientSecret("clientSecret")
+ .redirectUri("redirectUri")
+ .build());
+ // 自动跳转到授权页面
+ authRequest.authorize(response);
+ // 返回授权页面,可自行调整
+ authRequest.authorize();
+ }
+
+ @Test
+ public void weiboTest(HttpServletResponse response) {
+ AuthRequest authRequest = new AuthWeiboRequest(AuthConfig.builder()
+ .clientId("clientId")
+ .clientSecret("clientSecret")
+ .redirectUri("redirectUri")
+ .build());
+ // 自动跳转到授权页面
+ authRequest.authorize(response);
+ // 返回授权页面,可自行调整
+ authRequest.authorize();
+ }
+}
--
GitLab