Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Sajor_
JustAuth
提交
75176571
J
JustAuth
项目概览
Sajor_
/
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
75176571
编写于
3月 27, 2019
作者:
智布道
👁
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
✨
集成支付宝授权登录
上级
95d38fcc
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
167 addition
and
21 deletion
+167
-21
README.md
README.md
+20
-15
pom.xml
pom.xml
+10
-2
src/main/java/me/zhyd/oauth/config/AuthConfig.java
src/main/java/me/zhyd/oauth/config/AuthConfig.java
+9
-0
src/main/java/me/zhyd/oauth/consts/ApiUrl.java
src/main/java/me/zhyd/oauth/consts/ApiUrl.java
+29
-0
src/main/java/me/zhyd/oauth/model/AuthSource.java
src/main/java/me/zhyd/oauth/model/AuthSource.java
+1
-0
src/main/java/me/zhyd/oauth/model/AuthUserGender.java
src/main/java/me/zhyd/oauth/model/AuthUserGender.java
+1
-1
src/main/java/me/zhyd/oauth/request/AuthAlipayRequest.java
src/main/java/me/zhyd/oauth/request/AuthAlipayRequest.java
+75
-0
src/main/java/me/zhyd/oauth/request/BaseAuthRequest.java
src/main/java/me/zhyd/oauth/request/BaseAuthRequest.java
+9
-3
src/main/java/me/zhyd/oauth/utils/UrlBuilder.java
src/main/java/me/zhyd/oauth/utils/UrlBuilder.java
+13
-0
未找到文件。
README.md
浏览文件 @
75176571
...
...
@@ -29,6 +29,7 @@
<td
align=
"center"
width=
"200"
><a
href=
"https://coding.net"
><img
src=
"https://gitee.com/yadong.zhang/static/raw/master/JustAuth/coding.png"
width=
"30"
></a></td>
<td
align=
"center"
width=
"200"
><a
href=
"https://dev.tencent.com/"
><img
src=
"https://gitee.com/yadong.zhang/static/raw/master/JustAuth/tencent_cloud.png"
width=
"30"
></a></td>
<td
align=
"center"
width=
"200"
><a
href=
"https://www.oschina.net"
><img
src=
"https://gitee.com/yadong.zhang/static/raw/master/JustAuth/oschinas.png"
width=
"30"
></a></td>
<td
align=
"center"
width=
"200"
><a
href=
"https://www.alipay.com"
><img
src=
"https://gitee.com/yadong.zhang/static/raw/master/JustAuth/alipay.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>
...
...
@@ -42,8 +43,9 @@
<td
align=
"center"
width=
"200"
><a
href=
"#授权百度"
>
百度
</a></td>
<td
align=
"center"
width=
"200"
><a
href=
"#授权csdn"
>
CSDN
</a></td>
<td
align=
"center"
width=
"200"
><a
href=
"#授权coding"
>
Coding
</a></td>
<td
align=
"center"
width=
"200"
><a
href=
"#授权腾讯云开发者平台"
title=
"coding升级后就变成腾讯云开发者平台了"
>
腾讯云
开发者平台
</a></td>
<td
align=
"center"
width=
"200"
><a
href=
"#授权腾讯云开发者平台"
title=
"coding升级后就变成腾讯云开发者平台了"
>
腾讯云
</a></td>
<td
align=
"center"
width=
"200"
><a
href=
"#授权oschina"
>
OSChina
</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>
...
...
@@ -57,13 +59,15 @@
JustAuth,如你所见,它仅仅是一个
**第三方授权登录**
的
**工具类库**
,它可以让我们脱离繁琐的第三方登录SDK,让登录变得
**So easy!**
项目开源地址:
[
gitee
](
https://gitee.com/yadong.zhang/JustAuth
)
|
[
github
](
https://github.com/zhangyd-c/JustAuth
)
## 快速开始
-
引入依赖
```
xml
<dependency>
<groupId>
me.zhyd.oauth
</groupId>
<artifactId>
JustAuth
</artifactId>
<version>
1.0.
0
</version>
<version>
1.0.
1
</version>
</dependency>
```
-
调用api
...
...
@@ -80,7 +84,10 @@ authRequest.authorize();
authRequest
.
login
(
"code"
);
```
具体的例子可以参考:
[
实现Gitee授权登录
](
http://t.cn/ExDKxQs
)
具体的例子可以参考:
-
[
实现Gitee授权登录
](
http://t.cn/ExDKxQs
)
-
[
实现Github授权登录
](
http://t.cn/EJ0Fxqo
)
#### API列表
| :computer: 平台 | :coffee: API类 | :page_facing_up: SDK |
...
...
@@ -90,10 +97,11 @@ authRequest.login("code");
|
<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
)
|
<a
href=
"https://open.weibo.com/apps?_blank"
target=
"_blank"
>
参考文档
</a>
|
|
<img
src=
"https://gitee.com/yadong.zhang/static/raw/master/JustAuth/dingding.png"
width=
"20"
>
|
[
AuthDingTalkRequest
](
https://gitee.com/yadong.zhang/JustAuth/blob/master/src/main/java/me/zhyd/oauth/request/AuthDingTalkRequest.java
)
|
<a
href=
"https://open-doc.dingtalk.com/microapp/serverapi2/kymkv6"
target=
"_blank"
>
参考文档
</a>
|
|
<img
src=
"https://gitee.com/yadong.zhang/static/raw/master/JustAuth/baidu.png"
width=
"20"
>
|
[
AuthBaiduRequest
](
https://gitee.com/yadong.zhang/JustAuth/blob/master/src/main/java/me/zhyd/oauth/request/AuthBaiduRequest.java
)
|
<a
href=
"https://developer.baidu.com/"
target=
"_blank"
>
参考文档
</a>
|
|
<img
src=
"https://gitee.com/yadong.zhang/static/raw/master/JustAuth/csdn.png"
width=
"20"
>
|
[
AuthCsdnRequest
](
https://gitee.com/yadong.zhang/JustAuth/blob/master/src/main/java/me/zhyd/oauth/request/AuthCsdnRequest.java
)
| 待续 |
|
<img
src=
"https://gitee.com/yadong.zhang/static/raw/master/JustAuth/coding.png"
width=
"25"
>
|
[
AuthCodingRequest
](
https://gitee.com/yadong.zhang/JustAuth/blob/master/src/main/java/me/zhyd/oauth/request/AuthCodingRequest.java
)
|
<a
href=
"https://open.coding.net/references/oauth/"
target=
"_blank"
>
参考文档
</a>
|
|
<img
src=
"https://gitee.com/yadong.zhang/static/raw/master/JustAuth/tencent_cloud.png"
width=
"25"
>
|
[
AuthTencentCloudRequest
](
https://gitee.com/yadong.zhang/JustAuth/blob/master/src/main/java/me/zhyd/oauth/request/AuthTencentCloudRequest.java
)
|
<a
href=
"https://dev.tencent.com/help/doc/faq/b4e5b7aee786/oauth"
target=
"_blank"
>
参考文档
</a>
|
|
<img
src=
"https://gitee.com/yadong.zhang/static/raw/master/JustAuth/oschinas.png"
width=
"20"
>
|
[
AuthOschinaRequest
](
https://gitee.com/yadong.zhang/JustAuth/blob/master/src/main/java/me/zhyd/oauth/request/AuthOschinaRequest.java
)
|
<a
href=
"https://www.oschina.net/openapi/docs/openapi_user"
target=
"_blank"
>
参考文档
</a>
|
|
<img
src=
"https://gitee.com/yadong.zhang/static/raw/master/JustAuth/alipay.png"
width=
"20"
>
|
[
AuthAlipayRequest
](
https://gitee.com/yadong.zhang/JustAuth/blob/master/src/main/java/me/zhyd/oauth/request/AuthAlipayRequest.java
)
|
<a
href=
"https://alipay.open.taobao.com/docs/doc.htm?spm=a219a.7629140.0.0.336d4b70GUKXOl&treeId=193&articleId=105809&docType=1"
target=
"_blank"
>
参考文档
</a>
|
|
<img
src=
"https://gitee.com/yadong.zhang/static/raw/master/JustAuth/csdn.png"
width=
"20"
>
|
[
AuthCsdnRequest
](
https://gitee.com/yadong.zhang/JustAuth/blob/master/src/main/java/me/zhyd/oauth/request/AuthCsdnRequest.java
)
| 待续 |
|
<img
src=
"https://gitee.com/yadong.zhang/static/raw/master/JustAuth/qq.png"
width=
"20"
>
| AuthQqRequest |
<a
href=
"https://connect.qq.com/"
target=
"_blank"
>
参考文档
</a>
|
|
<img
src=
"https://gitee.com/yadong.zhang/static/raw/master/JustAuth/wechats.png"
width=
"20"
>
| AuthWechatRequest | 待续 |
...
...
@@ -103,13 +111,6 @@ authRequest.login("code");
另外,期待您和我一起完善这个项目!
## 本项目同步开源到Gitee和Github
[
gitee
](
https://gitee.com/yadong.zhang/JustAuth
)
[
github
](
https://github.com/zhangyd-c/JustAuth
)
## 致谢
在项目立项初期,也对当前开源圈的一些相同类型的项目作过调研,同时本项目也参考过这些项目,再次感谢开源圈内的朋友。
...
...
@@ -139,10 +140,6 @@ authRequest.login("code");
![
百度授权登录
](
https://images.gitee.com/uploads/images/2019/0221/140607_ebf1dcb6_784199.png
"百度授权登录"
)
#### 授权csdn
待续
#### 授权coding
![
Coding授权登录
](
https://images.gitee.com/uploads/images/2019/0224/192106_fd53b3d7_784199.png
"Coding授权登录"
)
...
...
@@ -155,6 +152,14 @@ authRequest.login("code");
![
授权oschina登录
](
https://images.gitee.com/uploads/images/2019/0322/230652_05b4fd8a_784199.png
"授权oschina"
)
#### 授权支付宝
待续
#### 授权csdn
待续
#### 授权qq
待续
...
...
pom.xml
浏览文件 @
75176571
<?xml version="1.0" encoding="UTF-8"?>
<project
xmlns
=
"http://maven.apache.org/POM/4.0.0"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance
"
<project
xmlns
:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xmlns=
"http://maven.apache.org/POM/4.0.0
"
xsi:schemaLocation=
"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<modelVersion>
4.0.0
</modelVersion>
<groupId>
me.zhyd.oauth
</groupId>
<artifactId>
JustAuth
</artifactId>
<version>
1.0.
0
</version>
<version>
1.0.
1
</version>
<name>
JustAuth
</name>
<url>
https://gitee.com/yadong.zhang/JustAuth
</url>
...
...
@@ -45,6 +45,7 @@
<junit-version>
4.11
</junit-version>
<fastjson-version>
1.2.44
</fastjson-version>
<google-api-version>
1.28.0
</google-api-version>
<alipay-sdk-version>
3.7.4.ALL
</alipay-sdk-version>
</properties>
<dependencies>
...
...
@@ -74,6 +75,13 @@
<artifactId>google-api-client</artifactId>
<version>${google-api-version}</version>
</dependency>-->
<dependency>
<groupId>
com.alipay.sdk
</groupId>
<artifactId>
alipay-sdk-java
</artifactId>
<version>
${alipay-sdk-version}
</version>
<scope>
compile
</scope>
</dependency>
</dependencies>
<build>
...
...
src/main/java/me/zhyd/oauth/config/AuthConfig.java
浏览文件 @
75176571
package
me.zhyd.oauth.config
;
import
lombok.AllArgsConstructor
;
import
lombok.Builder
;
import
lombok.Getter
;
import
lombok.NoArgsConstructor
;
/**
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
...
...
@@ -12,6 +14,8 @@ import lombok.Getter;
*/
@Getter
@Builder
@NoArgsConstructor
@AllArgsConstructor
public
class
AuthConfig
{
private
String
clientId
;
private
String
clientSecret
;
...
...
@@ -19,4 +23,9 @@ public class AuthConfig {
* 登录成功后的回调地址
*/
private
String
redirectUri
;
/**
* 支付宝公钥:当选择支付宝登录时,该值可用
*/
private
String
alipayPublicKey
;
}
src/main/java/me/zhyd/oauth/consts/ApiUrl.java
浏览文件 @
75176571
...
...
@@ -269,6 +269,35 @@ public enum ApiUrl {
throw
new
AuthException
(
ResponseStatus
.
UNSUPPORTED
);
}
@Override
public
String
refresh
()
{
throw
new
AuthException
(
ResponseStatus
.
UNSUPPORTED
);
}
},
/**
* 支付宝
*/
ALIPAY
{
@Override
public
String
authorize
()
{
return
"https://openauth.alipay.com/oauth2/publicAppAuthorize.htm"
;
}
@Override
public
String
accessToken
()
{
return
"https://openapi.alipay.com/gateway.do"
;
}
@Override
public
String
userInfo
()
{
return
"https://openapi.alipay.com/gateway.do"
;
}
@Override
public
String
revoke
()
{
throw
new
AuthException
(
ResponseStatus
.
UNSUPPORTED
);
}
@Override
public
String
refresh
()
{
throw
new
AuthException
(
ResponseStatus
.
UNSUPPORTED
);
...
...
src/main/java/me/zhyd/oauth/model/AuthSource.java
浏览文件 @
75176571
...
...
@@ -17,6 +17,7 @@ public enum AuthSource {
CODING
,
OSCHINA
,
TENCEN_CLOUD
,
ALIPAY
,
QQ
,
WECHAT
,
...
...
src/main/java/me/zhyd/oauth/model/AuthUserGender.java
浏览文件 @
75176571
...
...
@@ -21,7 +21,7 @@ public enum AuthUserGender {
if
(
code
==
null
)
{
return
UNKNOW
;
}
if
(
"m"
.
equals
(
code
)
||
"男"
.
equals
(
code
)
||
"1"
.
equals
(
code
)
||
"male"
.
equalsIgnoreCase
(
code
))
{
if
(
"m"
.
equals
(
code
)
||
"男"
.
equals
(
code
)
||
"1"
.
equals
(
code
)
||
"male"
.
equalsIgnoreCase
(
code
)
||
"F"
.
equalsIgnoreCase
(
code
)
)
{
return
MALE
;
}
if
(
"f"
.
equals
(
code
)
||
"女"
.
equals
(
code
)
||
"0"
.
equals
(
code
)
||
"female"
.
equalsIgnoreCase
(
code
))
{
...
...
src/main/java/me/zhyd/oauth/request/AuthAlipayRequest.java
0 → 100644
浏览文件 @
75176571
package
me.zhyd.oauth.request
;
import
com.alipay.api.AlipayApiException
;
import
com.alipay.api.AlipayClient
;
import
com.alipay.api.DefaultAlipayClient
;
import
com.alipay.api.request.AlipaySystemOauthTokenRequest
;
import
com.alipay.api.request.AlipayUserInfoShareRequest
;
import
com.alipay.api.response.AlipaySystemOauthTokenResponse
;
import
com.alipay.api.response.AlipayUserInfoShareResponse
;
import
me.zhyd.oauth.config.AuthConfig
;
import
me.zhyd.oauth.consts.ApiUrl
;
import
me.zhyd.oauth.exception.AuthException
;
import
me.zhyd.oauth.model.AuthSource
;
import
me.zhyd.oauth.model.AuthUser
;
import
me.zhyd.oauth.model.AuthUserGender
;
import
me.zhyd.oauth.utils.StringUtils
;
/**
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
* @version 1.0
* @website https://www.zhyd.me
* @date 2019/3/25 22:48
* @since 1.8
*/
public
class
AuthAlipayRequest
extends
BaseAuthRequest
{
private
AlipayClient
alipayClient
;
public
AuthAlipayRequest
(
AuthConfig
config
)
{
super
(
config
,
AuthSource
.
ALIPAY
);
this
.
alipayClient
=
new
DefaultAlipayClient
(
ApiUrl
.
ALIPAY
.
accessToken
(),
config
.
getClientId
(),
config
.
getClientSecret
(),
"json"
,
"UTF-8"
,
config
.
getAlipayPublicKey
(),
"RSA2"
);
}
@Override
protected
String
getAccessToken
(
String
code
)
{
AlipaySystemOauthTokenRequest
request
=
new
AlipaySystemOauthTokenRequest
();
request
.
setGrantType
(
"authorization_code"
);
request
.
setCode
(
code
);
AlipaySystemOauthTokenResponse
response
=
null
;
try
{
response
=
this
.
alipayClient
.
execute
(
request
);
}
catch
(
Exception
e
)
{
throw
new
AuthException
(
"Unable to get token from alipay using code ["
+
code
+
"]"
,
e
);
}
if
(!
response
.
isSuccess
())
{
throw
new
AuthException
(
response
.
getSubMsg
());
}
return
response
.
getAccessToken
();
}
@Override
protected
AuthUser
getUserInfo
(
String
accessToken
)
{
AlipayUserInfoShareRequest
request
=
new
AlipayUserInfoShareRequest
();
AlipayUserInfoShareResponse
response
=
null
;
try
{
response
=
this
.
alipayClient
.
execute
(
request
,
accessToken
);
}
catch
(
AlipayApiException
e
)
{
throw
new
AuthException
(
e
.
getErrMsg
(),
e
);
}
if
(!
response
.
isSuccess
())
{
throw
new
AuthException
(
response
.
getSubMsg
());
}
String
province
=
response
.
getProvince
(),
city
=
response
.
getCity
();
return
AuthUser
.
builder
()
.
username
(
response
.
getUserName
())
.
nickname
(
response
.
getNickName
())
.
avatar
(
response
.
getAvatar
())
.
location
(
String
.
format
(
"%s %s"
,
StringUtils
.
isEmpty
(
province
)
?
""
:
province
,
StringUtils
.
isEmpty
(
city
)
?
""
:
city
))
.
gender
(
AuthUserGender
.
getRealGender
(
response
.
getGender
()))
.
accessToken
(
accessToken
)
.
source
(
AuthSource
.
ALIPAY
)
.
build
();
}
}
src/main/java/me/zhyd/oauth/request/BaseAuthRequest.java
浏览文件 @
75176571
...
...
@@ -35,9 +35,12 @@ public abstract class BaseAuthRequest implements AuthRequest {
@Override
public
AuthResponse
login
(
String
code
)
{
return
AuthResponse
.
builder
()
.
data
(
this
.
getUserInfo
(
this
.
getAccessToken
(
code
)))
.
build
();
try
{
AuthUser
user
=
this
.
getUserInfo
(
this
.
getAccessToken
(
code
));
return
AuthResponse
.
builder
().
data
(
user
).
build
();
}
catch
(
Exception
e
)
{
return
AuthResponse
.
builder
().
code
(
500
).
msg
(
e
.
getMessage
()).
build
();
}
}
@Override
...
...
@@ -71,6 +74,9 @@ public abstract class BaseAuthRequest implements AuthRequest {
case
OSCHINA:
authorizeUrl
=
UrlBuilder
.
getOschinaAuthorizeUrl
(
config
.
getClientId
(),
config
.
getRedirectUri
());
break
;
case
ALIPAY:
authorizeUrl
=
UrlBuilder
.
getAlipayAuthorizeUrl
(
config
.
getClientId
(),
config
.
getRedirectUri
());
break
;
case
QQ:
break
;
case
WECHAT:
...
...
src/main/java/me/zhyd/oauth/utils/UrlBuilder.java
浏览文件 @
75176571
...
...
@@ -51,6 +51,8 @@ public class UrlBuilder {
private
static
final
String
OSCHINA_USER_INFO_PATTERN
=
"{0}?access_token={1}&dataType=json"
;
private
static
final
String
OSCHINA_AUTHORIZE_PATTERN
=
"{0}?client_id={1}&response_type=code&redirect_uri={2}"
;
private
static
final
String
ALIPAY_AUTHORIZE_PATTERN
=
"{0}?app_id={1}&scope=auth_user&redirect_uri={2}&state=init"
;
/**
* 获取githubtoken的接口地址
*
...
...
@@ -353,4 +355,15 @@ public class UrlBuilder {
public
static
String
getOschinaAuthorizeUrl
(
String
clientId
,
String
redirectUrl
)
{
return
MessageFormat
.
format
(
OSCHINA_AUTHORIZE_PATTERN
,
ApiUrl
.
OSCHINA
.
authorize
(),
clientId
,
redirectUrl
);
}
/**
* 获取alipay授权地址
*
* @param clientId alipay 应用的Client ID
* @param redirectUrl alipay 应用授权成功后的回调地址
* @return full url
*/
public
static
String
getAlipayAuthorizeUrl
(
String
clientId
,
String
redirectUrl
)
{
return
MessageFormat
.
format
(
ALIPAY_AUTHORIZE_PATTERN
,
ApiUrl
.
ALIPAY
.
authorize
(),
clientId
,
redirectUrl
);
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录