Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
justauth
JustAuth
提交
80329c24
J
JustAuth
项目概览
justauth
/
JustAuth
1 年多 前同步成功
通知
391
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看板
提交
80329c24
编写于
6月 28, 2019
作者:
智布道
👁
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
✨
全面开启state校验
上级
78988555
变更
23
隐藏空白更改
内联
并排
Showing
23 changed file
with
265 addition
and
157 deletion
+265
-157
README.md
README.md
+10
-8
src/main/java/me/zhyd/oauth/model/AuthUser.java
src/main/java/me/zhyd/oauth/model/AuthUser.java
+4
-4
src/main/java/me/zhyd/oauth/request/AuthAlipayRequest.java
src/main/java/me/zhyd/oauth/request/AuthAlipayRequest.java
+3
-3
src/main/java/me/zhyd/oauth/request/AuthBaiduRequest.java
src/main/java/me/zhyd/oauth/request/AuthBaiduRequest.java
+1
-1
src/main/java/me/zhyd/oauth/request/AuthCodingRequest.java
src/main/java/me/zhyd/oauth/request/AuthCodingRequest.java
+6
-2
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
-1
src/main/java/me/zhyd/oauth/request/AuthDouyinRequest.java
src/main/java/me/zhyd/oauth/request/AuthDouyinRequest.java
+1
-1
src/main/java/me/zhyd/oauth/request/AuthFacebookRequest.java
src/main/java/me/zhyd/oauth/request/AuthFacebookRequest.java
+7
-7
src/main/java/me/zhyd/oauth/request/AuthGoogleRequest.java
src/main/java/me/zhyd/oauth/request/AuthGoogleRequest.java
+9
-9
src/main/java/me/zhyd/oauth/request/AuthLinkedinRequest.java
src/main/java/me/zhyd/oauth/request/AuthLinkedinRequest.java
+1
-1
src/main/java/me/zhyd/oauth/request/AuthMiRequest.java
src/main/java/me/zhyd/oauth/request/AuthMiRequest.java
+12
-12
src/main/java/me/zhyd/oauth/request/AuthMicrosoftRequest.java
...main/java/me/zhyd/oauth/request/AuthMicrosoftRequest.java
+8
-8
src/main/java/me/zhyd/oauth/request/AuthOschinaRequest.java
src/main/java/me/zhyd/oauth/request/AuthOschinaRequest.java
+7
-2
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
+11
-11
src/main/java/me/zhyd/oauth/request/AuthTencentCloudRequest.java
...n/java/me/zhyd/oauth/request/AuthTencentCloudRequest.java
+9
-5
src/main/java/me/zhyd/oauth/request/AuthToutiaoRequest.java
src/main/java/me/zhyd/oauth/request/AuthToutiaoRequest.java
+7
-7
src/main/java/me/zhyd/oauth/request/AuthWeChatRequest.java
src/main/java/me/zhyd/oauth/request/AuthWeChatRequest.java
+8
-8
src/main/java/me/zhyd/oauth/request/BaseAuthRequest.java
src/main/java/me/zhyd/oauth/request/BaseAuthRequest.java
+1
-1
src/main/java/me/zhyd/oauth/utils/UrlBuilder.java
src/main/java/me/zhyd/oauth/utils/UrlBuilder.java
+58
-49
src/test/java/me/zhyd/oauth/AuthRequestTest.java
src/test/java/me/zhyd/oauth/AuthRequestTest.java
+98
-14
update.md
update.md
+1
-1
未找到文件。
README.md
浏览文件 @
80329c24
...
@@ -6,7 +6,7 @@
...
@@ -6,7 +6,7 @@
</p>
</p>
<p
align=
"center"
>
<p
align=
"center"
>
<a
target=
"_blank"
href=
"https://search.maven.org/search?q=JustAuth"
>
<a
target=
"_blank"
href=
"https://search.maven.org/search?q=JustAuth"
>
<img
src=
"https://img.shields.io/badge/Maven Central-1.
7.1
-blue.svg"
></img>
<img
src=
"https://img.shields.io/badge/Maven Central-1.
8.0
-blue.svg"
></img>
</a>
</a>
<a
target=
"_blank"
href=
"https://gitee.com/yadong.zhang/JustAuth/blob/master/LICENSE"
>
<a
target=
"_blank"
href=
"https://gitee.com/yadong.zhang/JustAuth/blob/master/LICENSE"
>
<img
src=
"https://img.shields.io/apm/l/vim-mode.svg?color=yellow"
></img>
<img
src=
"https://img.shields.io/apm/l/vim-mode.svg?color=yellow"
></img>
...
@@ -15,7 +15,7 @@
...
@@ -15,7 +15,7 @@
<img
src=
"https://img.shields.io/badge/JDK-1.8+-green.svg"
></img>
<img
src=
"https://img.shields.io/badge/JDK-1.8+-green.svg"
></img>
</a>
</a>
<a
target=
"_blank"
href=
"https://apidoc.gitee.com/yadong.zhang/JustAuth/"
>
<a
target=
"_blank"
href=
"https://apidoc.gitee.com/yadong.zhang/JustAuth/"
>
<img
src=
"https://img.shields.io/badge/Docs-1.
7
.0-orange.svg"
></img>
<img
src=
"https://img.shields.io/badge/Docs-1.
8
.0-orange.svg"
></img>
</a>
</a>
</p>
</p>
...
@@ -68,7 +68,7 @@ JustAuth,如你所见,它仅仅是一个**第三方授权登录**的**工具
...
@@ -68,7 +68,7 @@ JustAuth,如你所见,它仅仅是一个**第三方授权登录**的**工具
<dependency>
<dependency>
<groupId>
me.zhyd.oauth
</groupId>
<groupId>
me.zhyd.oauth
</groupId>
<artifactId>
JustAuth
</artifactId>
<artifactId>
JustAuth
</artifactId>
<version>
1.
7.1
</version>
<version>
1.
8.0
</version>
</dependency>
</dependency>
```
```
-
调用api
-
调用api
...
@@ -81,10 +81,12 @@ AuthRequest authRequest = new AuthGiteeRequest(AuthConfig.builder()
...
@@ -81,10 +81,12 @@ AuthRequest authRequest = new AuthGiteeRequest(AuthConfig.builder()
.
build
());
.
build
());
// 生成授权页面
// 生成授权页面
authRequest
.
authorize
();
authRequest
.
authorize
();
// 授权登录后会返回
一个code,用这个code进行登录
// 授权登录后会返回
code(auth_code(仅限支付宝))、state,1.8.0版本后,可以用AuthCallback类作为回调接口的参数
authRequest
.
login
(
"code"
);
authRequest
.
login
(
callback
);
```
```
注:
`1.8.0`
版本后,增加了
`state`
参数校验,用于防止
[
CSRF
](
https://zh.wikipedia.org/wiki/%E8%B7%A8%E7%AB%99%E8%AF%B7%E6%B1%82%E4%BC%AA%E9%80%A0
)
。强烈建议,保证单次流程内
`state`
的唯一性,且每个
`state`
只可用一次。
**配套Demo**
:
[
JustAuth-demo
](
https://gitee.com/yadong.zhang/JustAuth-demo
)
**配套Demo**
:
[
JustAuth-demo
](
https://gitee.com/yadong.zhang/JustAuth-demo
)
具体的例子可以参考:
具体的例子可以参考:
...
@@ -99,12 +101,12 @@ authRequest.login("code");
...
@@ -99,12 +101,12 @@ authRequest.login("code");
|
<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://developer.github.com/apps/building-oauth-apps/authorizing-oauth-apps/"
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://developer.github.com/apps/building-oauth-apps/authorizing-oauth-apps/"
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/%E6%8E%88%E6%9D%83%E6%9C%BA%E5%88%B6%E8%AF%B4%E6%98%8E"
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/%E6%8E%88%E6%9D%83%E6%9C%BA%E5%88%B6%E8%AF%B4%E6%98%8E"
target=
"_blank"
>
参考文档
</a>
|
|
<img
src=
"https://gitee.com/yadong.zhang/static/raw/master/JustAuth/dingtalk.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/dingtalk.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=
"http
s://developer.baidu.com/
"
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=
"http
://developer.baidu.com/wiki/index.php?title=docs/oauth
"
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>
|
|
<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/tencentCloud.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/tencentCloud.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/oschina.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/o
penapi_user
"
target=
"_blank"
>
参考文档
</a>
|
|
<img
src=
"https://gitee.com/yadong.zhang/static/raw/master/JustAuth/oschina.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/o
auth2_authorize
"
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/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/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
s://wiki.connect.qq.com/%E4%BD%BF%E7%94%A8authorization_code%E8%8E%B7%E5%8F%96access_token
"
target=
"_blank"
>
参考文档
</a>
|
|
<img
src=
"https://gitee.com/yadong.zhang/static/raw/master/JustAuth/wechat.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/wechat.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>
|
|
<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>
|
|
<img
src=
"https://gitee.com/yadong.zhang/static/raw/master/JustAuth/google.png"
width=
"20"
>
|
[
AuthGoogleRequest
](
https://gitee.com/yadong.zhang/JustAuth/blob/master/src/main/java/me/zhyd/oauth/request/AuthGoogleRequest.java
)
|
<a
href=
"https://developers.google.com/identity/protocols/OpenIDConnect"
target=
"_blank"
>
参考文档
</a>
|
|
<img
src=
"https://gitee.com/yadong.zhang/static/raw/master/JustAuth/google.png"
width=
"20"
>
|
[
AuthGoogleRequest
](
https://gitee.com/yadong.zhang/JustAuth/blob/master/src/main/java/me/zhyd/oauth/request/AuthGoogleRequest.java
)
|
<a
href=
"https://developers.google.com/identity/protocols/OpenIDConnect"
target=
"_blank"
>
参考文档
</a>
|
...
...
src/main/java/me/zhyd/oauth/model/AuthUser.java
浏览文件 @
80329c24
...
@@ -17,6 +17,10 @@ import me.zhyd.oauth.config.AuthSource;
...
@@ -17,6 +17,10 @@ import me.zhyd.oauth.config.AuthSource;
@Setter
@Setter
@Builder
@Builder
public
class
AuthUser
{
public
class
AuthUser
{
/**
* 用户第三方系统的唯一id。在调用方集成改组件时,可以用uuid + source唯一确定一个用户
*/
private
String
uuid
;
/**
/**
* 用户名
* 用户名
*/
*/
...
@@ -61,8 +65,4 @@ public class AuthUser {
...
@@ -61,8 +65,4 @@ public class AuthUser {
* 用户授权的token信息
* 用户授权的token信息
*/
*/
private
AuthToken
token
;
private
AuthToken
token
;
/**
* 用户第三方系统的唯一id。在调用方集成改组件时,可以用uuid + source唯一确定一个用户
*/
private
String
uuid
;
}
}
src/main/java/me/zhyd/oauth/request/AuthAlipayRequest.java
浏览文件 @
80329c24
...
@@ -38,12 +38,12 @@ public class AuthAlipayRequest extends BaseAuthRequest {
...
@@ -38,12 +38,12 @@ public class AuthAlipayRequest extends BaseAuthRequest {
protected
AuthToken
getAccessToken
(
AuthCallback
authCallback
)
{
protected
AuthToken
getAccessToken
(
AuthCallback
authCallback
)
{
AlipaySystemOauthTokenRequest
request
=
new
AlipaySystemOauthTokenRequest
();
AlipaySystemOauthTokenRequest
request
=
new
AlipaySystemOauthTokenRequest
();
request
.
setGrantType
(
"authorization_code"
);
request
.
setGrantType
(
"authorization_code"
);
request
.
setCode
(
authCallback
.
get
C
ode
());
request
.
setCode
(
authCallback
.
get
Auth_c
ode
());
AlipaySystemOauthTokenResponse
response
=
null
;
AlipaySystemOauthTokenResponse
response
=
null
;
try
{
try
{
response
=
this
.
alipayClient
.
execute
(
request
);
response
=
this
.
alipayClient
.
execute
(
request
);
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
throw
new
AuthException
(
"Unable to get token from alipay using code ["
+
authCallback
.
get
C
ode
()
+
"]"
,
e
);
throw
new
AuthException
(
"Unable to get token from alipay using code ["
+
authCallback
.
get
Auth_c
ode
()
+
"]"
,
e
);
}
}
if
(!
response
.
isSuccess
())
{
if
(!
response
.
isSuccess
())
{
throw
new
AuthException
(
response
.
getSubMsg
());
throw
new
AuthException
(
response
.
getSubMsg
());
...
@@ -93,6 +93,6 @@ public class AuthAlipayRequest extends BaseAuthRequest {
...
@@ -93,6 +93,6 @@ public class AuthAlipayRequest extends BaseAuthRequest {
*/
*/
@Override
@Override
public
String
authorize
()
{
public
String
authorize
()
{
return
UrlBuilder
.
getAlipayAuthorizeUrl
(
config
.
getClientId
(),
config
.
getRedirectUri
());
return
UrlBuilder
.
getAlipayAuthorizeUrl
(
config
.
getClientId
(),
config
.
getRedirectUri
()
,
config
.
getState
()
);
}
}
}
}
src/main/java/me/zhyd/oauth/request/AuthBaiduRequest.java
浏览文件 @
80329c24
...
@@ -67,7 +67,7 @@ public class AuthBaiduRequest extends BaseAuthRequest {
...
@@ -67,7 +67,7 @@ public class AuthBaiduRequest extends BaseAuthRequest {
*/
*/
@Override
@Override
public
String
authorize
()
{
public
String
authorize
()
{
return
UrlBuilder
.
getBaiduAuthorizeUrl
(
config
.
getClientId
(),
config
.
getRedirectUri
());
return
UrlBuilder
.
getBaiduAuthorizeUrl
(
config
.
getClientId
(),
config
.
getRedirectUri
()
,
config
.
getState
()
);
}
}
@Override
@Override
...
...
src/main/java/me/zhyd/oauth/request/AuthCodingRequest.java
浏览文件 @
80329c24
...
@@ -33,7 +33,11 @@ public class AuthCodingRequest extends BaseAuthRequest {
...
@@ -33,7 +33,11 @@ public class AuthCodingRequest extends BaseAuthRequest {
if
(
accessTokenObject
.
getIntValue
(
"code"
)
!=
0
)
{
if
(
accessTokenObject
.
getIntValue
(
"code"
)
!=
0
)
{
throw
new
AuthException
(
"Unable to get token from coding using code ["
+
authCallback
.
getCode
()
+
"]"
);
throw
new
AuthException
(
"Unable to get token from coding using code ["
+
authCallback
.
getCode
()
+
"]"
);
}
}
return
AuthToken
.
builder
().
accessToken
(
accessTokenObject
.
getString
(
"access_token"
)).
build
();
return
AuthToken
.
builder
()
.
accessToken
(
accessTokenObject
.
getString
(
"access_token"
))
.
expireIn
(
accessTokenObject
.
getIntValue
(
"expires_in"
))
.
refreshToken
(
accessTokenObject
.
getString
(
"refresh_token"
))
.
build
();
}
}
@Override
@Override
...
@@ -69,6 +73,6 @@ public class AuthCodingRequest extends BaseAuthRequest {
...
@@ -69,6 +73,6 @@ public class AuthCodingRequest extends BaseAuthRequest {
*/
*/
@Override
@Override
public
String
authorize
()
{
public
String
authorize
()
{
return
UrlBuilder
.
getCodingAuthorizeUrl
(
config
.
getClientId
(),
config
.
getRedirectUri
());
return
UrlBuilder
.
getCodingAuthorizeUrl
(
config
.
getClientId
(),
config
.
getRedirectUri
()
,
config
.
getState
()
);
}
}
}
}
src/main/java/me/zhyd/oauth/request/AuthCsdnRequest.java
浏览文件 @
80329c24
...
@@ -63,6 +63,6 @@ public class AuthCsdnRequest extends BaseAuthRequest {
...
@@ -63,6 +63,6 @@ public class AuthCsdnRequest extends BaseAuthRequest {
*/
*/
@Override
@Override
public
String
authorize
()
{
public
String
authorize
()
{
return
UrlBuilder
.
getCsdnAuthorizeUrl
(
config
.
getClientId
(),
config
.
getRedirectUri
());
return
UrlBuilder
.
getCsdnAuthorizeUrl
(
config
.
getClientId
(),
config
.
getRedirectUri
()
,
config
.
getState
()
);
}
}
}
}
src/main/java/me/zhyd/oauth/request/AuthDingTalkRequest.java
浏览文件 @
80329c24
...
@@ -67,6 +67,6 @@ public class AuthDingTalkRequest extends BaseAuthRequest {
...
@@ -67,6 +67,6 @@ public class AuthDingTalkRequest extends BaseAuthRequest {
*/
*/
@Override
@Override
public
String
authorize
()
{
public
String
authorize
()
{
return
UrlBuilder
.
getDingTalkQrConnectUrl
(
config
.
getClientId
(),
config
.
getRedirectUri
());
return
UrlBuilder
.
getDingTalkQrConnectUrl
(
config
.
getClientId
(),
config
.
getRedirectUri
()
,
config
.
getState
()
);
}
}
}
}
src/main/java/me/zhyd/oauth/request/AuthDouyinRequest.java
浏览文件 @
80329c24
...
@@ -58,7 +58,7 @@ public class AuthDouyinRequest extends BaseAuthRequest {
...
@@ -58,7 +58,7 @@ public class AuthDouyinRequest extends BaseAuthRequest {
*/
*/
@Override
@Override
public
String
authorize
()
{
public
String
authorize
()
{
return
UrlBuilder
.
getDouyinAuthorizeUrl
(
config
.
getClientId
(),
config
.
getRedirectUri
());
return
UrlBuilder
.
getDouyinAuthorizeUrl
(
config
.
getClientId
(),
config
.
getRedirectUri
()
,
config
.
getState
()
);
}
}
@Override
@Override
...
...
src/main/java/me/zhyd/oauth/request/AuthFacebookRequest.java
浏览文件 @
80329c24
...
@@ -30,16 +30,16 @@ public class AuthFacebookRequest extends BaseAuthRequest {
...
@@ -30,16 +30,16 @@ public class AuthFacebookRequest extends BaseAuthRequest {
String
accessTokenUrl
=
UrlBuilder
.
getFacebookAccessTokenUrl
(
config
.
getClientId
(),
config
.
getClientSecret
(),
String
accessTokenUrl
=
UrlBuilder
.
getFacebookAccessTokenUrl
(
config
.
getClientId
(),
config
.
getClientSecret
(),
authCallback
.
getCode
(),
config
.
getRedirectUri
());
authCallback
.
getCode
(),
config
.
getRedirectUri
());
HttpResponse
response
=
HttpRequest
.
post
(
accessTokenUrl
).
execute
();
HttpResponse
response
=
HttpRequest
.
post
(
accessTokenUrl
).
execute
();
JSONObject
o
bject
=
JSONObject
.
parseObject
(
response
.
body
());
JSONObject
accessTokenO
bject
=
JSONObject
.
parseObject
(
response
.
body
());
if
(
o
bject
.
containsKey
(
"error"
))
{
if
(
accessTokenO
bject
.
containsKey
(
"error"
))
{
throw
new
AuthException
(
o
bject
.
getJSONObject
(
"error"
).
getString
(
"message"
));
throw
new
AuthException
(
accessTokenO
bject
.
getJSONObject
(
"error"
).
getString
(
"message"
));
}
}
return
AuthToken
.
builder
()
return
AuthToken
.
builder
()
.
accessToken
(
o
bject
.
getString
(
"access_token"
))
.
accessToken
(
accessTokenO
bject
.
getString
(
"access_token"
))
.
expireIn
(
o
bject
.
getIntValue
(
"expires_in"
))
.
expireIn
(
accessTokenO
bject
.
getIntValue
(
"expires_in"
))
.
tokenType
(
o
bject
.
getString
(
"token_type"
))
.
tokenType
(
accessTokenO
bject
.
getString
(
"token_type"
))
.
build
();
.
build
();
}
}
...
@@ -80,6 +80,6 @@ public class AuthFacebookRequest extends BaseAuthRequest {
...
@@ -80,6 +80,6 @@ public class AuthFacebookRequest extends BaseAuthRequest {
*/
*/
@Override
@Override
public
String
authorize
()
{
public
String
authorize
()
{
return
UrlBuilder
.
getFacebookAuthorizeUrl
(
config
.
getClientId
(),
config
.
getRedirectUri
());
return
UrlBuilder
.
getFacebookAuthorizeUrl
(
config
.
getClientId
(),
config
.
getRedirectUri
()
,
config
.
getState
()
);
}
}
}
}
src/main/java/me/zhyd/oauth/request/AuthGoogleRequest.java
浏览文件 @
80329c24
...
@@ -30,19 +30,19 @@ public class AuthGoogleRequest extends BaseAuthRequest {
...
@@ -30,19 +30,19 @@ public class AuthGoogleRequest extends BaseAuthRequest {
String
accessTokenUrl
=
UrlBuilder
.
getGoogleAccessTokenUrl
(
config
.
getClientId
(),
config
.
getClientSecret
(),
authCallback
.
getCode
(),
config
String
accessTokenUrl
=
UrlBuilder
.
getGoogleAccessTokenUrl
(
config
.
getClientId
(),
config
.
getClientSecret
(),
authCallback
.
getCode
(),
config
.
getRedirectUri
());
.
getRedirectUri
());
HttpResponse
response
=
HttpRequest
.
post
(
accessTokenUrl
).
execute
();
HttpResponse
response
=
HttpRequest
.
post
(
accessTokenUrl
).
execute
();
JSONObject
o
bject
=
JSONObject
.
parseObject
(
response
.
body
());
JSONObject
accessTokenO
bject
=
JSONObject
.
parseObject
(
response
.
body
());
if
(
object
.
containsKey
(
"error"
)
||
o
bject
.
containsKey
(
"error_description"
))
{
if
(
accessTokenObject
.
containsKey
(
"error"
)
||
accessTokenO
bject
.
containsKey
(
"error_description"
))
{
throw
new
AuthException
(
"get google access_token has error:["
+
object
.
getString
(
"error"
)
+
"], error_description:["
+
o
bject
throw
new
AuthException
(
"get google access_token has error:["
+
accessTokenObject
.
getString
(
"error"
)
+
"], error_description:["
+
accessTokenO
bject
.
getString
(
"error_description"
)
+
"]"
);
.
getString
(
"error_description"
)
+
"]"
);
}
}
return
AuthToken
.
builder
()
return
AuthToken
.
builder
()
.
accessToken
(
o
bject
.
getString
(
"access_token"
))
.
accessToken
(
accessTokenO
bject
.
getString
(
"access_token"
))
.
expireIn
(
o
bject
.
getIntValue
(
"expires_in"
))
.
expireIn
(
accessTokenO
bject
.
getIntValue
(
"expires_in"
))
.
scope
(
o
bject
.
getString
(
"scope"
))
.
scope
(
accessTokenO
bject
.
getString
(
"scope"
))
.
tokenType
(
o
bject
.
getString
(
"token_type"
))
.
tokenType
(
accessTokenO
bject
.
getString
(
"token_type"
))
.
idToken
(
o
bject
.
getString
(
"id_token"
))
.
idToken
(
accessTokenO
bject
.
getString
(
"id_token"
))
.
build
();
.
build
();
}
}
...
@@ -72,6 +72,6 @@ public class AuthGoogleRequest extends BaseAuthRequest {
...
@@ -72,6 +72,6 @@ public class AuthGoogleRequest extends BaseAuthRequest {
*/
*/
@Override
@Override
public
String
authorize
()
{
public
String
authorize
()
{
return
UrlBuilder
.
getGoogleAuthorizeUrl
(
config
.
getClientId
(),
config
.
getRedirectUri
());
return
UrlBuilder
.
getGoogleAuthorizeUrl
(
config
.
getClientId
(),
config
.
getRedirectUri
()
,
config
.
getState
()
);
}
}
}
}
src/main/java/me/zhyd/oauth/request/AuthLinkedinRequest.java
浏览文件 @
80329c24
...
@@ -93,7 +93,7 @@ public class AuthLinkedinRequest extends BaseAuthRequest {
...
@@ -93,7 +93,7 @@ public class AuthLinkedinRequest extends BaseAuthRequest {
*/
*/
@Override
@Override
public
String
authorize
()
{
public
String
authorize
()
{
return
UrlBuilder
.
getLinkedinAuthorizeUrl
(
config
.
getClientId
(),
config
.
getRedirectUri
());
return
UrlBuilder
.
getLinkedinAuthorizeUrl
(
config
.
getClientId
(),
config
.
getRedirectUri
()
,
config
.
getState
()
);
}
}
private
String
getUserEmail
(
String
accessToken
)
{
private
String
getUserEmail
(
String
accessToken
)
{
...
...
src/main/java/me/zhyd/oauth/request/AuthMiRequest.java
浏览文件 @
80329c24
...
@@ -35,21 +35,21 @@ public class AuthMiRequest extends BaseAuthRequest {
...
@@ -35,21 +35,21 @@ public class AuthMiRequest extends BaseAuthRequest {
private
AuthToken
getToken
(
String
accessTokenUrl
)
{
private
AuthToken
getToken
(
String
accessTokenUrl
)
{
HttpResponse
response
=
HttpRequest
.
get
(
accessTokenUrl
).
execute
();
HttpResponse
response
=
HttpRequest
.
get
(
accessTokenUrl
).
execute
();
String
jsonStr
=
StrUtil
.
replace
(
response
.
body
(),
PREFIX
,
StrUtil
.
EMPTY
);
String
jsonStr
=
StrUtil
.
replace
(
response
.
body
(),
PREFIX
,
StrUtil
.
EMPTY
);
JSONObject
o
bject
=
JSONObject
.
parseObject
(
jsonStr
);
JSONObject
accessTokenO
bject
=
JSONObject
.
parseObject
(
jsonStr
);
if
(
o
bject
.
containsKey
(
"error"
))
{
if
(
accessTokenO
bject
.
containsKey
(
"error"
))
{
throw
new
AuthException
(
o
bject
.
getString
(
"error_description"
));
throw
new
AuthException
(
accessTokenO
bject
.
getString
(
"error_description"
));
}
}
return
AuthToken
.
builder
()
return
AuthToken
.
builder
()
.
accessToken
(
o
bject
.
getString
(
"access_token"
))
.
accessToken
(
accessTokenO
bject
.
getString
(
"access_token"
))
.
expireIn
(
o
bject
.
getIntValue
(
"expires_in"
))
.
expireIn
(
accessTokenO
bject
.
getIntValue
(
"expires_in"
))
.
scope
(
o
bject
.
getString
(
"scope"
))
.
scope
(
accessTokenO
bject
.
getString
(
"scope"
))
.
tokenType
(
o
bject
.
getString
(
"token_type"
))
.
tokenType
(
accessTokenO
bject
.
getString
(
"token_type"
))
.
refreshToken
(
o
bject
.
getString
(
"refresh_token"
))
.
refreshToken
(
accessTokenO
bject
.
getString
(
"refresh_token"
))
.
openId
(
o
bject
.
getString
(
"openId"
))
.
openId
(
accessTokenO
bject
.
getString
(
"openId"
))
.
macAlgorithm
(
o
bject
.
getString
(
"mac_algorithm"
))
.
macAlgorithm
(
accessTokenO
bject
.
getString
(
"mac_algorithm"
))
.
macKey
(
o
bject
.
getString
(
"mac_key"
))
.
macKey
(
accessTokenO
bject
.
getString
(
"mac_key"
))
.
build
();
.
build
();
}
}
...
@@ -98,7 +98,7 @@ public class AuthMiRequest extends BaseAuthRequest {
...
@@ -98,7 +98,7 @@ public class AuthMiRequest extends BaseAuthRequest {
*/
*/
@Override
@Override
public
String
authorize
()
{
public
String
authorize
()
{
return
UrlBuilder
.
getMiAuthorizeUrl
(
config
.
getClientId
(),
config
.
getRedirectUri
());
return
UrlBuilder
.
getMiAuthorizeUrl
(
config
.
getClientId
(),
config
.
getRedirectUri
()
,
config
.
getState
()
);
}
}
/**
/**
...
...
src/main/java/me/zhyd/oauth/request/AuthMicrosoftRequest.java
浏览文件 @
80329c24
...
@@ -48,16 +48,16 @@ public class AuthMicrosoftRequest extends BaseAuthRequest {
...
@@ -48,16 +48,16 @@ public class AuthMicrosoftRequest extends BaseAuthRequest {
.
form
(
paramMap
)
.
form
(
paramMap
)
.
execute
();
.
execute
();
String
accessTokenStr
=
response
.
body
();
String
accessTokenStr
=
response
.
body
();
JSONObject
o
bject
=
JSONObject
.
parseObject
(
accessTokenStr
);
JSONObject
accessTokenO
bject
=
JSONObject
.
parseObject
(
accessTokenStr
);
this
.
checkResponse
(
o
bject
);
this
.
checkResponse
(
accessTokenO
bject
);
return
AuthToken
.
builder
()
return
AuthToken
.
builder
()
.
accessToken
(
o
bject
.
getString
(
"access_token"
))
.
accessToken
(
accessTokenO
bject
.
getString
(
"access_token"
))
.
expireIn
(
o
bject
.
getIntValue
(
"expires_in"
))
.
expireIn
(
accessTokenO
bject
.
getIntValue
(
"expires_in"
))
.
scope
(
o
bject
.
getString
(
"scope"
))
.
scope
(
accessTokenO
bject
.
getString
(
"scope"
))
.
tokenType
(
o
bject
.
getString
(
"token_type"
))
.
tokenType
(
accessTokenO
bject
.
getString
(
"token_type"
))
.
refreshToken
(
o
bject
.
getString
(
"refresh_token"
))
.
refreshToken
(
accessTokenO
bject
.
getString
(
"refresh_token"
))
.
build
();
.
build
();
}
}
...
@@ -96,7 +96,7 @@ public class AuthMicrosoftRequest extends BaseAuthRequest {
...
@@ -96,7 +96,7 @@ public class AuthMicrosoftRequest extends BaseAuthRequest {
*/
*/
@Override
@Override
public
String
authorize
()
{
public
String
authorize
()
{
return
UrlBuilder
.
getMicrosoftAuthorizeUrl
(
config
.
getClientId
(),
config
.
getRedirectUri
());
return
UrlBuilder
.
getMicrosoftAuthorizeUrl
(
config
.
getClientId
(),
config
.
getRedirectUri
()
,
config
.
getState
()
);
}
}
/**
/**
...
...
src/main/java/me/zhyd/oauth/request/AuthOschinaRequest.java
浏览文件 @
80329c24
...
@@ -34,7 +34,12 @@ public class AuthOschinaRequest extends BaseAuthRequest {
...
@@ -34,7 +34,12 @@ public class AuthOschinaRequest extends BaseAuthRequest {
if
(
accessTokenObject
.
containsKey
(
"error"
))
{
if
(
accessTokenObject
.
containsKey
(
"error"
))
{
throw
new
AuthException
(
"Unable to get token from oschina using code ["
+
authCallback
.
getCode
()
+
"]"
);
throw
new
AuthException
(
"Unable to get token from oschina using code ["
+
authCallback
.
getCode
()
+
"]"
);
}
}
return
AuthToken
.
builder
().
accessToken
(
accessTokenObject
.
getString
(
"access_token"
)).
build
();
return
AuthToken
.
builder
()
.
accessToken
(
accessTokenObject
.
getString
(
"access_token"
))
.
refreshToken
(
accessTokenObject
.
getString
(
"refresh_token"
))
.
uid
(
accessTokenObject
.
getString
(
"uid"
))
.
expireIn
(
accessTokenObject
.
getIntValue
(
"expires_in"
))
.
build
();
}
}
@Override
@Override
...
@@ -66,6 +71,6 @@ public class AuthOschinaRequest extends BaseAuthRequest {
...
@@ -66,6 +71,6 @@ public class AuthOschinaRequest extends BaseAuthRequest {
*/
*/
@Override
@Override
public
String
authorize
()
{
public
String
authorize
()
{
return
UrlBuilder
.
getOschinaAuthorizeUrl
(
config
.
getClientId
(),
config
.
getRedirectUri
());
return
UrlBuilder
.
getOschinaAuthorizeUrl
(
config
.
getClientId
(),
config
.
getRedirectUri
()
,
config
.
getState
()
);
}
}
}
}
src/main/java/me/zhyd/oauth/request/AuthQqRequest.java
浏览文件 @
80329c24
...
@@ -81,7 +81,7 @@ public class AuthQqRequest extends BaseAuthRequest {
...
@@ -81,7 +81,7 @@ public class AuthQqRequest extends BaseAuthRequest {
*/
*/
@Override
@Override
public
String
authorize
()
{
public
String
authorize
()
{
return
UrlBuilder
.
getQqAuthorizeUrl
(
config
.
getClientId
(),
config
.
getRedirectUri
());
return
UrlBuilder
.
getQqAuthorizeUrl
(
config
.
getClientId
(),
config
.
getRedirectUri
()
,
config
.
getState
()
);
}
}
private
String
getOpenId
(
AuthToken
authToken
)
{
private
String
getOpenId
(
AuthToken
authToken
)
{
...
...
src/main/java/me/zhyd/oauth/request/AuthTaobaoRequest.java
浏览文件 @
80329c24
...
@@ -36,19 +36,19 @@ public class AuthTaobaoRequest extends BaseAuthRequest {
...
@@ -36,19 +36,19 @@ public class AuthTaobaoRequest extends BaseAuthRequest {
String
accessCode
=
authToken
.
getAccessCode
();
String
accessCode
=
authToken
.
getAccessCode
();
HttpResponse
response
=
HttpRequest
.
post
(
UrlBuilder
.
getTaobaoAccessTokenUrl
(
this
.
config
.
getClientId
(),
this
.
config
HttpResponse
response
=
HttpRequest
.
post
(
UrlBuilder
.
getTaobaoAccessTokenUrl
(
this
.
config
.
getClientId
(),
this
.
config
.
getClientSecret
(),
accessCode
,
this
.
config
.
getRedirectUri
())).
execute
();
.
getClientSecret
(),
accessCode
,
this
.
config
.
getRedirectUri
())).
execute
();
JSONObject
o
bject
=
JSONObject
.
parseObject
(
response
.
body
());
JSONObject
accessTokenO
bject
=
JSONObject
.
parseObject
(
response
.
body
());
if
(
o
bject
.
containsKey
(
"error"
))
{
if
(
accessTokenO
bject
.
containsKey
(
"error"
))
{
throw
new
AuthException
(
ResponseStatus
.
FAILURE
+
":"
+
o
bject
.
getString
(
"error_description"
));
throw
new
AuthException
(
ResponseStatus
.
FAILURE
+
":"
+
accessTokenO
bject
.
getString
(
"error_description"
));
}
}
authToken
.
setAccessToken
(
o
bject
.
getString
(
"access_token"
));
authToken
.
setAccessToken
(
accessTokenO
bject
.
getString
(
"access_token"
));
authToken
.
setRefreshToken
(
o
bject
.
getString
(
"refresh_token"
));
authToken
.
setRefreshToken
(
accessTokenO
bject
.
getString
(
"refresh_token"
));
authToken
.
setExpireIn
(
o
bject
.
getIntValue
(
"expires_in"
));
authToken
.
setExpireIn
(
accessTokenO
bject
.
getIntValue
(
"expires_in"
));
authToken
.
setUid
(
o
bject
.
getString
(
"taobao_user_id"
));
authToken
.
setUid
(
accessTokenO
bject
.
getString
(
"taobao_user_id"
));
authToken
.
setOpenId
(
o
bject
.
getString
(
"taobao_open_uid"
));
authToken
.
setOpenId
(
accessTokenO
bject
.
getString
(
"taobao_open_uid"
));
String
nick
=
GlobalAuthUtil
.
urlDecode
(
o
bject
.
getString
(
"taobao_user_nick"
));
String
nick
=
GlobalAuthUtil
.
urlDecode
(
accessTokenO
bject
.
getString
(
"taobao_user_nick"
));
return
AuthUser
.
builder
()
return
AuthUser
.
builder
()
.
uuid
(
o
bject
.
getString
(
"taobao_user_id"
))
.
uuid
(
accessTokenO
bject
.
getString
(
"taobao_user_id"
))
.
username
(
nick
)
.
username
(
nick
)
.
nickname
(
nick
)
.
nickname
(
nick
)
.
gender
(
AuthUserGender
.
UNKNOW
)
.
gender
(
AuthUserGender
.
UNKNOW
)
...
@@ -64,6 +64,6 @@ public class AuthTaobaoRequest extends BaseAuthRequest {
...
@@ -64,6 +64,6 @@ public class AuthTaobaoRequest extends BaseAuthRequest {
*/
*/
@Override
@Override
public
String
authorize
()
{
public
String
authorize
()
{
return
UrlBuilder
.
getTaobaoAuthorizeUrl
(
config
.
getClientId
(),
config
.
getRedirectUri
());
return
UrlBuilder
.
getTaobaoAuthorizeUrl
(
config
.
getClientId
(),
config
.
getRedirectUri
()
,
config
.
getState
()
);
}
}
}
}
src/main/java/me/zhyd/oauth/request/AuthTencentCloudRequest.java
浏览文件 @
80329c24
...
@@ -29,11 +29,15 @@ public class AuthTencentCloudRequest extends BaseAuthRequest {
...
@@ -29,11 +29,15 @@ public class AuthTencentCloudRequest extends BaseAuthRequest {
protected
AuthToken
getAccessToken
(
AuthCallback
authCallback
)
{
protected
AuthToken
getAccessToken
(
AuthCallback
authCallback
)
{
String
accessTokenUrl
=
UrlBuilder
.
getTencentCloudAccessTokenUrl
(
config
.
getClientId
(),
config
.
getClientSecret
(),
authCallback
.
getCode
());
String
accessTokenUrl
=
UrlBuilder
.
getTencentCloudAccessTokenUrl
(
config
.
getClientId
(),
config
.
getClientSecret
(),
authCallback
.
getCode
());
HttpResponse
response
=
HttpRequest
.
get
(
accessTokenUrl
).
execute
();
HttpResponse
response
=
HttpRequest
.
get
(
accessTokenUrl
).
execute
();
JSONObject
o
bject
=
JSONObject
.
parseObject
(
response
.
body
());
JSONObject
accessTokenO
bject
=
JSONObject
.
parseObject
(
response
.
body
());
if
(
o
bject
.
getIntValue
(
"code"
)
!=
0
)
{
if
(
accessTokenO
bject
.
getIntValue
(
"code"
)
!=
0
)
{
throw
new
AuthException
(
"Unable to get token from tencent cloud using code ["
+
authCallback
.
getCode
()
+
"]: "
+
o
bject
.
get
(
"msg"
));
throw
new
AuthException
(
"Unable to get token from tencent cloud using code ["
+
authCallback
.
getCode
()
+
"]: "
+
accessTokenO
bject
.
get
(
"msg"
));
}
}
return
AuthToken
.
builder
().
accessToken
(
object
.
getString
(
"access_token"
)).
build
();
return
AuthToken
.
builder
()
.
accessToken
(
accessTokenObject
.
getString
(
"access_token"
))
.
expireIn
(
accessTokenObject
.
getIntValue
(
"expires_in"
))
.
refreshToken
(
accessTokenObject
.
getString
(
"refresh_token"
))
.
build
();
}
}
@Override
@Override
...
@@ -68,6 +72,6 @@ public class AuthTencentCloudRequest extends BaseAuthRequest {
...
@@ -68,6 +72,6 @@ public class AuthTencentCloudRequest extends BaseAuthRequest {
*/
*/
@Override
@Override
public
String
authorize
()
{
public
String
authorize
()
{
return
UrlBuilder
.
getTencentCloudAuthorizeUrl
(
config
.
getClientId
(),
config
.
getRedirectUri
());
return
UrlBuilder
.
getTencentCloudAuthorizeUrl
(
config
.
getClientId
(),
config
.
getRedirectUri
()
,
config
.
getState
()
);
}
}
}
}
src/main/java/me/zhyd/oauth/request/AuthToutiaoRequest.java
浏览文件 @
80329c24
...
@@ -26,16 +26,16 @@ public class AuthToutiaoRequest extends BaseAuthRequest {
...
@@ -26,16 +26,16 @@ public class AuthToutiaoRequest extends BaseAuthRequest {
protected
AuthToken
getAccessToken
(
AuthCallback
authCallback
)
{
protected
AuthToken
getAccessToken
(
AuthCallback
authCallback
)
{
String
accessTokenUrl
=
UrlBuilder
.
getToutiaoAccessTokenUrl
(
config
.
getClientId
(),
config
.
getClientSecret
(),
authCallback
.
getCode
());
String
accessTokenUrl
=
UrlBuilder
.
getToutiaoAccessTokenUrl
(
config
.
getClientId
(),
config
.
getClientSecret
(),
authCallback
.
getCode
());
HttpResponse
response
=
HttpRequest
.
get
(
accessTokenUrl
).
execute
();
HttpResponse
response
=
HttpRequest
.
get
(
accessTokenUrl
).
execute
();
JSONObject
o
bject
=
JSONObject
.
parseObject
(
response
.
body
());
JSONObject
accessTokenO
bject
=
JSONObject
.
parseObject
(
response
.
body
());
if
(
o
bject
.
containsKey
(
"error_code"
))
{
if
(
accessTokenO
bject
.
containsKey
(
"error_code"
))
{
throw
new
AuthException
(
AuthToutiaoErrorCode
.
getErrorCode
(
o
bject
.
getIntValue
(
"error_code"
)).
getDesc
());
throw
new
AuthException
(
AuthToutiaoErrorCode
.
getErrorCode
(
accessTokenO
bject
.
getIntValue
(
"error_code"
)).
getDesc
());
}
}
return
AuthToken
.
builder
()
return
AuthToken
.
builder
()
.
accessToken
(
o
bject
.
getString
(
"access_token"
))
.
accessToken
(
accessTokenO
bject
.
getString
(
"access_token"
))
.
expireIn
(
o
bject
.
getIntValue
(
"expires_in"
))
.
expireIn
(
accessTokenO
bject
.
getIntValue
(
"expires_in"
))
.
openId
(
o
bject
.
getString
(
"open_id"
))
.
openId
(
accessTokenO
bject
.
getString
(
"open_id"
))
.
build
();
.
build
();
}
}
...
@@ -73,6 +73,6 @@ public class AuthToutiaoRequest extends BaseAuthRequest {
...
@@ -73,6 +73,6 @@ public class AuthToutiaoRequest extends BaseAuthRequest {
*/
*/
@Override
@Override
public
String
authorize
()
{
public
String
authorize
()
{
return
UrlBuilder
.
getToutiaoAuthorizeUrl
(
config
.
getClientId
(),
config
.
getRedirectUri
());
return
UrlBuilder
.
getToutiaoAuthorizeUrl
(
config
.
getClientId
(),
config
.
getRedirectUri
()
,
config
.
getState
()
);
}
}
}
}
src/main/java/me/zhyd/oauth/request/AuthWeChatRequest.java
浏览文件 @
80329c24
...
@@ -24,7 +24,7 @@ public class AuthWeChatRequest extends BaseAuthRequest {
...
@@ -24,7 +24,7 @@ public class AuthWeChatRequest extends BaseAuthRequest {
/**
/**
* 微信的特殊性,此时返回的信息同时包含 openid 和 access_token
* 微信的特殊性,此时返回的信息同时包含 openid 和 access_token
*
*
* @param
code 授权码
* @param
authCallback 回调返回的参数
* @return 所有信息
* @return 所有信息
*/
*/
@Override
@Override
...
@@ -63,7 +63,7 @@ public class AuthWeChatRequest extends BaseAuthRequest {
...
@@ -63,7 +63,7 @@ public class AuthWeChatRequest extends BaseAuthRequest {
*/
*/
@Override
@Override
public
String
authorize
()
{
public
String
authorize
()
{
return
UrlBuilder
.
getWeChatAuthorizeUrl
(
config
.
getClientId
(),
config
.
getRedirectUri
());
return
UrlBuilder
.
getWeChatAuthorizeUrl
(
config
.
getClientId
(),
config
.
getRedirectUri
()
,
config
.
getState
()
);
}
}
@Override
@Override
...
@@ -94,15 +94,15 @@ public class AuthWeChatRequest extends BaseAuthRequest {
...
@@ -94,15 +94,15 @@ public class AuthWeChatRequest extends BaseAuthRequest {
*/
*/
private
AuthToken
getToken
(
String
accessTokenUrl
)
{
private
AuthToken
getToken
(
String
accessTokenUrl
)
{
HttpResponse
response
=
HttpRequest
.
get
(
accessTokenUrl
).
execute
();
HttpResponse
response
=
HttpRequest
.
get
(
accessTokenUrl
).
execute
();
JSONObject
o
bject
=
JSONObject
.
parseObject
(
response
.
body
());
JSONObject
accessTokenO
bject
=
JSONObject
.
parseObject
(
response
.
body
());
this
.
checkResponse
(
o
bject
);
this
.
checkResponse
(
accessTokenO
bject
);
return
AuthToken
.
builder
()
return
AuthToken
.
builder
()
.
accessToken
(
o
bject
.
getString
(
"access_token"
))
.
accessToken
(
accessTokenO
bject
.
getString
(
"access_token"
))
.
refreshToken
(
o
bject
.
getString
(
"refresh_token"
))
.
refreshToken
(
accessTokenO
bject
.
getString
(
"refresh_token"
))
.
expireIn
(
o
bject
.
getIntValue
(
"expires_in"
))
.
expireIn
(
accessTokenO
bject
.
getIntValue
(
"expires_in"
))
.
openId
(
o
bject
.
getString
(
"openid"
))
.
openId
(
accessTokenO
bject
.
getString
(
"openid"
))
.
build
();
.
build
();
}
}
}
}
src/main/java/me/zhyd/oauth/request/BaseAuthRequest.java
浏览文件 @
80329c24
...
@@ -37,7 +37,7 @@ public abstract class BaseAuthRequest implements AuthRequest {
...
@@ -37,7 +37,7 @@ public abstract class BaseAuthRequest implements AuthRequest {
@Override
@Override
public
AuthResponse
login
(
AuthCallback
authCallback
)
{
public
AuthResponse
login
(
AuthCallback
authCallback
)
{
try
{
try
{
AuthChecker
.
checkCode
(
authCallback
.
getCode
());
AuthChecker
.
checkCode
(
source
==
AuthSource
.
ALIPAY
?
authCallback
.
getAuth_code
()
:
authCallback
.
getCode
());
AuthChecker
.
checkState
(
authCallback
.
getState
(),
config
.
getState
());
AuthChecker
.
checkState
(
authCallback
.
getState
(),
config
.
getState
());
AuthToken
authToken
=
this
.
getAccessToken
(
authCallback
);
AuthToken
authToken
=
this
.
getAccessToken
(
authCallback
);
...
...
src/main/java/me/zhyd/oauth/utils/UrlBuilder.java
浏览文件 @
80329c24
...
@@ -29,31 +29,31 @@ public class UrlBuilder {
...
@@ -29,31 +29,31 @@ public class UrlBuilder {
private
static
final
String
GITEE_USER_INFO_PATTERN
=
"{0}?access_token={1}"
;
private
static
final
String
GITEE_USER_INFO_PATTERN
=
"{0}?access_token={1}"
;
private
static
final
String
GITEE_AUTHORIZE_PATTERN
=
"{0}?client_id={1}&response_type=code&redirect_uri={2}&state={3}"
;
private
static
final
String
GITEE_AUTHORIZE_PATTERN
=
"{0}?client_id={1}&response_type=code&redirect_uri={2}&state={3}"
;
private
static
final
String
DING_TALK_QRCONNECT_PATTERN
=
"{0}?appid={1}&response_type=code&scope=snsapi_login&
state=STATE&redirect_uri={2
}"
;
private
static
final
String
DING_TALK_QRCONNECT_PATTERN
=
"{0}?appid={1}&response_type=code&scope=snsapi_login&
redirect_uri={2}&state={3
}"
;
private
static
final
String
DING_TALK_USER_INFO_PATTERN
=
"{0}?signature={1}×tamp={2}&accessKey={3}"
;
private
static
final
String
DING_TALK_USER_INFO_PATTERN
=
"{0}?signature={1}×tamp={2}&accessKey={3}"
;
private
static
final
String
BAIDU_ACCESS_TOKEN_PATTERN
=
"{0}?client_id={1}&client_secret={2}&grant_type=authorization_code&code={3}&redirect_uri={4}"
;
private
static
final
String
BAIDU_ACCESS_TOKEN_PATTERN
=
"{0}?client_id={1}&client_secret={2}&grant_type=authorization_code&code={3}&redirect_uri={4}"
;
private
static
final
String
BAIDU_USER_INFO_PATTERN
=
"{0}?access_token={1}"
;
private
static
final
String
BAIDU_USER_INFO_PATTERN
=
"{0}?access_token={1}"
;
private
static
final
String
BAIDU_AUTHORIZE_PATTERN
=
"{0}?client_id={1}&response_type=code&redirect_uri={2}&display=popup"
;
private
static
final
String
BAIDU_AUTHORIZE_PATTERN
=
"{0}?client_id={1}&response_type=code&redirect_uri={2}&display=popup
&state={3}
"
;
private
static
final
String
BAIDU_REVOKE_PATTERN
=
"{0}?access_token={1}"
;
private
static
final
String
BAIDU_REVOKE_PATTERN
=
"{0}?access_token={1}"
;
private
static
final
String
CSDN_ACCESS_TOKEN_PATTERN
=
"{0}?client_id={1}&client_secret={2}&grant_type=authorization_code&code={3}&redirect_uri={4}"
;
private
static
final
String
CSDN_ACCESS_TOKEN_PATTERN
=
"{0}?client_id={1}&client_secret={2}&grant_type=authorization_code&code={3}&redirect_uri={4}"
;
private
static
final
String
CSDN_USER_INFO_PATTERN
=
"{0}?access_token={1}"
;
private
static
final
String
CSDN_USER_INFO_PATTERN
=
"{0}?access_token={1}"
;
private
static
final
String
CSDN_AUTHORIZE_PATTERN
=
"{0}?client_id={1}&response_type=code&redirect_uri={2}"
;
private
static
final
String
CSDN_AUTHORIZE_PATTERN
=
"{0}?client_id={1}&response_type=code&redirect_uri={2}
&state={3}
"
;
private
static
final
String
CODING_ACCESS_TOKEN_PATTERN
=
"{0}?client_id={1}&client_secret={2}&grant_type=authorization_code&code={3}"
;
private
static
final
String
CODING_ACCESS_TOKEN_PATTERN
=
"{0}?client_id={1}&client_secret={2}&grant_type=authorization_code&code={3}"
;
private
static
final
String
CODING_USER_INFO_PATTERN
=
"{0}?access_token={1}"
;
private
static
final
String
CODING_USER_INFO_PATTERN
=
"{0}?access_token={1}"
;
private
static
final
String
CODING_AUTHORIZE_PATTERN
=
"{0}?client_id={1}&response_type=code&redirect_uri={2}&scope=user"
;
private
static
final
String
CODING_AUTHORIZE_PATTERN
=
"{0}?client_id={1}&response_type=code&redirect_uri={2}&scope=user
&state={3}
"
;
private
static
final
String
TENCENT_ACCESS_TOKEN_PATTERN
=
"{0}?client_id={1}&client_secret={2}&grant_type=authorization_code&code={3}"
;
private
static
final
String
TENCENT_ACCESS_TOKEN_PATTERN
=
"{0}?client_id={1}&client_secret={2}&grant_type=authorization_code&code={3}"
;
private
static
final
String
TENCENT_USER_INFO_PATTERN
=
"{0}?access_token={1}"
;
private
static
final
String
TENCENT_USER_INFO_PATTERN
=
"{0}?access_token={1}"
;
private
static
final
String
TENCENT_AUTHORIZE_PATTERN
=
"{0}?client_id={1}&response_type=code&redirect_uri={2}&scope=user"
;
private
static
final
String
TENCENT_AUTHORIZE_PATTERN
=
"{0}?client_id={1}&response_type=code&redirect_uri={2}&scope=user
&state={3}
"
;
private
static
final
String
OSCHINA_ACCESS_TOKEN_PATTERN
=
"{0}?client_id={1}&client_secret={2}&grant_type=authorization_code&code={3}&redirect_uri={4}&dataType=json"
;
private
static
final
String
OSCHINA_ACCESS_TOKEN_PATTERN
=
"{0}?client_id={1}&client_secret={2}&grant_type=authorization_code&code={3}&redirect_uri={4}&dataType=json"
;
private
static
final
String
OSCHINA_USER_INFO_PATTERN
=
"{0}?access_token={1}&dataType=json"
;
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
OSCHINA_AUTHORIZE_PATTERN
=
"{0}?client_id={1}&response_type=code&redirect_uri={2}
&state={3}
"
;
private
static
final
String
ALIPAY_AUTHORIZE_PATTERN
=
"{0}?app_id={1}&scope=auth_user&redirect_uri={2}&state=
init
"
;
private
static
final
String
ALIPAY_AUTHORIZE_PATTERN
=
"{0}?app_id={1}&scope=auth_user&redirect_uri={2}&state=
{3}
"
;
private
static
final
String
QQ_ACCESS_TOKEN_PATTERN
=
"{0}?client_id={1}&client_secret={2}&grant_type=authorization_code&code={3}&redirect_uri={4}"
;
private
static
final
String
QQ_ACCESS_TOKEN_PATTERN
=
"{0}?client_id={1}&client_secret={2}&grant_type=authorization_code&code={3}&redirect_uri={4}"
;
private
static
final
String
QQ_USER_INFO_PATTERN
=
"{0}?oauth_consumer_key={1}&access_token={2}&openid={3}"
;
private
static
final
String
QQ_USER_INFO_PATTERN
=
"{0}?oauth_consumer_key={1}&access_token={2}&openid={3}"
;
...
@@ -215,10 +215,11 @@ public class UrlBuilder {
...
@@ -215,10 +215,11 @@ public class UrlBuilder {
*
*
* @param clientId 钉钉 应用的App Id
* @param clientId 钉钉 应用的App Id
* @param redirectUrl 钉钉 应用授权成功后的回调地址
* @param redirectUrl 钉钉 应用授权成功后的回调地址
* @param state 随机字符串,用于保持会话状态,防止CSRF攻击
* @return full url
* @return full url
*/
*/
public
static
String
getDingTalkQrConnectUrl
(
String
clientId
,
String
redirectUrl
)
{
public
static
String
getDingTalkQrConnectUrl
(
String
clientId
,
String
redirectUrl
,
String
state
)
{
return
MessageFormat
.
format
(
DING_TALK_QRCONNECT_PATTERN
,
AuthSource
.
DINGTALK
.
authorize
(),
clientId
,
redirectUrl
);
return
MessageFormat
.
format
(
DING_TALK_QRCONNECT_PATTERN
,
AuthSource
.
DINGTALK
.
authorize
(),
clientId
,
redirectUrl
,
getState
(
state
)
);
}
}
/**
/**
...
@@ -261,10 +262,11 @@ public class UrlBuilder {
...
@@ -261,10 +262,11 @@ public class UrlBuilder {
*
*
* @param clientId baidu 应用的API Key
* @param clientId baidu 应用的API Key
* @param redirectUrl baidu 应用授权成功后的回调地址
* @param redirectUrl baidu 应用授权成功后的回调地址
* @param state 随机字符串,用于保持会话状态,防止CSRF攻击
* @return json
* @return json
*/
*/
public
static
String
getBaiduAuthorizeUrl
(
String
clientId
,
String
redirectUrl
)
{
public
static
String
getBaiduAuthorizeUrl
(
String
clientId
,
String
redirectUrl
,
String
state
)
{
return
MessageFormat
.
format
(
BAIDU_AUTHORIZE_PATTERN
,
AuthSource
.
BAIDU
.
authorize
(),
clientId
,
redirectUrl
);
return
MessageFormat
.
format
(
BAIDU_AUTHORIZE_PATTERN
,
AuthSource
.
BAIDU
.
authorize
(),
clientId
,
redirectUrl
,
getState
(
state
)
);
}
}
/**
/**
...
@@ -305,10 +307,11 @@ public class UrlBuilder {
...
@@ -305,10 +307,11 @@ public class UrlBuilder {
*
*
* @param clientId csdn 应用的Client ID
* @param clientId csdn 应用的Client ID
* @param redirectUrl csdn 应用授权成功后的回调地址
* @param redirectUrl csdn 应用授权成功后的回调地址
* @param state 随机字符串,用于保持会话状态,防止CSRF攻击
* @return full url
* @return full url
*/
*/
public
static
String
getCsdnAuthorizeUrl
(
String
clientId
,
String
redirectUrl
)
{
public
static
String
getCsdnAuthorizeUrl
(
String
clientId
,
String
redirectUrl
,
String
state
)
{
return
MessageFormat
.
format
(
CSDN_AUTHORIZE_PATTERN
,
AuthSource
.
CSDN
.
authorize
(),
clientId
,
redirectUrl
);
return
MessageFormat
.
format
(
CSDN_AUTHORIZE_PATTERN
,
AuthSource
.
CSDN
.
authorize
(),
clientId
,
redirectUrl
,
getState
(
state
)
);
}
}
/**
/**
...
@@ -338,10 +341,11 @@ public class UrlBuilder {
...
@@ -338,10 +341,11 @@ public class UrlBuilder {
*
*
* @param clientId coding 应用的Client ID
* @param clientId coding 应用的Client ID
* @param redirectUrl coding 应用授权成功后的回调地址
* @param redirectUrl coding 应用授权成功后的回调地址
* @param state 随机字符串,用于保持会话状态,防止CSRF攻击
* @return full url
* @return full url
*/
*/
public
static
String
getCodingAuthorizeUrl
(
String
clientId
,
String
redirectUrl
)
{
public
static
String
getCodingAuthorizeUrl
(
String
clientId
,
String
redirectUrl
,
String
state
)
{
return
MessageFormat
.
format
(
CODING_AUTHORIZE_PATTERN
,
AuthSource
.
CODING
.
authorize
(),
clientId
,
redirectUrl
);
return
MessageFormat
.
format
(
CODING_AUTHORIZE_PATTERN
,
AuthSource
.
CODING
.
authorize
(),
clientId
,
redirectUrl
,
getState
(
state
)
);
}
}
/**
/**
...
@@ -371,10 +375,11 @@ public class UrlBuilder {
...
@@ -371,10 +375,11 @@ public class UrlBuilder {
*
*
* @param clientId coding 应用的Client ID
* @param clientId coding 应用的Client ID
* @param redirectUrl coding 应用授权成功后的回调地址
* @param redirectUrl coding 应用授权成功后的回调地址
* @param state 随机字符串,用于保持会话状态,防止CSRF攻击
* @return full url
* @return full url
*/
*/
public
static
String
getTencentCloudAuthorizeUrl
(
String
clientId
,
String
redirectUrl
)
{
public
static
String
getTencentCloudAuthorizeUrl
(
String
clientId
,
String
redirectUrl
,
String
state
)
{
return
MessageFormat
.
format
(
TENCENT_AUTHORIZE_PATTERN
,
AuthSource
.
TENCENT_CLOUD
.
authorize
(),
clientId
,
redirectUrl
);
return
MessageFormat
.
format
(
TENCENT_AUTHORIZE_PATTERN
,
AuthSource
.
TENCENT_CLOUD
.
authorize
(),
clientId
,
redirectUrl
,
getState
(
state
)
);
}
}
/**
/**
...
@@ -405,10 +410,11 @@ public class UrlBuilder {
...
@@ -405,10 +410,11 @@ public class UrlBuilder {
*
*
* @param clientId oschina 应用的Client ID
* @param clientId oschina 应用的Client ID
* @param redirectUrl oschina 应用授权成功后的回调地址
* @param redirectUrl oschina 应用授权成功后的回调地址
* @param state 随机字符串,用于保持会话状态,防止CSRF攻击
* @return full url
* @return full url
*/
*/
public
static
String
getOschinaAuthorizeUrl
(
String
clientId
,
String
redirectUrl
)
{
public
static
String
getOschinaAuthorizeUrl
(
String
clientId
,
String
redirectUrl
,
String
state
)
{
return
MessageFormat
.
format
(
OSCHINA_AUTHORIZE_PATTERN
,
AuthSource
.
OSCHINA
.
authorize
(),
clientId
,
redirectUrl
);
return
MessageFormat
.
format
(
OSCHINA_AUTHORIZE_PATTERN
,
AuthSource
.
OSCHINA
.
authorize
(),
clientId
,
redirectUrl
,
getState
(
state
)
);
}
}
/**
/**
...
@@ -441,10 +447,11 @@ public class UrlBuilder {
...
@@ -441,10 +447,11 @@ public class UrlBuilder {
*
*
* @param clientId qq 应用的Client ID
* @param clientId qq 应用的Client ID
* @param redirectUrl qq 应用授权成功后的回调地址
* @param redirectUrl qq 应用授权成功后的回调地址
* @param state 随机字符串,用于保持会话状态,防止CSRF攻击
* @return full url
* @return full url
*/
*/
public
static
String
getQqAuthorizeUrl
(
String
clientId
,
String
redirectUrl
)
{
public
static
String
getQqAuthorizeUrl
(
String
clientId
,
String
redirectUrl
,
String
state
)
{
return
MessageFormat
.
format
(
QQ_AUTHORIZE_PATTERN
,
AuthSource
.
QQ
.
authorize
(),
clientId
,
redirectUrl
,
System
.
currentTimeMillis
(
));
return
MessageFormat
.
format
(
QQ_AUTHORIZE_PATTERN
,
AuthSource
.
QQ
.
authorize
(),
clientId
,
redirectUrl
,
getState
(
state
));
}
}
/**
/**
...
@@ -464,10 +471,11 @@ public class UrlBuilder {
...
@@ -464,10 +471,11 @@ public class UrlBuilder {
*
*
* @param clientId alipay 应用的Client ID
* @param clientId alipay 应用的Client ID
* @param redirectUrl alipay 应用授权成功后的回调地址
* @param redirectUrl alipay 应用授权成功后的回调地址
* @param state 随机字符串,用于保持会话状态,防止CSRF攻击
* @return full url
* @return full url
*/
*/
public
static
String
getAlipayAuthorizeUrl
(
String
clientId
,
String
redirectUrl
)
{
public
static
String
getAlipayAuthorizeUrl
(
String
clientId
,
String
redirectUrl
,
String
state
)
{
return
MessageFormat
.
format
(
ALIPAY_AUTHORIZE_PATTERN
,
AuthSource
.
ALIPAY
.
authorize
(),
clientId
,
redirectUrl
);
return
MessageFormat
.
format
(
ALIPAY_AUTHORIZE_PATTERN
,
AuthSource
.
ALIPAY
.
authorize
(),
clientId
,
redirectUrl
,
getState
(
state
)
);
}
}
/**
/**
...
@@ -475,11 +483,11 @@ public class UrlBuilder {
...
@@ -475,11 +483,11 @@ public class UrlBuilder {
*
*
* @param clientId 微信 应用的appid
* @param clientId 微信 应用的appid
* @param redirectUrl 微信 应用授权成功后的回调地址
* @param redirectUrl 微信 应用授权成功后的回调地址
* @param state 随机字符串,用于保持会话状态,防止CSRF攻击
* @return full url
* @return full url
*/
*/
public
static
String
getWeChatAuthorizeUrl
(
String
clientId
,
String
redirectUrl
)
{
public
static
String
getWeChatAuthorizeUrl
(
String
clientId
,
String
redirectUrl
,
String
state
)
{
return
MessageFormat
.
format
(
WECHAT_AUTHORIZE_PATTERN
,
AuthSource
.
WECHAT
.
authorize
(),
clientId
,
redirectUrl
,
System
return
MessageFormat
.
format
(
WECHAT_AUTHORIZE_PATTERN
,
AuthSource
.
WECHAT
.
authorize
(),
clientId
,
redirectUrl
,
getState
(
state
));
.
currentTimeMillis
());
}
}
/**
/**
...
@@ -534,11 +542,11 @@ public class UrlBuilder {
...
@@ -534,11 +542,11 @@ public class UrlBuilder {
*
*
* @param clientId Taobao 应用的Client ID
* @param clientId Taobao 应用的Client ID
* @param redirectUrl Taobao 应用授权成功后的回调地址
* @param redirectUrl Taobao 应用授权成功后的回调地址
* @param state 随机字符串,用于保持会话状态,防止CSRF攻击
* @return full url
* @return full url
*/
*/
public
static
String
getTaobaoAuthorizeUrl
(
String
clientId
,
String
redirectUrl
)
{
public
static
String
getTaobaoAuthorizeUrl
(
String
clientId
,
String
redirectUrl
,
String
state
)
{
return
MessageFormat
.
format
(
TAOBAO_AUTHORIZE_PATTERN
,
AuthSource
.
TAOBAO
.
authorize
(),
clientId
,
redirectUrl
,
System
return
MessageFormat
.
format
(
TAOBAO_AUTHORIZE_PATTERN
,
AuthSource
.
TAOBAO
.
authorize
(),
clientId
,
redirectUrl
,
getState
(
state
));
.
currentTimeMillis
());
}
}
/**
/**
...
@@ -546,11 +554,11 @@ public class UrlBuilder {
...
@@ -546,11 +554,11 @@ public class UrlBuilder {
*
*
* @param clientId google 应用的Client ID
* @param clientId google 应用的Client ID
* @param redirectUrl google 应用授权成功后的回调地址
* @param redirectUrl google 应用授权成功后的回调地址
* @param state 随机字符串,用于保持会话状态,防止CSRF攻击
* @return full url
* @return full url
*/
*/
public
static
String
getGoogleAuthorizeUrl
(
String
clientId
,
String
redirectUrl
)
{
public
static
String
getGoogleAuthorizeUrl
(
String
clientId
,
String
redirectUrl
,
String
state
)
{
return
MessageFormat
.
format
(
GOOGLE_AUTHORIZE_PATTERN
,
AuthSource
.
GOOGLE
.
authorize
(),
clientId
,
redirectUrl
,
System
return
MessageFormat
.
format
(
GOOGLE_AUTHORIZE_PATTERN
,
AuthSource
.
GOOGLE
.
authorize
(),
clientId
,
redirectUrl
,
getState
(
state
));
.
currentTimeMillis
());
}
}
/**
/**
...
@@ -581,11 +589,11 @@ public class UrlBuilder {
...
@@ -581,11 +589,11 @@ public class UrlBuilder {
*
*
* @param clientId Facebook 应用的Client ID
* @param clientId Facebook 应用的Client ID
* @param redirectUrl Facebook 应用授权成功后的回调地址
* @param redirectUrl Facebook 应用授权成功后的回调地址
* @param state 随机字符串,用于保持会话状态,防止CSRF攻击
* @return full url
* @return full url
*/
*/
public
static
String
getFacebookAuthorizeUrl
(
String
clientId
,
String
redirectUrl
)
{
public
static
String
getFacebookAuthorizeUrl
(
String
clientId
,
String
redirectUrl
,
String
state
)
{
return
MessageFormat
.
format
(
FACEBOOK_AUTHORIZE_PATTERN
,
AuthSource
.
FACEBOOK
.
authorize
(),
clientId
,
redirectUrl
,
System
return
MessageFormat
.
format
(
FACEBOOK_AUTHORIZE_PATTERN
,
AuthSource
.
FACEBOOK
.
authorize
(),
clientId
,
redirectUrl
,
getState
(
state
));
.
currentTimeMillis
());
}
}
/**
/**
...
@@ -616,11 +624,11 @@ public class UrlBuilder {
...
@@ -616,11 +624,11 @@ public class UrlBuilder {
*
*
* @param clientId Douyin 应用的Client ID
* @param clientId Douyin 应用的Client ID
* @param redirectUrl Douyin 应用授权成功后的回调地址
* @param redirectUrl Douyin 应用授权成功后的回调地址
* @param state 随机字符串,用于保持会话状态,防止CSRF攻击
* @return full url
* @return full url
*/
*/
public
static
String
getDouyinAuthorizeUrl
(
String
clientId
,
String
redirectUrl
)
{
public
static
String
getDouyinAuthorizeUrl
(
String
clientId
,
String
redirectUrl
,
String
state
)
{
return
MessageFormat
.
format
(
DOUYIN_AUTHORIZE_PATTERN
,
AuthSource
.
DOUYIN
.
authorize
(),
clientId
,
redirectUrl
,
System
return
MessageFormat
.
format
(
DOUYIN_AUTHORIZE_PATTERN
,
AuthSource
.
DOUYIN
.
authorize
(),
clientId
,
redirectUrl
,
getState
(
state
));
.
currentTimeMillis
());
}
}
/**
/**
...
@@ -662,11 +670,11 @@ public class UrlBuilder {
...
@@ -662,11 +670,11 @@ public class UrlBuilder {
*
*
* @param clientId Linkedin 应用的Client ID
* @param clientId Linkedin 应用的Client ID
* @param redirectUrl Linkedin 应用授权成功后的回调地址
* @param redirectUrl Linkedin 应用授权成功后的回调地址
* @param state 随机字符串,用于保持会话状态,防止CSRF攻击
* @return full url
* @return full url
*/
*/
public
static
String
getLinkedinAuthorizeUrl
(
String
clientId
,
String
redirectUrl
)
{
public
static
String
getLinkedinAuthorizeUrl
(
String
clientId
,
String
redirectUrl
,
String
state
)
{
return
MessageFormat
.
format
(
LINKEDIN_AUTHORIZE_PATTERN
,
AuthSource
.
LINKEDIN
.
authorize
(),
clientId
,
redirectUrl
,
System
return
MessageFormat
.
format
(
LINKEDIN_AUTHORIZE_PATTERN
,
AuthSource
.
LINKEDIN
.
authorize
(),
clientId
,
redirectUrl
,
state
);
.
currentTimeMillis
());
}
}
/**
/**
...
@@ -708,11 +716,11 @@ public class UrlBuilder {
...
@@ -708,11 +716,11 @@ public class UrlBuilder {
*
*
* @param clientId 微软 应用的Client ID
* @param clientId 微软 应用的Client ID
* @param redirectUrl 微软 应用授权成功后的回调地址
* @param redirectUrl 微软 应用授权成功后的回调地址
* @param state 随机字符串,用于保持会话状态,防止CSRF攻击
* @return full url
* @return full url
*/
*/
public
static
String
getMicrosoftAuthorizeUrl
(
String
clientId
,
String
redirectUrl
)
{
public
static
String
getMicrosoftAuthorizeUrl
(
String
clientId
,
String
redirectUrl
,
String
state
)
{
return
MessageFormat
.
format
(
MICROSOFT_AUTHORIZE_PATTERN
,
AuthSource
.
MICROSOFT
.
authorize
(),
clientId
,
redirectUrl
,
System
return
MessageFormat
.
format
(
MICROSOFT_AUTHORIZE_PATTERN
,
AuthSource
.
MICROSOFT
.
authorize
(),
clientId
,
redirectUrl
,
getState
(
state
));
.
currentTimeMillis
());
}
}
/**
/**
...
@@ -755,10 +763,11 @@ public class UrlBuilder {
...
@@ -755,10 +763,11 @@ public class UrlBuilder {
*
*
* @param clientId 小米 应用的Client ID
* @param clientId 小米 应用的Client ID
* @param redirectUrl 小米 应用授权成功后的回调地址
* @param redirectUrl 小米 应用授权成功后的回调地址
* @param state 随机字符串,用于保持会话状态,防止CSRF攻击
* @return full url
* @return full url
*/
*/
public
static
String
getMiAuthorizeUrl
(
String
clientId
,
String
redirectUrl
)
{
public
static
String
getMiAuthorizeUrl
(
String
clientId
,
String
redirectUrl
,
String
state
)
{
return
MessageFormat
.
format
(
MI_AUTHORIZE_PATTERN
,
AuthSource
.
MI
.
authorize
(),
clientId
,
redirectUrl
,
System
.
currentTimeMillis
(
));
return
MessageFormat
.
format
(
MI_AUTHORIZE_PATTERN
,
AuthSource
.
MI
.
authorize
(),
clientId
,
redirectUrl
,
getState
(
state
));
}
}
/**
/**
...
@@ -803,11 +812,11 @@ public class UrlBuilder {
...
@@ -803,11 +812,11 @@ public class UrlBuilder {
*
*
* @param clientId 今日头条 应用的Client ID
* @param clientId 今日头条 应用的Client ID
* @param redirectUrl 今日头条 应用授权成功后的回调地址
* @param redirectUrl 今日头条 应用授权成功后的回调地址
* @param state 随机字符串,用于保持会话状态,防止CSRF攻击
* @return full url
* @return full url
*/
*/
public
static
String
getToutiaoAuthorizeUrl
(
String
clientId
,
String
redirectUrl
)
{
public
static
String
getToutiaoAuthorizeUrl
(
String
clientId
,
String
redirectUrl
,
String
state
)
{
return
MessageFormat
.
format
(
TOUTIAO_AUTHORIZE_PATTERN
,
AuthSource
.
TOUTIAO
.
authorize
(),
clientId
,
redirectUrl
,
System
return
MessageFormat
.
format
(
TOUTIAO_AUTHORIZE_PATTERN
,
AuthSource
.
TOUTIAO
.
authorize
(),
clientId
,
redirectUrl
,
getState
(
state
));
.
currentTimeMillis
());
}
}
/**
/**
...
...
src/test/java/me/zhyd/oauth/AuthRequestTest.java
浏览文件 @
80329c24
package
me.zhyd.oauth
;
package
me.zhyd.oauth
;
import
me.zhyd.oauth.config.AuthConfig
;
import
me.zhyd.oauth.config.AuthConfig
;
import
me.zhyd.oauth.model.AuthCallback
;
import
me.zhyd.oauth.model.AuthResponse
;
import
me.zhyd.oauth.model.AuthResponse
;
import
me.zhyd.oauth.request.*
;
import
me.zhyd.oauth.request.*
;
import
org.junit.Test
;
import
org.junit.Test
;
...
@@ -18,11 +19,12 @@ public class AuthRequestTest {
...
@@ -18,11 +19,12 @@ public class AuthRequestTest {
.
clientId
(
"clientId"
)
.
clientId
(
"clientId"
)
.
clientSecret
(
"clientSecret"
)
.
clientSecret
(
"clientSecret"
)
.
redirectUri
(
"redirectUri"
)
.
redirectUri
(
"redirectUri"
)
.
state
(
"state"
)
.
build
());
.
build
());
// 返回授权页面,可自行调整
// 返回授权页面,可自行调整
authRequest
.
authorize
();
authRequest
.
authorize
();
// 授权登录后会返回一个code,用这个code进行登录
// 授权登录后会返回一个code,用这个code进行登录
authRequest
.
login
(
"code"
);
authRequest
.
login
(
new
AuthCallback
()
);
}
}
@Test
@Test
...
@@ -31,11 +33,12 @@ public class AuthRequestTest {
...
@@ -31,11 +33,12 @@ public class AuthRequestTest {
.
clientId
(
"clientId"
)
.
clientId
(
"clientId"
)
.
clientSecret
(
"clientSecret"
)
.
clientSecret
(
"clientSecret"
)
.
redirectUri
(
"redirectUri"
)
.
redirectUri
(
"redirectUri"
)
.
state
(
"state"
)
.
build
());
.
build
());
// 返回授权页面,可自行调整
// 返回授权页面,可自行调整
authRequest
.
authorize
();
authRequest
.
authorize
();
// 授权登录后会返回一个code,用这个code进行登录
// 授权登录后会返回一个code,用这个code进行登录
authRequest
.
login
(
"code"
);
authRequest
.
login
(
new
AuthCallback
()
);
}
}
@Test
@Test
...
@@ -48,7 +51,7 @@ public class AuthRequestTest {
...
@@ -48,7 +51,7 @@ public class AuthRequestTest {
// 返回授权页面,可自行调整
// 返回授权页面,可自行调整
authRequest
.
authorize
();
authRequest
.
authorize
();
// 授权登录后会返回一个code,用这个code进行登录
// 授权登录后会返回一个code,用这个code进行登录
authRequest
.
login
(
"code"
);
authRequest
.
login
(
new
AuthCallback
()
);
}
}
@Test
@Test
...
@@ -57,11 +60,12 @@ public class AuthRequestTest {
...
@@ -57,11 +60,12 @@ public class AuthRequestTest {
.
clientId
(
"clientId"
)
.
clientId
(
"clientId"
)
.
clientSecret
(
"clientSecret"
)
.
clientSecret
(
"clientSecret"
)
.
redirectUri
(
"redirectUri"
)
.
redirectUri
(
"redirectUri"
)
.
state
(
"state"
)
.
build
());
.
build
());
// 返回授权页面,可自行调整
// 返回授权页面,可自行调整
String
url
=
authRequest
.
authorize
();
String
url
=
authRequest
.
authorize
();
// 授权登录后会返回一个code,用这个code进行登录
// 授权登录后会返回一个code,用这个code进行登录
authRequest
.
login
(
"code"
);
authRequest
.
login
(
new
AuthCallback
()
);
}
}
@Test
@Test
...
@@ -70,11 +74,12 @@ public class AuthRequestTest {
...
@@ -70,11 +74,12 @@ public class AuthRequestTest {
.
clientId
(
"clientId"
)
.
clientId
(
"clientId"
)
.
clientSecret
(
"clientSecret"
)
.
clientSecret
(
"clientSecret"
)
.
redirectUri
(
"redirectUri"
)
.
redirectUri
(
"redirectUri"
)
.
state
(
"state"
)
.
build
());
.
build
());
// 返回授权页面,可自行调整
// 返回授权页面,可自行调整
String
url
=
authRequest
.
authorize
();
String
url
=
authRequest
.
authorize
();
// 授权登录后会返回一个code,用这个code进行登录
// 授权登录后会返回一个code,用这个code进行登录
authRequest
.
login
(
"code"
);
authRequest
.
login
(
new
AuthCallback
()
);
}
}
@Test
@Test
...
@@ -83,11 +88,12 @@ public class AuthRequestTest {
...
@@ -83,11 +88,12 @@ public class AuthRequestTest {
.
clientId
(
"clientId"
)
.
clientId
(
"clientId"
)
.
clientSecret
(
"clientSecret"
)
.
clientSecret
(
"clientSecret"
)
.
redirectUri
(
"redirectUri"
)
.
redirectUri
(
"redirectUri"
)
.
state
(
"state"
)
.
build
());
.
build
());
// 返回授权页面,可自行调整
// 返回授权页面,可自行调整
String
url
=
authRequest
.
authorize
();
String
url
=
authRequest
.
authorize
();
// 授权登录后会返回一个code,用这个code进行登录
// 授权登录后会返回一个code,用这个code进行登录
authRequest
.
login
(
"code"
);
authRequest
.
login
(
new
AuthCallback
()
);
}
}
@Test
@Test
...
@@ -96,11 +102,12 @@ public class AuthRequestTest {
...
@@ -96,11 +102,12 @@ public class AuthRequestTest {
.
clientId
(
"clientId"
)
.
clientId
(
"clientId"
)
.
clientSecret
(
"clientSecret"
)
.
clientSecret
(
"clientSecret"
)
.
redirectUri
(
"redirectUri"
)
.
redirectUri
(
"redirectUri"
)
.
state
(
"state"
)
.
build
());
.
build
());
// 返回授权页面,可自行调整
// 返回授权页面,可自行调整
String
url
=
authRequest
.
authorize
();
String
url
=
authRequest
.
authorize
();
// 授权登录后会返回一个code,用这个code进行登录
// 授权登录后会返回一个code,用这个code进行登录
authRequest
.
login
(
"code"
);
authRequest
.
login
(
new
AuthCallback
()
);
}
}
@Test
@Test
...
@@ -109,11 +116,26 @@ public class AuthRequestTest {
...
@@ -109,11 +116,26 @@ public class AuthRequestTest {
.
clientId
(
"clientId"
)
.
clientId
(
"clientId"
)
.
clientSecret
(
"clientSecret"
)
.
clientSecret
(
"clientSecret"
)
.
redirectUri
(
"redirectUri"
)
.
redirectUri
(
"redirectUri"
)
.
state
(
"state"
)
.
build
());
.
build
());
// 返回授权页面,可自行调整
// 返回授权页面,可自行调整
String
url
=
authRequest
.
authorize
();
String
url
=
authRequest
.
authorize
();
// 授权登录后会返回一个code,用这个code进行登录
// 授权登录后会返回一个code,用这个code进行登录
authRequest
.
login
(
"code"
);
authRequest
.
login
(
new
AuthCallback
());
}
@Test
public
void
alipayTest
()
{
AuthRequest
authRequest
=
new
AuthAlipayRequest
(
AuthConfig
.
builder
()
.
clientId
(
"clientId"
)
.
clientSecret
(
"clientSecret"
)
.
redirectUri
(
"redirectUri"
)
.
state
(
"state"
)
.
build
());
// 返回授权页面,可自行调整
String
url
=
authRequest
.
authorize
();
// 授权登录后会返回一个code,用这个code进行登录
AuthResponse
login
=
authRequest
.
login
(
new
AuthCallback
());
}
}
@Test
@Test
...
@@ -122,11 +144,12 @@ public class AuthRequestTest {
...
@@ -122,11 +144,12 @@ public class AuthRequestTest {
.
clientId
(
"clientId"
)
.
clientId
(
"clientId"
)
.
clientSecret
(
"clientSecret"
)
.
clientSecret
(
"clientSecret"
)
.
redirectUri
(
"redirectUri"
)
.
redirectUri
(
"redirectUri"
)
.
state
(
"state"
)
.
build
());
.
build
());
// 返回授权页面,可自行调整
// 返回授权页面,可自行调整
String
url
=
authRequest
.
authorize
();
String
url
=
authRequest
.
authorize
();
// 授权登录后会返回一个code,用这个code进行登录
// 授权登录后会返回一个code,用这个code进行登录
AuthResponse
login
=
authRequest
.
login
(
"code"
);
AuthResponse
login
=
authRequest
.
login
(
new
AuthCallback
()
);
}
}
@Test
@Test
...
@@ -135,11 +158,26 @@ public class AuthRequestTest {
...
@@ -135,11 +158,26 @@ public class AuthRequestTest {
.
clientId
(
"clientId"
)
.
clientId
(
"clientId"
)
.
clientSecret
(
"clientSecret"
)
.
clientSecret
(
"clientSecret"
)
.
redirectUri
(
"redirectUri"
)
.
redirectUri
(
"redirectUri"
)
.
state
(
"state"
)
.
build
());
.
build
());
// 返回授权页面,可自行调整
// 返回授权页面,可自行调整
String
url
=
authRequest
.
authorize
();
String
url
=
authRequest
.
authorize
();
// 授权登录后会返回一个code,用这个code进行登录
// 授权登录后会返回一个code,用这个code进行登录
AuthResponse
login
=
authRequest
.
login
(
"code"
);
AuthResponse
login
=
authRequest
.
login
(
new
AuthCallback
());
}
@Test
public
void
taobaoTest
()
{
AuthRequest
authRequest
=
new
AuthTaobaoRequest
(
AuthConfig
.
builder
()
.
clientId
(
"clientId"
)
.
clientSecret
(
"clientSecret"
)
.
redirectUri
(
"redirectUri"
)
.
state
(
"state"
)
.
build
());
// 返回授权页面,可自行调整
String
url
=
authRequest
.
authorize
();
// 授权登录后会返回一个code,用这个code进行登录
AuthResponse
login
=
authRequest
.
login
(
new
AuthCallback
());
}
}
@Test
@Test
...
@@ -148,11 +186,12 @@ public class AuthRequestTest {
...
@@ -148,11 +186,12 @@ public class AuthRequestTest {
.
clientId
(
"clientId"
)
.
clientId
(
"clientId"
)
.
clientSecret
(
"clientSecret"
)
.
clientSecret
(
"clientSecret"
)
.
redirectUri
(
"redirectUri"
)
.
redirectUri
(
"redirectUri"
)
.
state
(
"state"
)
.
build
());
.
build
());
// 返回授权页面,可自行调整
// 返回授权页面,可自行调整
String
url
=
authRequest
.
authorize
();
String
url
=
authRequest
.
authorize
();
// 授权登录后会返回一个code,用这个code进行登录
// 授权登录后会返回一个code,用这个code进行登录
AuthResponse
login
=
authRequest
.
login
(
"code"
);
AuthResponse
login
=
authRequest
.
login
(
new
AuthCallback
()
);
}
}
@Test
@Test
...
@@ -161,11 +200,40 @@ public class AuthRequestTest {
...
@@ -161,11 +200,40 @@ public class AuthRequestTest {
.
clientId
(
"clientId"
)
.
clientId
(
"clientId"
)
.
clientSecret
(
"clientSecret"
)
.
clientSecret
(
"clientSecret"
)
.
redirectUri
(
"redirectUri"
)
.
redirectUri
(
"redirectUri"
)
.
state
(
"state"
)
.
build
());
// 返回授权页面,可自行调整
String
url
=
authRequest
.
authorize
();
// 授权登录后会返回一个code,用这个code进行登录
AuthResponse
login
=
authRequest
.
login
(
new
AuthCallback
());
}
@Test
public
void
douyinTest
()
{
AuthRequest
authRequest
=
new
AuthDouyinRequest
(
AuthConfig
.
builder
()
.
clientId
(
"clientId"
)
.
clientSecret
(
"clientSecret"
)
.
redirectUri
(
"redirectUri"
)
.
state
(
"state"
)
.
build
());
.
build
());
// 返回授权页面,可自行调整
// 返回授权页面,可自行调整
String
url
=
authRequest
.
authorize
();
String
url
=
authRequest
.
authorize
();
// 授权登录后会返回一个code,用这个code进行登录
// 授权登录后会返回一个code,用这个code进行登录
AuthResponse
login
=
authRequest
.
login
(
"code"
);
AuthResponse
login
=
authRequest
.
login
(
new
AuthCallback
());
}
@Test
public
void
linkedinTest
()
{
AuthRequest
authRequest
=
new
AuthLinkedinRequest
(
AuthConfig
.
builder
()
.
clientId
(
"clientId"
)
.
clientSecret
(
"clientSecret"
)
.
redirectUri
(
"redirectUri"
)
.
state
(
"state"
)
.
build
());
// 返回授权页面,可自行调整
String
url
=
authRequest
.
authorize
();
// 授权登录后会返回一个code,用这个code进行登录
AuthResponse
login
=
authRequest
.
login
(
new
AuthCallback
());
}
}
@Test
@Test
...
@@ -174,11 +242,12 @@ public class AuthRequestTest {
...
@@ -174,11 +242,12 @@ public class AuthRequestTest {
.
clientId
(
"clientId"
)
.
clientId
(
"clientId"
)
.
clientSecret
(
"clientSecret"
)
.
clientSecret
(
"clientSecret"
)
.
redirectUri
(
"redirectUri"
)
.
redirectUri
(
"redirectUri"
)
.
state
(
"state"
)
.
build
());
.
build
());
// 返回授权页面,可自行调整
// 返回授权页面,可自行调整
String
url
=
authRequest
.
authorize
();
String
url
=
authRequest
.
authorize
();
// 授权登录后会返回一个code,用这个code进行登录
// 授权登录后会返回一个code,用这个code进行登录
AuthResponse
login
=
authRequest
.
login
(
"code"
);
AuthResponse
login
=
authRequest
.
login
(
new
AuthCallback
()
);
}
}
@Test
@Test
...
@@ -187,10 +256,25 @@ public class AuthRequestTest {
...
@@ -187,10 +256,25 @@ public class AuthRequestTest {
.
clientId
(
"clientId"
)
.
clientId
(
"clientId"
)
.
clientSecret
(
"clientSecret"
)
.
clientSecret
(
"clientSecret"
)
.
redirectUri
(
"redirectUri"
)
.
redirectUri
(
"redirectUri"
)
.
state
(
"state"
)
.
build
());
// 返回授权页面,可自行调整
String
url
=
authRequest
.
authorize
();
// 授权登录后会返回一个code,用这个code进行登录
AuthResponse
login
=
authRequest
.
login
(
new
AuthCallback
());
}
@Test
public
void
toutiaoTest
()
{
AuthRequest
authRequest
=
new
AuthToutiaoRequest
(
AuthConfig
.
builder
()
.
clientId
(
"clientId"
)
.
clientSecret
(
"clientSecret"
)
.
redirectUri
(
"redirectUri"
)
.
state
(
"state"
)
.
build
());
.
build
());
// 返回授权页面,可自行调整
// 返回授权页面,可自行调整
String
url
=
authRequest
.
authorize
();
String
url
=
authRequest
.
authorize
();
// 授权登录后会返回一个code,用这个code进行登录
// 授权登录后会返回一个code,用这个code进行登录
AuthResponse
login
=
authRequest
.
login
(
"code"
);
AuthResponse
login
=
authRequest
.
login
(
new
AuthCallback
()
);
}
}
}
}
update.md
浏览文件 @
80329c24
### 2019/06/28
### 2019/06/28
1.
修复百度登录获取不到token失效时间的问题
1.
修复百度登录获取不到token失效时间的问题
2.
gitee增加state参数校验
2.
增加state参数校验,预防CSRF。强烈建议启用state!
### 2019/06/27
### 2019/06/27
1.
修改login方法的参数为AuthCallback,封装回调返回的参数
1.
修改login方法的参数为AuthCallback,封装回调返回的参数
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录