Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
My_csdo
JustAuth
提交
002430e4
J
JustAuth
项目概览
My_csdo
/
JustAuth
与 Fork 源项目一致
Fork自
justauth / JustAuth
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
J
JustAuth
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
002430e4
编写于
2月 18, 2019
作者:
智布道
👁
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
🎉
修改认证方式为显式的传参
上级
c327cbb1
变更
11
隐藏空白更改
内联
并排
Showing
11 changed file
with
184 addition
and
57 deletion
+184
-57
pom.xml
pom.xml
+66
-0
src/main/java/me/zhyd/oauth/config/AuthConfig.java
src/main/java/me/zhyd/oauth/config/AuthConfig.java
+9
-34
src/main/java/me/zhyd/oauth/config/GiteeConfig.java
src/main/java/me/zhyd/oauth/config/GiteeConfig.java
+16
-0
src/main/java/me/zhyd/oauth/config/GithubConfig.java
src/main/java/me/zhyd/oauth/config/GithubConfig.java
+16
-0
src/main/java/me/zhyd/oauth/config/QqConfig.java
src/main/java/me/zhyd/oauth/config/QqConfig.java
+17
-0
src/main/java/me/zhyd/oauth/config/WechatConfig.java
src/main/java/me/zhyd/oauth/config/WechatConfig.java
+17
-0
src/main/java/me/zhyd/oauth/config/WeiboConfig.java
src/main/java/me/zhyd/oauth/config/WeiboConfig.java
+16
-0
src/main/java/me/zhyd/oauth/request/AuthGiteeRequest.java
src/main/java/me/zhyd/oauth/request/AuthGiteeRequest.java
+6
-6
src/main/java/me/zhyd/oauth/request/AuthGithubRequest.java
src/main/java/me/zhyd/oauth/request/AuthGithubRequest.java
+6
-6
src/main/java/me/zhyd/oauth/request/AuthRequest.java
src/main/java/me/zhyd/oauth/request/AuthRequest.java
+9
-4
src/main/java/me/zhyd/oauth/request/AuthWeiboRequest.java
src/main/java/me/zhyd/oauth/request/AuthWeiboRequest.java
+6
-7
未找到文件。
pom.xml
浏览文件 @
002430e4
...
...
@@ -19,6 +19,12 @@
</license>
</licenses>
<scm>
<connection>
scm:git:https://gitee.com/yadong.zhang/JustAuth.git
</connection>
<developerConnection>
scm:git:https://gitee.com/yadong.zhang/JustAuth.git
</developerConnection>
<url>
https://gitee.com/yadong.zhang/JustAuth
</url>
</scm>
<developers>
<developer>
<name>
yadong.zhang
</name>
...
...
@@ -108,4 +114,64 @@
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>
release
</id>
<build>
<plugins>
<!-- Source -->
<plugin>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-source-plugin
</artifactId>
<version>
${maven-source.version}
</version>
<inherited>
true
</inherited>
<executions>
<execution>
<phase>
package
</phase>
<goals>
<goal>
jar-no-fork
</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- Javadoc -->
<plugin>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-javadoc-plugin
</artifactId>
<executions>
<execution>
<phase>
package
</phase>
<goals>
<goal>
jar
</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- GPG -->
<plugin>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-gpg-plugin
</artifactId>
<executions>
<execution>
<phase>
verify
</phase>
<goals>
<goal>
sign
</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<distributionManagement>
<snapshotRepository>
<id>
sonatype-oss
</id>
<url>
https://oss.sonatype.org/content/repositories/snapshots/
</url>
</snapshotRepository>
<repository>
<id>
sonatype-oss
</id>
<url>
https://oss.sonatype.org/service/local/staging/deploy/maven2/
</url>
</repository>
</distributionManagement>
</profile>
</profiles>
</project>
src/main/java/me/zhyd/oauth/config/AuthConfig.java
浏览文件 @
002430e4
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 登陆成功后的回调地址
* 登陆成功后的回调地址
*/
p
ublic
static
String
giteeRedirectUri
=
null
;
p
rivate
String
redirectUri
;
}
src/main/java/me/zhyd/oauth/config/GiteeConfig.java
0 → 100644
浏览文件 @
002430e4
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
{
}
src/main/java/me/zhyd/oauth/config/GithubConfig.java
0 → 100644
浏览文件 @
002430e4
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
{
}
src/main/java/me/zhyd/oauth/config/QqConfig.java
0 → 100644
浏览文件 @
002430e4
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
{
}
src/main/java/me/zhyd/oauth/config/WechatConfig.java
0 → 100644
浏览文件 @
002430e4
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
{
}
src/main/java/me/zhyd/oauth/config/WeiboConfig.java
0 → 100644
浏览文件 @
002430e4
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
{
}
src/main/java/me/zhyd/oauth/request/AuthGiteeRequest.java
浏览文件 @
002430e4
...
...
@@ -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
);
...
...
src/main/java/me/zhyd/oauth/request/AuthGithubRequest.java
浏览文件 @
002430e4
...
...
@@ -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
];
...
...
src/main/java/me/zhyd/oauth/request/AuthRequest.java
浏览文件 @
002430e4
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
);
}
}
src/main/java/me/zhyd/oauth/request/AuthWeiboRequest.java
浏览文件 @
002430e4
...
...
@@ -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
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录