diff --git a/pom.xml b/pom.xml
index bb9e4c7e6328aa2fa73613599464685293a3cca3..603b7ae31b56882f76a30161f6133f539d1cebbd 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1,111 +1,177 @@
-
-
-
- 4.0.0
-
- me.zhyd.oauth
- JustAuth
- 1.0.0-SNAPSHOT
-
- JustAuth
- https://gitee.com/yadong.zhang/JustAuth
- 史上最全的整合第三方登录的工具, Just Auth
-
-
-
- The Apache Software License, Version 2.0
- https://gitee.com/yadong.zhang/JustAuth/blob/master/LICENSE
-
-
-
-
-
- yadong.zhang
- yadong.zhang0415@gmail.com
-
-
-
-
- UTF-8
- 1.8
- 1.8
- 1.8
- 2.2.1
- 3.7.0
- true
- 4.1.21
- 1.18.4
- 4.11
- 2.5
- 1.2.44
-
-
-
-
- org.projectlombok
- lombok
- ${lombok-version}
-
-
- cn.hutool
- hutool-http
- ${hutool-version}
-
-
- junit
- junit
- ${junit-version}
- test
-
-
- javax.servlet
- servlet-api
- ${servlet-api-version}
-
-
- com.alibaba
- fastjson
- ${fastjson-version}
-
-
-
-
- ${project.artifactId}-${project.version}
-
-
- org.apache.maven.plugins
- maven-compiler-plugin
- ${maven-compiler.version}
-
- ${project.build.sourceEncoding}
- ${java.version}
- ${java.version}
-
-
-
- maven-source-plugin
- ${maven-source.version}
- true
-
-
- package
-
- jar-no-fork
-
-
-
-
-
-
- org.apache.maven.plugins
- maven-javadoc-plugin
-
-
-
- org.apache.maven.plugins
- maven-gpg-plugin
-
-
-
-
+
+
+
+ 4.0.0
+
+ me.zhyd.oauth
+ JustAuth
+ 1.0.0-SNAPSHOT
+
+ JustAuth
+ https://gitee.com/yadong.zhang/JustAuth
+ 史上最全的整合第三方登录的工具, Just Auth
+
+
+
+ The Apache Software License, Version 2.0
+ https://gitee.com/yadong.zhang/JustAuth/blob/master/LICENSE
+
+
+
+
+ scm:git:https://gitee.com/yadong.zhang/JustAuth.git
+ scm:git:https://gitee.com/yadong.zhang/JustAuth.git
+ https://gitee.com/yadong.zhang/JustAuth
+
+
+
+
+ yadong.zhang
+ yadong.zhang0415@gmail.com
+
+
+
+
+ UTF-8
+ 1.8
+ 1.8
+ 1.8
+ 2.2.1
+ 3.7.0
+ true
+ 4.1.21
+ 1.18.4
+ 4.11
+ 2.5
+ 1.2.44
+
+
+
+
+ org.projectlombok
+ lombok
+ ${lombok-version}
+
+
+ cn.hutool
+ hutool-http
+ ${hutool-version}
+
+
+ junit
+ junit
+ ${junit-version}
+ test
+
+
+ javax.servlet
+ servlet-api
+ ${servlet-api-version}
+
+
+ com.alibaba
+ fastjson
+ ${fastjson-version}
+
+
+
+
+ ${project.artifactId}-${project.version}
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ ${maven-compiler.version}
+
+ ${project.build.sourceEncoding}
+ ${java.version}
+ ${java.version}
+
+
+
+ maven-source-plugin
+ ${maven-source.version}
+ true
+
+
+ package
+
+ jar-no-fork
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-javadoc-plugin
+
+
+
+ org.apache.maven.plugins
+ maven-gpg-plugin
+
+
+
+
+
+ release
+
+
+
+
+ org.apache.maven.plugins
+ maven-source-plugin
+ ${maven-source.version}
+ true
+
+
+ package
+
+ jar-no-fork
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-javadoc-plugin
+
+
+ package
+
+ jar
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-gpg-plugin
+
+
+ verify
+
+ sign
+
+
+
+
+
+
+
+
+ sonatype-oss
+ https://oss.sonatype.org/content/repositories/snapshots/
+
+
+ sonatype-oss
+ https://oss.sonatype.org/service/local/staging/deploy/maven2/
+
+
+
+
+
diff --git a/src/main/java/me/zhyd/oauth/config/AuthConfig.java b/src/main/java/me/zhyd/oauth/config/AuthConfig.java
index 9ea8b3b673566a044c92e04c8c2b6abcd963d68a..d880afb371af7c7f4bd23512a6f1a1681b4e5ccc 100644
--- a/src/main/java/me/zhyd/oauth/config/AuthConfig.java
+++ b/src/main/java/me/zhyd/oauth/config/AuthConfig.java
@@ -1,5 +1,8 @@
package me.zhyd.oauth.config;
+import lombok.Builder;
+import lombok.Getter;
+
/**
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
* @version 1.0
@@ -7,41 +10,13 @@ package me.zhyd.oauth.config;
* @date 2019/1/31 14:03
* @since 1.8
*/
+@Getter
+@Builder
public class AuthConfig {
+ private String clientId;
+ private String clientSecret;
/**
- * github应用的Client ID
- */
- public static String githubClientId = null;
- /**
- * github应用的Client Secret
- */
- public static String githubClientSecret = null;
- /**
- * github应用的redirect_uri 登陆成功后的回调地址
- */
- public static String githubRedirectUri = null;
- /**
- * weibo应用的App Key
- */
- public static String weiboClientId = null;
- /**
- * weibo应用的App Secret
- */
- public static String weiboClientSecret = null;
- /**
- * weibo应用的redirect_uri 登陆成功后的回调地址
- */
- public static String weiboRedirectUri = null;
- /**
- * gitee应用的Client ID
- */
- public static String giteeClientId = null;
- /**
- * gitee应用的Client Secret
- */
- public static String giteeClientSecret = null;
- /**
- * gitee应用的redirect_uri 登陆成功后的回调地址
+ * 登陆成功后的回调地址
*/
- public static String giteeRedirectUri = null;
+ private String redirectUri;
}
diff --git a/src/main/java/me/zhyd/oauth/config/GiteeConfig.java b/src/main/java/me/zhyd/oauth/config/GiteeConfig.java
new file mode 100644
index 0000000000000000000000000000000000000000..f5ad3fd0f334737ef36375e923fb93eef3264840
--- /dev/null
+++ b/src/main/java/me/zhyd/oauth/config/GiteeConfig.java
@@ -0,0 +1,16 @@
+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
new file mode 100644
index 0000000000000000000000000000000000000000..73de97165baae1ebb1438b8eac92628c616a8686
--- /dev/null
+++ b/src/main/java/me/zhyd/oauth/config/GithubConfig.java
@@ -0,0 +1,16 @@
+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
new file mode 100644
index 0000000000000000000000000000000000000000..d1057b1df365b96ecfa693198b2d72d8344b84a8
--- /dev/null
+++ b/src/main/java/me/zhyd/oauth/config/QqConfig.java
@@ -0,0 +1,17 @@
+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
new file mode 100644
index 0000000000000000000000000000000000000000..96250670de6996833ae14e9b67f984c6dbdd0980
--- /dev/null
+++ b/src/main/java/me/zhyd/oauth/config/WechatConfig.java
@@ -0,0 +1,17 @@
+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
new file mode 100644
index 0000000000000000000000000000000000000000..8ea09842bdb24047407b528957e74484371e246f
--- /dev/null
+++ b/src/main/java/me/zhyd/oauth/config/WeiboConfig.java
@@ -0,0 +1,16 @@
+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 4d851e5e1048adc1253b8ae871699124f1f4089f..9f230616b63835a0ca6aa6e54bcf62ce613865c6 100644
--- a/src/main/java/me/zhyd/oauth/request/AuthGiteeRequest.java
+++ b/src/main/java/me/zhyd/oauth/request/AuthGiteeRequest.java
@@ -24,11 +24,11 @@ import java.io.IOException;
public class AuthGiteeRequest implements AuthRequest {
@Override
- public void authorize(HttpServletResponse response) {
+ public void authorize(AuthConfig config, HttpServletResponse response) {
if (!AuthConfigChecker.isSupportedGitee()) {
throw new AuthException(ResponseStatus.UNSUPPORTED);
}
- String authorizeUrl = UrlBuilder.getGiteeAuthorizeUrl(AuthConfig.giteeClientId, AuthConfig.giteeRedirectUri);
+ String authorizeUrl = UrlBuilder.getGiteeAuthorizeUrl(config.getClientId(), config.getRedirectUri());
try {
response.sendRedirect(authorizeUrl);
} catch (IOException e) {
@@ -37,22 +37,22 @@ public class AuthGiteeRequest implements AuthRequest {
}
@Override
- public String authorize() {
+ public String authorize(AuthConfig config) {
if (!AuthConfigChecker.isSupportedGitee()) {
throw new AuthException(ResponseStatus.UNSUPPORTED);
}
- return UrlBuilder.getGiteeAuthorizeUrl(AuthConfig.giteeClientId, AuthConfig.giteeRedirectUri);
+ return UrlBuilder.getGiteeAuthorizeUrl(config.getClientId(), config.getRedirectUri());
}
@Override
- public AuthResponse login(String code) {
+ public AuthResponse login(AuthConfig config, String code) {
if (!AuthConfigChecker.isSupportedGitee()) {
return AuthResponse.builder()
.code(ResponseStatus.UNSUPPORTED.getCode())
.msg(ResponseStatus.UNSUPPORTED.getMsg())
.build();
}
- String accessTokenUrl = UrlBuilder.getGiteeAccessTokenUrl(AuthConfig.giteeClientId, AuthConfig.giteeClientSecret, code, AuthConfig.giteeRedirectUri);
+ String accessTokenUrl = UrlBuilder.getGiteeAccessTokenUrl(config.getClientId(), config.getClientSecret(), code, config.getRedirectUri());
HttpResponse response = HttpRequest.post(accessTokenUrl).execute();
String accessTokenStr = response.body();
JSONObject accessTokenObject = JSONObject.parseObject(accessTokenStr);
diff --git a/src/main/java/me/zhyd/oauth/request/AuthGithubRequest.java b/src/main/java/me/zhyd/oauth/request/AuthGithubRequest.java
index 69e49f43161d91103df8f175bddc995265698e60..97da27bc42f1f3d646eb9635e095516e4739e205 100644
--- a/src/main/java/me/zhyd/oauth/request/AuthGithubRequest.java
+++ b/src/main/java/me/zhyd/oauth/request/AuthGithubRequest.java
@@ -24,11 +24,11 @@ import java.io.IOException;
public class AuthGithubRequest implements AuthRequest {
@Override
- public void authorize(HttpServletResponse response) {
+ public void authorize(AuthConfig config, HttpServletResponse response) {
if (!AuthConfigChecker.isSupportedGithub()) {
throw new AuthException(ResponseStatus.UNSUPPORTED);
}
- String authorizeUrl = UrlBuilder.getGithubAuthorizeUrl(AuthConfig.githubClientId, AuthConfig.githubRedirectUri);
+ String authorizeUrl = UrlBuilder.getGithubAuthorizeUrl(config.getClientId(), config.getRedirectUri());
try {
response.sendRedirect(authorizeUrl);
} catch (IOException e) {
@@ -37,22 +37,22 @@ public class AuthGithubRequest implements AuthRequest {
}
@Override
- public String authorize() {
+ public String authorize(AuthConfig config) {
if (!AuthConfigChecker.isSupportedGithub()) {
throw new AuthException(ResponseStatus.UNSUPPORTED);
}
- return UrlBuilder.getGithubAuthorizeUrl(AuthConfig.githubClientId, AuthConfig.githubRedirectUri);
+ return UrlBuilder.getGithubAuthorizeUrl(config.getClientId(), config.getRedirectUri());
}
@Override
- public AuthResponse login(String code) {
+ public AuthResponse login(AuthConfig config, String code) {
if (!AuthConfigChecker.isSupportedGithub()) {
return AuthResponse.builder()
.code(ResponseStatus.UNSUPPORTED.getCode())
.msg(ResponseStatus.UNSUPPORTED.getMsg())
.build();
}
- String accessTokenUrl = UrlBuilder.getGithubAccessTokenUrl(AuthConfig.githubClientId, AuthConfig.githubClientSecret, code, AuthConfig.githubRedirectUri);
+ String accessTokenUrl = UrlBuilder.getGithubAccessTokenUrl(config.getClientId(), config.getClientSecret(), code, config.getRedirectUri());
HttpResponse response = HttpRequest.post(accessTokenUrl).execute();
String accessTokenStr = response.body();
String accessToken = accessTokenStr.split("&")[0];
diff --git a/src/main/java/me/zhyd/oauth/request/AuthRequest.java b/src/main/java/me/zhyd/oauth/request/AuthRequest.java
index 76d10fac5ef9a159f2706d1c3a4e0f83ab8b9449..eb9d3d03280bfee300441ffb74b5b3540996568c 100644
--- a/src/main/java/me/zhyd/oauth/request/AuthRequest.java
+++ b/src/main/java/me/zhyd/oauth/request/AuthRequest.java
@@ -1,5 +1,6 @@
package me.zhyd.oauth.request;
+import me.zhyd.oauth.config.AuthConfig;
import me.zhyd.oauth.exception.AuthException;
import me.zhyd.oauth.model.AuthResponse;
@@ -17,26 +18,30 @@ public interface AuthRequest {
/**
* 自动跳转到认证页面
*
+ * @param config 授权的配置,对应不同平台
* @param response response
*/
- default void authorize(HttpServletResponse response) {
+ default void authorize(AuthConfig config, HttpServletResponse response) {
throw new AuthException(ResponseStatus.NOT_IMPLEMENTED);
}
/**
* 返回认证url,可自行跳转页面
+ *
+ * @param config 授权的配置,对应不同平台
*/
- default String authorize() {
+ default String authorize(AuthConfig config) {
throw new AuthException(ResponseStatus.NOT_IMPLEMENTED);
}
/**
* 第三方登录
*
- * @param code 通过authorize换回的code
+ * @param config 授权的配置,对应不同平台
+ * @param code 通过authorize换回的code
* @return 返回登陆成功后的用户信息
*/
- default AuthResponse login(String code) {
+ default AuthResponse login(AuthConfig config, 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 7862549fd266170d2fc84c3c97ce4aefd9e42ea1..cc2a8c1cf7da2c3a9b22cff47d1105e3cd4522ea 100644
--- a/src/main/java/me/zhyd/oauth/request/AuthWeiboRequest.java
+++ b/src/main/java/me/zhyd/oauth/request/AuthWeiboRequest.java
@@ -16,7 +16,6 @@ import me.zhyd.oauth.utils.UrlBuilder;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
-import java.net.InetAddress;
/**
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
@@ -28,11 +27,11 @@ import java.net.InetAddress;
public class AuthWeiboRequest implements AuthRequest {
@Override
- public void authorize(HttpServletResponse response) {
+ public void authorize(AuthConfig config, HttpServletResponse response) {
if (!AuthConfigChecker.isSupportedWeibo()) {
throw new AuthException(ResponseStatus.UNSUPPORTED);
}
- String authorizeUrl = UrlBuilder.getWeiboAuthorizeUrl(AuthConfig.weiboClientId, AuthConfig.weiboRedirectUri);
+ String authorizeUrl = UrlBuilder.getWeiboAuthorizeUrl(config.getClientId(), config.getRedirectUri());
try {
response.sendRedirect(authorizeUrl);
} catch (IOException e) {
@@ -41,22 +40,22 @@ public class AuthWeiboRequest implements AuthRequest {
}
@Override
- public String authorize() {
+ public String authorize(AuthConfig config) {
if (!AuthConfigChecker.isSupportedWeibo()) {
throw new AuthException(ResponseStatus.UNSUPPORTED);
}
- return UrlBuilder.getWeiboAuthorizeUrl(AuthConfig.weiboClientId, AuthConfig.weiboRedirectUri);
+ return UrlBuilder.getWeiboAuthorizeUrl(config.getClientId(), config.getRedirectUri());
}
@Override
- public AuthResponse login(String code) {
+ public AuthResponse login(AuthConfig config, String code) {
if (!AuthConfigChecker.isSupportedWeibo()) {
return AuthResponse.builder()
.code(ResponseStatus.UNSUPPORTED.getCode())
.msg(ResponseStatus.UNSUPPORTED.getMsg())
.build();
}
- String accessTokenUrl = UrlBuilder.getWeiboAccessTokenUrl(AuthConfig.weiboClientId, AuthConfig.weiboClientSecret, code, AuthConfig.weiboRedirectUri);
+ String accessTokenUrl = UrlBuilder.getWeiboAccessTokenUrl(config.getClientId(), config.getClientSecret(), code, config.getRedirectUri());
HttpResponse response = HttpRequest.post(accessTokenUrl).execute();
String accessTokenStr = response.body();
JSONObject accessTokenObject = JSONObject.parseObject(accessTokenStr);
diff --git a/src/main/java/me/zhyd/oauth/utils/IpUtils.java b/src/main/java/me/zhyd/oauth/utils/IpUtils.java
index da3dab970d7f56e7b234cf6651c06fe94d05665f..eeec62c579607d1beb25efc8bfcf9650ea24c055 100644
--- a/src/main/java/me/zhyd/oauth/utils/IpUtils.java
+++ b/src/main/java/me/zhyd/oauth/utils/IpUtils.java
@@ -15,7 +15,6 @@ import java.net.UnknownHostException;
* @date 2019/1/31 16:31
* @since 1.0
*/
-@Slf4j
public class IpUtils {
/**