Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
My_csdo
JustAuth
提交
b8c3caea
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看板
提交
b8c3caea
编写于
5月 18, 2019
作者:
智布道
👁
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
✨
支持淘宝登录、修改AuthUser.java类中的accessToken属性,由原本的accessToken (String)改为token (AuthToken)
上级
4fb81436
变更
22
隐藏空白更改
内联
并排
Showing
22 changed file
with
180 addition
and
37 deletion
+180
-37
README.md
README.md
+21
-14
pom.xml
pom.xml
+1
-1
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
-1
src/main/java/me/zhyd/oauth/model/AuthToken.java
src/main/java/me/zhyd/oauth/model/AuthToken.java
+1
-4
src/main/java/me/zhyd/oauth/model/AuthUser.java
src/main/java/me/zhyd/oauth/model/AuthUser.java
+1
-1
src/main/java/me/zhyd/oauth/request/AuthAlipayRequest.java
src/main/java/me/zhyd/oauth/request/AuthAlipayRequest.java
+1
-1
src/main/java/me/zhyd/oauth/request/AuthBaiduRequest.java
src/main/java/me/zhyd/oauth/request/AuthBaiduRequest.java
+8
-1
src/main/java/me/zhyd/oauth/request/AuthCodingRequest.java
src/main/java/me/zhyd/oauth/request/AuthCodingRequest.java
+1
-1
src/main/java/me/zhyd/oauth/request/AuthCsdnRequest.java
src/main/java/me/zhyd/oauth/request/AuthCsdnRequest.java
+1
-1
src/main/java/me/zhyd/oauth/request/AuthDingTalkRequest.java
src/main/java/me/zhyd/oauth/request/AuthDingTalkRequest.java
+1
-0
src/main/java/me/zhyd/oauth/request/AuthGiteeRequest.java
src/main/java/me/zhyd/oauth/request/AuthGiteeRequest.java
+1
-1
src/main/java/me/zhyd/oauth/request/AuthGithubRequest.java
src/main/java/me/zhyd/oauth/request/AuthGithubRequest.java
+1
-1
src/main/java/me/zhyd/oauth/request/AuthOschinaRequest.java
src/main/java/me/zhyd/oauth/request/AuthOschinaRequest.java
+1
-1
src/main/java/me/zhyd/oauth/request/AuthQqRequest.java
src/main/java/me/zhyd/oauth/request/AuthQqRequest.java
+1
-1
src/main/java/me/zhyd/oauth/request/AuthTaobaoRequest.java
src/main/java/me/zhyd/oauth/request/AuthTaobaoRequest.java
+58
-0
src/main/java/me/zhyd/oauth/request/AuthTencentCloudRequest.java
...n/java/me/zhyd/oauth/request/AuthTencentCloudRequest.java
+1
-1
src/main/java/me/zhyd/oauth/request/AuthWeChatRequest.java
src/main/java/me/zhyd/oauth/request/AuthWeChatRequest.java
+1
-1
src/main/java/me/zhyd/oauth/request/AuthWeiboRequest.java
src/main/java/me/zhyd/oauth/request/AuthWeiboRequest.java
+10
-6
src/main/java/me/zhyd/oauth/request/BaseAuthRequest.java
src/main/java/me/zhyd/oauth/request/BaseAuthRequest.java
+3
-0
src/main/java/me/zhyd/oauth/utils/UrlBuilder.java
src/main/java/me/zhyd/oauth/utils/UrlBuilder.java
+27
-0
update.md
update.md
+10
-0
未找到文件。
README.md
浏览文件 @
b8c3caea
...
...
@@ -20,18 +20,19 @@
<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.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://developer.baidu.com/"
><img
src=
"https://gitee.com/yadong.zhang/static/raw/master/JustAuth/baidu.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://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>
<td
align=
"center"
width=
"200"
><a
href=
"https://gitee.com/"
><img
src=
"https://gitee.com/logo_icon.png"
width=
"20"
></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=
"20"
></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=
"20"
></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=
"20"
></a></td>
<td
align=
"center"
width=
"200"
><a
href=
"https://developer.baidu.com/"
><img
src=
"https://gitee.com/yadong.zhang/static/raw/master/JustAuth/baidu.png"
width=
"20"
></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=
"20"
></a></td>
<td
align=
"center"
width=
"200"
><a
href=
"https://coding.net"
><img
src=
"https://gitee.com/yadong.zhang/static/raw/master/JustAuth/coding.png"
width=
"20"
></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=
"20"
></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=
"20"
></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=
"20"
></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=
"20"
></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=
"20"
></a></td>
<td
align=
"center"
width=
"200"
><a
href=
"https://open.taobao.com/"
><img
src=
"https://gitee.com/yadong.zhang/static/raw/master/JustAuth/taobao.png"
width=
"20"
></a></td>
</tr>
</thead>
<tbody>
...
...
@@ -48,6 +49,7 @@
<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>
<td
align=
"center"
width=
"200"
><a
href=
"#授权淘宝"
>
淘宝
</a></td>
</tr>
</tbody>
</table>
...
...
@@ -94,7 +96,7 @@ authRequest.login("code");
|:------:|:-------:|:-------:|
|
<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
)
|
<a
href=
"https://gitee.com/api/v5/oauth_doc#list_1"
target=
"_blank"
>
参考文档
</a>
|
|
<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
)
|
<a
href=
"https://github.com/settings/developers"
target=
"_blank"
>
参考文档
</a>
|
|
<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/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/
wiki/%E5%BE%AE%E5%8D%9AAPI
"
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/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>
|
...
...
@@ -103,7 +105,8 @@ authRequest.login("code");
|
<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/qq.png"
width=
"20"
>
|
[
AuthQqRequest
](
https://gitee.com/yadong.zhang/JustAuth/blob/master/src/main/java/me/zhyd/oauth/request/AuthQqRequest.java
)
|
<a
href=
"http://wiki.connect.qq.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/wechats.png"
width=
"20"
>
|
[
AuthWeChatRequest
](
https://gitee.com/yadong.zhang/JustAuth/blob/master/src/main/java/me/zhyd/oauth/request/AuthCsdnRequest.java
)
|
<a
href=
"https://open.weixin.qq.com/cgi-bin/showdocument?action=dir_list&t=resource/res_list&verify=1&id=open1419316505&token=&lang=zh_CN"
target=
"_blank"
>
参考文档
</a>
|
|
<img
src=
"https://gitee.com/yadong.zhang/static/raw/master/JustAuth/wechats.png"
width=
"20"
>
|
[
AuthWeChatRequest
](
https://gitee.com/yadong.zhang/JustAuth/blob/master/src/main/java/me/zhyd/oauth/request/AuthWeChatRequest.java
)
|
<a
href=
"https://open.weixin.qq.com/cgi-bin/showdocument?action=dir_list&t=resource/res_list&verify=1&id=open1419316505&token=&lang=zh_CN"
target=
"_blank"
>
参考文档
</a>
|
|
<img
src=
"https://gitee.com/yadong.zhang/static/raw/master/JustAuth/taobao.png"
width=
"20"
>
|
[
AuthTaobaoRequest
](
https://gitee.com/yadong.zhang/JustAuth/blob/master/src/main/java/me/zhyd/oauth/request/AuthTaobaoRequest.java
)
|
<a
href=
"https://open.taobao.com/doc.htm?spm=a219a.7386797.0.0.4e00669acnkQy6&source=search&docId=105590&docType=1"
target=
"_blank"
>
参考文档
</a>
|
## 后续开发计划
...
...
@@ -168,6 +171,10 @@ authRequest.login("code");
待续
#### 授权淘宝
待续
# 交流
| 微信(备注:加群) | 公众号 |
...
...
pom.xml
浏览文件 @
b8c3caea
...
...
@@ -6,7 +6,7 @@
<groupId>
me.zhyd.oauth
</groupId>
<artifactId>
JustAuth
</artifactId>
<version>
1.
1
.0
</version>
<version>
1.
2
.0
</version>
<name>
JustAuth
</name>
<url>
https://gitee.com/yadong.zhang/JustAuth
</url>
...
...
src/main/java/me/zhyd/oauth/consts/ApiUrl.java
浏览文件 @
b8c3caea
...
...
@@ -358,6 +358,35 @@ public enum ApiUrl {
public
String
refresh
()
{
return
"https://api.weixin.qq.com/sns/oauth2/refresh_token"
;
}
},
/**
* 淘宝
*/
TAOBAO
{
@Override
public
String
authorize
()
{
return
"https://oauth.taobao.com/authorize"
;
}
@Override
public
String
accessToken
()
{
return
"https://oauth.taobao.com/token"
;
}
@Override
public
String
userInfo
()
{
throw
new
AuthException
(
ResponseStatus
.
UNSUPPORTED
);
}
@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
浏览文件 @
b8c3caea
...
...
@@ -16,7 +16,7 @@ public enum AuthSource {
OSCHINA
,
TENCEN_CLOUD
,
ALIPAY
,
TAOBAO
,
QQ
,
WECHAT
,
GOOGLE
,
...
...
src/main/java/me/zhyd/oauth/model/AuthToken.java
浏览文件 @
b8c3caea
...
...
@@ -12,12 +12,9 @@ import lombok.Data;
@Builder
public
class
AuthToken
{
private
String
accessToken
;
private
String
expireIn
;
private
int
expireIn
;
private
String
refreshToken
;
private
String
uid
;
private
String
openId
;
/**
* 针对钉钉
*/
private
String
accessCode
;
}
src/main/java/me/zhyd/oauth/model/AuthUser.java
浏览文件 @
b8c3caea
...
...
@@ -21,5 +21,5 @@ public class AuthUser {
private
String
remark
;
private
AuthUserGender
gender
;
private
AuthSource
source
;
private
String
accessT
oken
;
private
AuthToken
t
oken
;
}
src/main/java/me/zhyd/oauth/request/AuthAlipayRequest.java
浏览文件 @
b8c3caea
...
...
@@ -72,7 +72,7 @@ public class AuthAlipayRequest extends BaseAuthRequest {
.
avatar
(
response
.
getAvatar
())
.
location
(
String
.
format
(
"%s %s"
,
StringUtils
.
isEmpty
(
province
)
?
""
:
province
,
StringUtils
.
isEmpty
(
city
)
?
""
:
city
))
.
gender
(
AuthUserGender
.
getRealGender
(
response
.
getGender
()))
.
accessToken
(
access
Token
)
.
token
(
auth
Token
)
.
source
(
AuthSource
.
ALIPAY
)
.
build
();
}
...
...
src/main/java/me/zhyd/oauth/request/AuthBaiduRequest.java
浏览文件 @
b8c3caea
...
...
@@ -3,6 +3,7 @@ package me.zhyd.oauth.request;
import
cn.hutool.http.HttpRequest
;
import
cn.hutool.http.HttpResponse
;
import
com.alibaba.fastjson.JSONObject
;
import
lombok.extern.slf4j.Slf4j
;
import
me.zhyd.oauth.config.AuthConfig
;
import
me.zhyd.oauth.exception.AuthException
;
import
me.zhyd.oauth.model.*
;
...
...
@@ -49,7 +50,7 @@ public class AuthBaiduRequest extends BaseAuthRequest {
.
username
(
object
.
getString
(
"username"
))
.
nickname
(
object
.
getString
(
"username"
))
.
gender
(
AuthUserGender
.
getRealGender
(
object
.
getString
(
"sex"
)))
.
accessToken
(
access
Token
)
.
token
(
auth
Token
)
.
source
(
AuthSource
.
BAIDU
)
.
build
();
}
...
...
@@ -60,6 +61,12 @@ public class AuthBaiduRequest extends BaseAuthRequest {
HttpResponse
response
=
HttpRequest
.
get
(
UrlBuilder
.
getBaiduRevokeUrl
(
accessToken
)).
execute
();
String
userInfo
=
response
.
body
();
JSONObject
object
=
JSONObject
.
parseObject
(
userInfo
);
if
(
object
.
containsKey
(
"error_code"
))
{
return
AuthResponse
.
builder
()
.
code
(
ResponseStatus
.
FAILURE
.
getCode
())
.
msg
(
object
.
getString
(
"error_msg"
))
.
build
();
}
ResponseStatus
status
=
object
.
getIntValue
(
"result"
)
==
1
?
ResponseStatus
.
SUCCESS
:
ResponseStatus
.
FAILURE
;
return
AuthResponse
.
builder
().
code
(
status
.
getCode
()).
msg
(
status
.
getMsg
()).
build
();
}
...
...
src/main/java/me/zhyd/oauth/request/AuthCodingRequest.java
浏览文件 @
b8c3caea
...
...
@@ -56,7 +56,7 @@ public class AuthCodingRequest extends BaseAuthRequest {
.
gender
(
AuthUserGender
.
getRealGender
(
object
.
getString
(
"sex"
)))
.
email
(
object
.
getString
(
"email"
))
.
remark
(
object
.
getString
(
"slogan"
))
.
accessToken
(
access
Token
)
.
token
(
auth
Token
)
.
source
(
AuthSource
.
CODING
)
.
build
();
}
...
...
src/main/java/me/zhyd/oauth/request/AuthCsdnRequest.java
浏览文件 @
b8c3caea
...
...
@@ -46,7 +46,7 @@ public class AuthCsdnRequest extends BaseAuthRequest {
}
return
AuthUser
.
builder
()
.
username
(
object
.
getString
(
"username"
))
.
accessToken
(
access
Token
)
.
token
(
auth
Token
)
.
source
(
AuthSource
.
CSDN
)
.
build
();
}
...
...
src/main/java/me/zhyd/oauth/request/AuthDingTalkRequest.java
浏览文件 @
b8c3caea
...
...
@@ -52,6 +52,7 @@ public class AuthDingTalkRequest extends BaseAuthRequest {
object
=
object
.
getJSONObject
(
"user_info"
);
return
AuthUser
.
builder
()
.
nickname
(
object
.
getStr
(
"nick"
))
.
username
(
object
.
getStr
(
"nick"
))
.
source
(
AuthSource
.
DINGTALK
)
.
build
();
}
...
...
src/main/java/me/zhyd/oauth/request/AuthGiteeRequest.java
浏览文件 @
b8c3caea
...
...
@@ -51,7 +51,7 @@ public class AuthGiteeRequest extends BaseAuthRequest {
.
location
(
object
.
getString
(
"address"
))
.
email
(
object
.
getString
(
"email"
))
.
remark
(
object
.
getString
(
"bio"
))
.
accessToken
(
access
Token
)
.
token
(
auth
Token
)
.
source
(
AuthSource
.
GITEE
)
.
build
();
}
...
...
src/main/java/me/zhyd/oauth/request/AuthGithubRequest.java
浏览文件 @
b8c3caea
...
...
@@ -54,7 +54,7 @@ public class AuthGithubRequest extends BaseAuthRequest {
.
location
(
object
.
getString
(
"location"
))
.
email
(
object
.
getString
(
"email"
))
.
remark
(
object
.
getString
(
"bio"
))
.
accessToken
(
access
Token
)
.
token
(
auth
Token
)
.
source
(
AuthSource
.
GITHUB
)
.
build
();
}
...
...
src/main/java/me/zhyd/oauth/request/AuthOschinaRequest.java
浏览文件 @
b8c3caea
...
...
@@ -53,7 +53,7 @@ public class AuthOschinaRequest extends BaseAuthRequest {
.
location
(
object
.
getString
(
"location"
))
.
gender
(
AuthUserGender
.
getRealGender
(
object
.
getString
(
"gender"
)))
.
email
(
object
.
getString
(
"email"
))
.
accessToken
(
access
Token
)
.
token
(
auth
Token
)
.
source
(
AuthSource
.
OSCHINA
)
.
build
();
}
...
...
src/main/java/me/zhyd/oauth/request/AuthQqRequest.java
浏览文件 @
b8c3caea
...
...
@@ -55,7 +55,7 @@ public class AuthQqRequest extends BaseAuthRequest {
.
nickname
(
object
.
getString
(
"nickname"
))
.
avatar
(
avatar
)
.
gender
(
AuthUserGender
.
getRealGender
(
object
.
getString
(
"gender"
)))
.
accessToken
(
access
Token
)
.
token
(
auth
Token
)
.
source
(
AuthSource
.
QQ
)
.
build
();
}
...
...
src/main/java/me/zhyd/oauth/request/AuthTaobaoRequest.java
0 → 100644
浏览文件 @
b8c3caea
package
me.zhyd.oauth.request
;
import
cn.hutool.http.HttpRequest
;
import
cn.hutool.http.HttpResponse
;
import
com.alibaba.fastjson.JSONObject
;
import
me.zhyd.oauth.config.AuthConfig
;
import
me.zhyd.oauth.exception.AuthException
;
import
me.zhyd.oauth.model.AuthSource
;
import
me.zhyd.oauth.model.AuthToken
;
import
me.zhyd.oauth.model.AuthUser
;
import
me.zhyd.oauth.model.AuthUserGender
;
import
me.zhyd.oauth.utils.GlobalAuthUtil
;
import
me.zhyd.oauth.utils.UrlBuilder
;
/**
* 淘宝登录
*
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
* @version 1.0
* @since 1.8
*/
public
class
AuthTaobaoRequest
extends
BaseAuthRequest
{
public
AuthTaobaoRequest
(
AuthConfig
config
)
{
super
(
config
,
AuthSource
.
TAOBAO
);
}
@Override
protected
AuthToken
getAccessToken
(
String
code
)
{
return
AuthToken
.
builder
()
.
accessCode
(
code
)
.
build
();
}
@Override
protected
AuthUser
getUserInfo
(
AuthToken
authToken
)
{
String
accessCode
=
authToken
.
getAccessCode
();
HttpResponse
response
=
HttpRequest
.
post
(
UrlBuilder
.
getTaobaoAccessTokenUrl
(
this
.
config
.
getClientId
(),
this
.
config
.
getClientSecret
(),
accessCode
,
this
.
config
.
getRedirectUri
())).
execute
();
JSONObject
object
=
JSONObject
.
parseObject
(
response
.
body
());
if
(
object
.
containsKey
(
"error"
))
{
throw
new
AuthException
(
ResponseStatus
.
FAILURE
+
":"
+
object
.
getString
(
"error_description"
));
}
authToken
.
setAccessToken
(
object
.
getString
(
"access_token"
));
authToken
.
setRefreshToken
(
object
.
getString
(
"refresh_token"
));
authToken
.
setExpireIn
(
object
.
getIntValue
(
"expires_in"
));
authToken
.
setUid
(
object
.
getString
(
"taobao_user_id"
));
authToken
.
setOpenId
(
object
.
getString
(
"taobao_open_uid"
));
String
nick
=
GlobalAuthUtil
.
urlDecode
(
object
.
getString
(
"taobao_user_nick"
));
return
AuthUser
.
builder
()
.
username
(
nick
)
.
nickname
(
nick
)
.
gender
(
AuthUserGender
.
UNKNOW
)
.
token
(
authToken
)
.
source
(
AuthSource
.
TAOBAO
)
.
build
();
}
}
src/main/java/me/zhyd/oauth/request/AuthTencentCloudRequest.java
浏览文件 @
b8c3caea
...
...
@@ -56,7 +56,7 @@ public class AuthTencentCloudRequest extends BaseAuthRequest {
.
gender
(
AuthUserGender
.
getRealGender
(
object
.
getString
(
"sex"
)))
.
email
(
object
.
getString
(
"email"
))
.
remark
(
object
.
getString
(
"slogan"
))
.
accessToken
(
access
Token
)
.
token
(
auth
Token
)
.
source
(
AuthSource
.
TENCEN_CLOUD
)
.
build
();
}
...
...
src/main/java/me/zhyd/oauth/request/AuthWeChatRequest.java
浏览文件 @
b8c3caea
...
...
@@ -60,7 +60,7 @@ public class AuthWeChatRequest extends BaseAuthRequest {
.
avatar
(
object
.
getString
(
"headimgurl"
))
.
location
(
object
.
getString
(
"country"
)
+
"-"
+
object
.
getString
(
"province"
)
+
"-"
+
object
.
getString
(
"city"
))
.
gender
(
AuthUserGender
.
getRealGender
(
object
.
getString
(
"sex"
)))
.
accessToken
(
access
Token
)
.
token
(
auth
Token
)
.
source
(
AuthSource
.
WECHAT
)
.
build
();
}
...
...
src/main/java/me/zhyd/oauth/request/AuthWeiboRequest.java
浏览文件 @
b8c3caea
...
...
@@ -35,24 +35,28 @@ public class AuthWeiboRequest extends BaseAuthRequest {
String
accessTokenStr
=
response
.
body
();
JSONObject
accessTokenObject
=
JSONObject
.
parseObject
(
accessTokenStr
);
if
(
accessTokenObject
.
containsKey
(
"error"
))
{
throw
new
AuthException
(
"Unable to get token from
gitee using code ["
+
code
+
"]"
);
throw
new
AuthException
(
"Unable to get token from
weibo using code ["
+
code
+
"]:"
+
accessTokenObject
.
getString
(
"error_description"
)
);
}
String
accessToken
=
accessTokenObject
.
getString
(
"access_token"
);
String
uid
=
accessTokenObject
.
getString
(
"uid"
);
return
AuthToken
.
builder
()
.
accessToken
(
String
.
format
(
"uid=%s&access_token=%s"
,
uid
,
accessToken
))
.
accessToken
(
accessTokenObject
.
getString
(
"access_token"
))
.
uid
(
accessTokenObject
.
getString
(
"uid"
))
.
expireIn
(
accessTokenObject
.
getIntValue
(
"remind_in"
))
.
build
();
}
@Override
protected
AuthUser
getUserInfo
(
AuthToken
authToken
)
{
String
accessToken
=
authToken
.
getAccessToken
();
String
uid
=
authToken
.
getUid
();
HttpResponse
response
=
HttpRequest
.
get
(
UrlBuilder
.
getWeiboUserInfoUrl
(
accessToken
))
.
header
(
"Authorization"
,
"OAuth2 "
+
accessToken
)
.
header
(
"Authorization"
,
"OAuth2 "
+
String
.
format
(
"uid=%s&access_token=%s"
,
uid
,
accessToken
)
)
.
header
(
"API-RemoteIP"
,
IpUtils
.
getIp
())
.
execute
();
String
userInfo
=
response
.
body
();
JSONObject
object
=
JSONObject
.
parseObject
(
userInfo
);
if
(
object
.
containsKey
(
"error"
))
{
throw
new
AuthException
(
object
.
getString
(
"error"
));
}
return
AuthUser
.
builder
()
.
username
(
object
.
getString
(
"name"
))
.
avatar
(
object
.
getString
(
"profile_image_url"
))
...
...
@@ -61,7 +65,7 @@ public class AuthWeiboRequest extends BaseAuthRequest {
.
location
(
object
.
getString
(
"location"
))
.
remark
(
object
.
getString
(
"description"
))
.
gender
(
AuthUserGender
.
getRealGender
(
object
.
getString
(
"gender"
)))
.
accessToken
(
GlobalAuthUtil
.
parseStringToMap
(
accessToken
).
get
(
"access_token"
)
)
.
token
(
authToken
)
.
source
(
AuthSource
.
WEIBO
)
.
build
();
}
...
...
src/main/java/me/zhyd/oauth/request/BaseAuthRequest.java
浏览文件 @
b8c3caea
...
...
@@ -82,6 +82,9 @@ public abstract class BaseAuthRequest implements AuthRequest {
case
WECHAT:
authorizeUrl
=
UrlBuilder
.
getWeChatAuthorizeUrl
(
config
.
getClientId
(),
config
.
getRedirectUri
());
break
;
case
TAOBAO:
authorizeUrl
=
UrlBuilder
.
getTaobaoAuthorizeUrl
(
config
.
getClientId
(),
config
.
getRedirectUri
());
break
;
case
GOOGLE:
break
;
default
:
...
...
src/main/java/me/zhyd/oauth/utils/UrlBuilder.java
浏览文件 @
b8c3caea
...
...
@@ -61,6 +61,9 @@ public class UrlBuilder {
private
static
final
String
WECHAT_REFRESH_TOKEN_PATTERN
=
"{0}?appid={1}&grant_type=refresh_token&refresh_token={2}"
;
private
static
final
String
WECHAT_USER_INFO_PATTERN
=
"{0}?access_token={1}&openid={2}&lang=zh_CN"
;
private
static
final
String
TAOBAO_AUTHORIZE_PATTERN
=
"{0}?response_type=code&client_id={1}&redirect_uri={2}&state=&view=web"
;
private
static
final
String
TAOBAO_ACCESS_TOKEN_PATTERN
=
"{0}?client_id={1}&client_secret={2}&code={3}&redirect_uri={4}&grant_type=authorization_code"
;
/**
* 获取githubtoken的接口地址
*
...
...
@@ -465,4 +468,28 @@ public class UrlBuilder {
public
static
String
getWeChatRefreshUrl
(
String
clientId
,
String
refreshToken
)
{
return
MessageFormat
.
format
(
WECHAT_REFRESH_TOKEN_PATTERN
,
ApiUrl
.
WECHAT
.
refresh
(),
clientId
,
refreshToken
);
}
/**
* 获取Taobao token的接口地址: 淘宝的授权登录,在这一步就会返回用户信息
*
* @param clientId taobao应用的App Key
* @param clientSecret taobao应用的App Secret
* @param code taobao授权前的code,用来换token
* @param redirectUri 待跳转的页面
* @return full url
*/
public
static
String
getTaobaoAccessTokenUrl
(
String
clientId
,
String
clientSecret
,
String
code
,
String
redirectUri
)
{
return
MessageFormat
.
format
(
TAOBAO_ACCESS_TOKEN_PATTERN
,
ApiUrl
.
TAOBAO
.
accessToken
(),
clientId
,
clientSecret
,
code
,
redirectUri
);
}
/**
* 获取Taobao授权地址
*
* @param clientId Taobao 应用的Client ID
* @param redirectUrl Taobao 应用授权成功后的回调地址
* @return full url
*/
public
static
String
getTaobaoAuthorizeUrl
(
String
clientId
,
String
redirectUrl
)
{
return
MessageFormat
.
format
(
TAOBAO_AUTHORIZE_PATTERN
,
ApiUrl
.
TAOBAO
.
authorize
(),
clientId
,
redirectUrl
);
}
}
update.md
0 → 100644
浏览文件 @
b8c3caea
### 2019/05/18
1.
迭代到1.1.0版本,发布jar包
2.
支持淘宝登录
3.
修改
`AuthUser.java`
类中的
`accessToken`
属性,由原本的~~accessToken (String)~~改为
`token (AuthToken)`
----
### 2019/05/17
1.
增加qq和微信的授权登录
2.
修改getAccessToken方法的返回值
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录