Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
justauth
JustAuth
提交
3589878b
J
JustAuth
项目概览
justauth
/
JustAuth
1 年多 前同步成功
通知
392
Star
15212
Fork
2708
代码
文件
提交
分支
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看板
提交
3589878b
编写于
2月 18, 2019
作者:
智布道
👁
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
👽
更新api调用方式、更新文档
上级
8675f1f9
变更
11
显示空白变更内容
内联
并排
Showing
11 changed file
with
169 addition
and
88 deletion
+169
-88
README.md
README.md
+62
-1
src/main/java/me/zhyd/oauth/config/GithubConfig.java
src/main/java/me/zhyd/oauth/config/GithubConfig.java
+0
-16
src/main/java/me/zhyd/oauth/config/QqConfig.java
src/main/java/me/zhyd/oauth/config/QqConfig.java
+0
-17
src/main/java/me/zhyd/oauth/config/WechatConfig.java
src/main/java/me/zhyd/oauth/config/WechatConfig.java
+0
-17
src/main/java/me/zhyd/oauth/config/WeiboConfig.java
src/main/java/me/zhyd/oauth/config/WeiboConfig.java
+0
-16
src/main/java/me/zhyd/oauth/request/AuthGiteeRequest.java
src/main/java/me/zhyd/oauth/request/AuthGiteeRequest.java
+8
-4
src/main/java/me/zhyd/oauth/request/AuthGithubRequest.java
src/main/java/me/zhyd/oauth/request/AuthGithubRequest.java
+8
-4
src/main/java/me/zhyd/oauth/request/AuthRequest.java
src/main/java/me/zhyd/oauth/request/AuthRequest.java
+4
-9
src/main/java/me/zhyd/oauth/request/AuthWeiboRequest.java
src/main/java/me/zhyd/oauth/request/AuthWeiboRequest.java
+8
-4
src/main/java/me/zhyd/oauth/request/BaseAuthRequest.java
src/main/java/me/zhyd/oauth/request/BaseAuthRequest.java
+20
-0
src/test/java/me/zhyd/oauth/AuthRequestTest.java
src/test/java/me/zhyd/oauth/AuthRequestTest.java
+59
-0
未找到文件。
README.md
浏览文件 @
3589878b
...
...
@@ -16,6 +16,67 @@
</a>
</p>
<center>
<table>
<thead>
<tr>
<td
align=
"center"
width=
"200"
><a
href=
"https://gitee.com/"
><img
src=
"https://gitee.com/logo_icon.png"
width=
"30"
></a></td>
<td
align=
"center"
width=
"200"
><a
href=
"https://github.com"
><img
src=
"https://gitee.com/yadong.zhang/static/raw/master/JustAuth/github.png"
width=
"30"
></a></td>
<td
align=
"center"
width=
"200"
><a
href=
"https://weibo.com"
><img
src=
"https://gitee.com/yadong.zhang/static/raw/master/JustAuth/weibo.png"
width=
"30"
></a></td>
<td
align=
"center"
width=
"200"
><a
href=
"https://www.csdn.net/"
><img
src=
"https://gitee.com/yadong.zhang/static/raw/master/JustAuth/csdn.png"
width=
"30"
></a></td>
<td
align=
"center"
width=
"200"
><a
href=
"https://www.dingtalk.com"
><img
src=
"https://gitee.com/yadong.zhang/static/raw/master/JustAuth/dingding.png"
width=
"30"
></a></td>
<td
align=
"center"
width=
"200"
><a
href=
"https://connect.qq.com/devuser.html#/"
><img
src=
"https://gitee.com/yadong.zhang/static/raw/master/JustAuth/qq.png"
width=
"30"
></a></td>
<td
align=
"center"
width=
"200"
><a
href=
"https://mp.weixin.qq.com/cgi-bin/loginpage?t=wxm2-login&lang=zh_CN"
><img
src=
"https://gitee.com/yadong.zhang/static/raw/master/JustAuth/wechats.png"
width=
"30"
></a></td>
</tr>
</thead>
<tbody>
<tr>
<td
align=
"center"
width=
"200"
><a
href=
"#Gitee"
>
Gitee
</a></td>
<td
align=
"center"
width=
"200"
><a
href=
"#Github"
>
Github
</a></td>
<td
align=
"center"
width=
"200"
><a
href=
"#Weibo"
>
Weibo
</a></td>
<td
align=
"center"
width=
"200"
><a
href=
"#CSDN"
>
CSDN
</a></td>
<td
align=
"center"
width=
"200"
><a
href=
"#钉钉"
>
钉钉
</a></td>
<td
align=
"center"
width=
"200"
><a
href=
"#QQ"
>
QQ
</a></td>
<td
align=
"center"
width=
"200"
><a
href=
"#微信"
>
微信
</a></td>
</tr>
</tbody>
</table>
</center>
-------------------------------------------------------------------------------
JustAuth,如你所见,它仅仅是一个
**第三方授权登录**
的
**工具类库**
,它可以让我们脱离繁琐的第三方登录SDK,让登录变得
**So easy!**
## 快速使用
-
引入依赖
```
xml
<dependency>
<groupId>
me.zhyd.oauth
</groupId>
<artifactId>
JustAuth
</artifactId>
<version>
1.0.0
</version>
</dependency>
```
-
调用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 |
|:------:|:-------:|:-------:|
|
<img
src=
"https://gitee.com/logo_icon.png"
width=
"20"
>
|
[
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
)
|
|
<img
src=
"https://gitee.com/yadong.zhang/static/raw/master/JustAuth/github.png"
width=
"20"
>
|
[
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
)
|
|
<img
src=
"https://gitee.com/yadong.zhang/static/raw/master/JustAuth/weibo.png"
width=
"20"
>
|
[
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
)
|
|
<img
src=
"https://gitee.com/yadong.zhang/static/raw/master/JustAuth/csdn.png"
width=
"20"
>
| AuthCsdnRequest |
[
https://connect.qq.com/
](
https://connect.qq.com/
)
|
|
<img
src=
"https://gitee.com/yadong.zhang/static/raw/master/JustAuth/dingding.png"
width=
"20"
>
| AuthDingTalkRequest | 待续 |
|
<img
src=
"https://gitee.com/yadong.zhang/static/raw/master/JustAuth/qq.png"
width=
"20"
>
| AuthQqRequest | 待续 |
|
<img
src=
"https://gitee.com/yadong.zhang/static/raw/master/JustAuth/wechats.png"
width=
"20"
>
| AuthWechatRequest | 待续 |
src/main/java/me/zhyd/oauth/config/GithubConfig.java
已删除
100644 → 0
浏览文件 @
8675f1f9
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
已删除
100644 → 0
浏览文件 @
8675f1f9
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
已删除
100644 → 0
浏览文件 @
8675f1f9
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
已删除
100644 → 0
浏览文件 @
8675f1f9
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
浏览文件 @
3589878b
...
...
@@ -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
())
...
...
src/main/java/me/zhyd/oauth/request/AuthGithubRequest.java
浏览文件 @
3589878b
...
...
@@ -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
())
...
...
src/main/java/me/zhyd/oauth/request/AuthRequest.java
浏览文件 @
3589878b
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
* @return 返回登陆成功后的用户信息
*/
default
AuthResponse
login
(
AuthConfig
config
,
String
code
)
{
default
AuthResponse
login
(
String
code
)
{
throw
new
AuthException
(
ResponseStatus
.
NOT_IMPLEMENTED
);
}
}
src/main/java/me/zhyd/oauth/request/AuthWeiboRequest.java
浏览文件 @
3589878b
...
...
@@ -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
())
...
...
src/main/java/me/zhyd/oauth/
config/GiteeConfig
.java
→
src/main/java/me/zhyd/oauth/
request/BaseAuthRequest
.java
浏览文件 @
3589878b
package
me.zhyd.oauth.
config
;
package
me.zhyd.oauth.
request
;
import
lombok.
Builder
;
import
lombok.Getter
;
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/1
4 13:34
* @date 2019/2/1
8 13:11
* @since 1.8
*/
@Getter
@Builder
public
class
GiteeConfig
extends
AuthConfig
{
@Data
public
abstract
class
BaseAuthRequest
{
protected
AuthConfig
config
;
public
BaseAuthRequest
(
AuthConfig
config
)
{
this
.
config
=
config
;
}
}
src/test/java/me/zhyd/oauth/AuthRequestTest.java
0 → 100644
浏览文件 @
3589878b
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
();
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录