Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
My_csdo
JustAuth
提交
188c52ca
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看板
提交
188c52ca
编写于
5月 17, 2019
作者:
智布道
👁
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
👌
修改获取accessToken时的返回值为实体类,方便扩展
上级
2e0262ed
变更
15
显示空白变更内容
内联
并排
Showing
15 changed file
with
102 addition
and
48 deletion
+102
-48
README.md
README.md
+11
-0
src/main/java/me/zhyd/oauth/model/AuthToken.java
src/main/java/me/zhyd/oauth/model/AuthToken.java
+5
-0
src/main/java/me/zhyd/oauth/request/AuthAlipayRequest.java
src/main/java/me/zhyd/oauth/request/AuthAlipayRequest.java
+7
-3
src/main/java/me/zhyd/oauth/request/AuthBaiduRequest.java
src/main/java/me/zhyd/oauth/request/AuthBaiduRequest.java
+8
-4
src/main/java/me/zhyd/oauth/request/AuthCodingRequest.java
src/main/java/me/zhyd/oauth/request/AuthCodingRequest.java
+7
-3
src/main/java/me/zhyd/oauth/request/AuthCsdnRequest.java
src/main/java/me/zhyd/oauth/request/AuthCsdnRequest.java
+7
-3
src/main/java/me/zhyd/oauth/request/AuthDingTalkRequest.java
src/main/java/me/zhyd/oauth/request/AuthDingTalkRequest.java
+7
-11
src/main/java/me/zhyd/oauth/request/AuthGiteeRequest.java
src/main/java/me/zhyd/oauth/request/AuthGiteeRequest.java
+7
-3
src/main/java/me/zhyd/oauth/request/AuthGithubRequest.java
src/main/java/me/zhyd/oauth/request/AuthGithubRequest.java
+7
-3
src/main/java/me/zhyd/oauth/request/AuthOschinaRequest.java
src/main/java/me/zhyd/oauth/request/AuthOschinaRequest.java
+7
-3
src/main/java/me/zhyd/oauth/request/AuthQqRequest.java
src/main/java/me/zhyd/oauth/request/AuthQqRequest.java
+7
-3
src/main/java/me/zhyd/oauth/request/AuthRequest.java
src/main/java/me/zhyd/oauth/request/AuthRequest.java
+5
-4
src/main/java/me/zhyd/oauth/request/AuthTencentCloudRequest.java
...n/java/me/zhyd/oauth/request/AuthTencentCloudRequest.java
+7
-3
src/main/java/me/zhyd/oauth/request/AuthWeiboRequest.java
src/main/java/me/zhyd/oauth/request/AuthWeiboRequest.java
+7
-3
src/main/java/me/zhyd/oauth/request/BaseAuthRequest.java
src/main/java/me/zhyd/oauth/request/BaseAuthRequest.java
+3
-2
未找到文件。
README.md
浏览文件 @
188c52ca
...
...
@@ -168,6 +168,17 @@ authRequest.login("code");
待续
# 交流
| 微信(备注:加群) | 公众号 |
| :------------: | :------------: |
|
<img
src=
"https://gitee.com/yadong.zhang/static/raw/master/wx/wx.png"
width=
"170"
/>
|
<img
src=
"https://gitee.com/yadong.zhang/static/raw/master/wx/wechat_account.jpg"
width=
"200"
/>
|
**QQ群**
[
![
](
https://images.gitee.com/uploads/images/2019/0129/191256_a40bceba_784199.png
)
](https://shang.qq.com/wpa/qunwpa?idkey=3571c554a143eff1e15807de033a240196c6b493b25b903d1d37571cfb6040aa)
## 请喝咖啡
| 支付宝 | 微信 |
...
...
src/main/java/me/zhyd/oauth/model/AuthToken.java
浏览文件 @
188c52ca
...
...
@@ -15,4 +15,9 @@ public class AuthToken {
private
String
expireIn
;
private
String
refreshToken
;
private
String
uid
;
private
String
openId
;
/**
* 针对钉钉
*/
private
String
accessCode
;
}
src/main/java/me/zhyd/oauth/request/AuthAlipayRequest.java
浏览文件 @
188c52ca
...
...
@@ -11,6 +11,7 @@ import me.zhyd.oauth.config.AuthConfig;
import
me.zhyd.oauth.consts.ApiUrl
;
import
me.zhyd.oauth.exception.AuthException
;
import
me.zhyd.oauth.model.AuthSource
;
import
me.zhyd.oauth.model.AuthToken
;
import
me.zhyd.oauth.model.AuthUser
;
import
me.zhyd.oauth.model.AuthUserGender
;
import
me.zhyd.oauth.utils.StringUtils
;
...
...
@@ -32,7 +33,7 @@ public class AuthAlipayRequest extends BaseAuthRequest {
}
@Override
protected
String
getAccessToken
(
String
code
)
{
protected
AuthToken
getAccessToken
(
String
code
)
{
AlipaySystemOauthTokenRequest
request
=
new
AlipaySystemOauthTokenRequest
();
request
.
setGrantType
(
"authorization_code"
);
request
.
setCode
(
code
);
...
...
@@ -45,11 +46,14 @@ public class AuthAlipayRequest extends BaseAuthRequest {
if
(!
response
.
isSuccess
())
{
throw
new
AuthException
(
response
.
getSubMsg
());
}
return
response
.
getAccessToken
();
return
AuthToken
.
builder
()
.
accessToken
(
response
.
getAccessToken
())
.
build
();
}
@Override
protected
AuthUser
getUserInfo
(
String
accessToken
)
{
protected
AuthUser
getUserInfo
(
AuthToken
authToken
)
{
String
accessToken
=
authToken
.
getAccessToken
();
AlipayUserInfoShareRequest
request
=
new
AlipayUserInfoShareRequest
();
AlipayUserInfoShareResponse
response
=
null
;
try
{
...
...
src/main/java/me/zhyd/oauth/request/AuthBaiduRequest.java
浏览文件 @
188c52ca
...
...
@@ -22,7 +22,7 @@ public class AuthBaiduRequest extends BaseAuthRequest {
}
@Override
protected
String
getAccessToken
(
String
code
)
{
protected
AuthToken
getAccessToken
(
String
code
)
{
String
accessTokenUrl
=
UrlBuilder
.
getBaiduAccessTokenUrl
(
config
.
getClientId
(),
config
.
getClientSecret
(),
code
,
config
.
getRedirectUri
());
HttpResponse
response
=
HttpRequest
.
post
(
accessTokenUrl
).
execute
();
JSONObject
accessTokenObject
=
JSONObject
.
parseObject
(
response
.
body
());
...
...
@@ -30,11 +30,14 @@ public class AuthBaiduRequest extends BaseAuthRequest {
if
(!
AuthBaiduErrorCode
.
OK
.
equals
(
errorCode
))
{
throw
new
AuthException
(
errorCode
.
getDesc
());
}
return
accessTokenObject
.
getString
(
"access_token"
);
return
AuthToken
.
builder
()
.
accessToken
(
accessTokenObject
.
getString
(
"access_token"
))
.
build
();
}
@Override
protected
AuthUser
getUserInfo
(
String
accessToken
)
{
protected
AuthUser
getUserInfo
(
AuthToken
authToken
)
{
String
accessToken
=
authToken
.
getAccessToken
();
HttpResponse
response
=
HttpRequest
.
get
(
UrlBuilder
.
getBaiduUserInfoUrl
(
accessToken
)).
execute
();
String
userInfo
=
response
.
body
();
JSONObject
object
=
JSONObject
.
parseObject
(
userInfo
);
...
...
@@ -52,7 +55,8 @@ public class AuthBaiduRequest extends BaseAuthRequest {
}
@Override
public
AuthResponse
revoke
(
String
accessToken
)
{
public
AuthResponse
revoke
(
AuthToken
authToken
)
{
String
accessToken
=
authToken
.
getAccessToken
();
HttpResponse
response
=
HttpRequest
.
get
(
UrlBuilder
.
getBaiduRevokeUrl
(
accessToken
)).
execute
();
String
userInfo
=
response
.
body
();
JSONObject
object
=
JSONObject
.
parseObject
(
userInfo
);
...
...
src/main/java/me/zhyd/oauth/request/AuthCodingRequest.java
浏览文件 @
188c52ca
...
...
@@ -6,6 +6,7 @@ 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.UrlBuilder
;
...
...
@@ -24,18 +25,21 @@ public class AuthCodingRequest extends BaseAuthRequest {
}
@Override
protected
String
getAccessToken
(
String
code
)
{
protected
AuthToken
getAccessToken
(
String
code
)
{
String
accessTokenUrl
=
UrlBuilder
.
getCodingAccessTokenUrl
(
config
.
getClientId
(),
config
.
getClientSecret
(),
code
);
HttpResponse
response
=
HttpRequest
.
get
(
accessTokenUrl
).
execute
();
JSONObject
accessTokenObject
=
JSONObject
.
parseObject
(
response
.
body
());
if
(
accessTokenObject
.
getIntValue
(
"code"
)
!=
0
)
{
throw
new
AuthException
(
"Unable to get token from coding using code ["
+
code
+
"]"
);
}
return
accessTokenObject
.
getString
(
"access_token"
);
return
AuthToken
.
builder
()
.
accessToken
(
accessTokenObject
.
getString
(
"access_token"
))
.
build
();
}
@Override
protected
AuthUser
getUserInfo
(
String
accessToken
)
{
protected
AuthUser
getUserInfo
(
AuthToken
authToken
)
{
String
accessToken
=
authToken
.
getAccessToken
();
HttpResponse
response
=
HttpRequest
.
get
(
UrlBuilder
.
getCodingUserInfoUrl
(
accessToken
)).
execute
();
JSONObject
object
=
JSONObject
.
parseObject
(
response
.
body
());
if
(
object
.
getIntValue
(
"code"
)
!=
0
)
{
...
...
src/main/java/me/zhyd/oauth/request/AuthCsdnRequest.java
浏览文件 @
188c52ca
...
...
@@ -6,6 +6,7 @@ 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.utils.UrlBuilder
;
...
...
@@ -23,18 +24,21 @@ public class AuthCsdnRequest extends BaseAuthRequest {
}
@Override
protected
String
getAccessToken
(
String
code
)
{
protected
AuthToken
getAccessToken
(
String
code
)
{
String
accessTokenUrl
=
UrlBuilder
.
getCsdnAccessTokenUrl
(
config
.
getClientId
(),
config
.
getClientSecret
(),
code
,
config
.
getRedirectUri
());
HttpResponse
response
=
HttpRequest
.
post
(
accessTokenUrl
).
execute
();
JSONObject
accessTokenObject
=
JSONObject
.
parseObject
(
response
.
body
());
if
(
accessTokenObject
.
containsKey
(
"error_code"
))
{
throw
new
AuthException
(
"Unable to get token from csdn using code ["
+
code
+
"]"
);
}
return
accessTokenObject
.
getString
(
"access_token"
);
return
AuthToken
.
builder
()
.
accessToken
(
accessTokenObject
.
getString
(
"access_token"
))
.
build
();
}
@Override
protected
AuthUser
getUserInfo
(
String
accessToken
)
{
protected
AuthUser
getUserInfo
(
AuthToken
authToken
)
{
String
accessToken
=
authToken
.
getAccessToken
();
HttpResponse
response
=
HttpRequest
.
get
(
UrlBuilder
.
getCsdnUserInfoUrl
(
accessToken
)).
execute
();
JSONObject
object
=
JSONObject
.
parseObject
(
response
.
body
());
if
(
object
.
containsKey
(
"error_code"
))
{
...
...
src/main/java/me/zhyd/oauth/request/AuthDingTalkRequest.java
浏览文件 @
188c52ca
...
...
@@ -6,8 +6,8 @@ import cn.hutool.json.JSONObject;
import
me.zhyd.oauth.config.AuthConfig
;
import
me.zhyd.oauth.exception.AuthException
;
import
me.zhyd.oauth.model.AuthDingTalkErrorCode
;
import
me.zhyd.oauth.model.AuthResponse
;
import
me.zhyd.oauth.model.AuthSource
;
import
me.zhyd.oauth.model.AuthToken
;
import
me.zhyd.oauth.model.AuthUser
;
import
me.zhyd.oauth.utils.GlobalAuthUtil
;
import
me.zhyd.oauth.utils.UrlBuilder
;
...
...
@@ -28,12 +28,15 @@ public class AuthDingTalkRequest extends BaseAuthRequest {
}
@Override
protected
String
getAccessToken
(
String
code
)
{
throw
new
AuthException
(
ResponseStatus
.
NOT_IMPLEMENTED
);
protected
AuthToken
getAccessToken
(
String
code
)
{
return
AuthToken
.
builder
()
.
accessCode
(
code
)
.
build
();
}
@Override
protected
AuthUser
getUserInfo
(
String
code
)
{
protected
AuthUser
getUserInfo
(
AuthToken
authToken
)
{
String
code
=
authToken
.
getAccessCode
();
// 根据timestamp, appSecret计算签名值
String
stringToSign
=
System
.
currentTimeMillis
()
+
""
;
String
urlEncodeSignature
=
GlobalAuthUtil
.
generateDingTalkSignature
(
config
.
getClientSecret
(),
stringToSign
);
...
...
@@ -52,11 +55,4 @@ public class AuthDingTalkRequest extends BaseAuthRequest {
.
source
(
AuthSource
.
DINGTALK
)
.
build
();
}
@Override
public
AuthResponse
login
(
String
code
)
{
return
AuthResponse
.
builder
()
.
data
(
this
.
getUserInfo
(
code
))
.
build
();
}
}
src/main/java/me/zhyd/oauth/request/AuthGiteeRequest.java
浏览文件 @
188c52ca
...
...
@@ -6,6 +6,7 @@ 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.utils.UrlBuilder
;
...
...
@@ -23,18 +24,21 @@ public class AuthGiteeRequest extends BaseAuthRequest {
}
@Override
protected
String
getAccessToken
(
String
code
)
{
protected
AuthToken
getAccessToken
(
String
code
)
{
String
accessTokenUrl
=
UrlBuilder
.
getGiteeAccessTokenUrl
(
config
.
getClientId
(),
config
.
getClientSecret
(),
code
,
config
.
getRedirectUri
());
HttpResponse
response
=
HttpRequest
.
post
(
accessTokenUrl
).
execute
();
JSONObject
accessTokenObject
=
JSONObject
.
parseObject
(
response
.
body
());
if
(
accessTokenObject
.
containsKey
(
"error"
))
{
throw
new
AuthException
(
"Unable to get token from gitee using code ["
+
code
+
"]"
);
}
return
accessTokenObject
.
getString
(
"access_token"
);
return
AuthToken
.
builder
()
.
accessToken
(
accessTokenObject
.
getString
(
"access_token"
))
.
build
();
}
@Override
protected
AuthUser
getUserInfo
(
String
accessToken
)
{
protected
AuthUser
getUserInfo
(
AuthToken
authToken
)
{
String
accessToken
=
authToken
.
getAccessToken
();
HttpResponse
response
=
HttpRequest
.
get
(
UrlBuilder
.
getGiteeUserInfoUrl
(
accessToken
)).
execute
();
String
userInfo
=
response
.
body
();
JSONObject
object
=
JSONObject
.
parseObject
(
userInfo
);
...
...
src/main/java/me/zhyd/oauth/request/AuthGithubRequest.java
浏览文件 @
188c52ca
...
...
@@ -6,6 +6,7 @@ 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.utils.GlobalAuthUtil
;
import
me.zhyd.oauth.utils.UrlBuilder
;
...
...
@@ -26,18 +27,21 @@ public class AuthGithubRequest extends BaseAuthRequest {
}
@Override
protected
String
getAccessToken
(
String
code
)
{
protected
AuthToken
getAccessToken
(
String
code
)
{
String
accessTokenUrl
=
UrlBuilder
.
getGithubAccessTokenUrl
(
config
.
getClientId
(),
config
.
getClientSecret
(),
code
,
config
.
getRedirectUri
());
HttpResponse
response
=
HttpRequest
.
post
(
accessTokenUrl
).
execute
();
Map
<
String
,
String
>
res
=
GlobalAuthUtil
.
parseStringToMap
(
response
.
body
());
if
(
res
.
containsKey
(
"error"
))
{
throw
new
AuthException
(
res
.
get
(
"error"
)
+
":"
+
res
.
get
(
"error_description"
));
}
return
res
.
get
(
"access_token"
);
return
AuthToken
.
builder
()
.
accessToken
(
res
.
get
(
"access_token"
))
.
build
();
}
@Override
protected
AuthUser
getUserInfo
(
String
accessToken
)
{
protected
AuthUser
getUserInfo
(
AuthToken
authToken
)
{
String
accessToken
=
authToken
.
getAccessToken
();
HttpResponse
response
=
HttpRequest
.
get
(
UrlBuilder
.
getGithubUserInfoUrl
(
accessToken
)).
execute
();
String
userInfo
=
response
.
body
();
JSONObject
object
=
JSONObject
.
parseObject
(
userInfo
);
...
...
src/main/java/me/zhyd/oauth/request/AuthOschinaRequest.java
浏览文件 @
188c52ca
...
...
@@ -6,6 +6,7 @@ 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.UrlBuilder
;
...
...
@@ -24,18 +25,21 @@ public class AuthOschinaRequest extends BaseAuthRequest {
}
@Override
protected
String
getAccessToken
(
String
code
)
{
protected
AuthToken
getAccessToken
(
String
code
)
{
String
accessTokenUrl
=
UrlBuilder
.
getOschinaAccessTokenUrl
(
config
.
getClientId
(),
config
.
getClientSecret
(),
code
,
config
.
getRedirectUri
());
HttpResponse
response
=
HttpRequest
.
post
(
accessTokenUrl
).
execute
();
JSONObject
accessTokenObject
=
JSONObject
.
parseObject
(
response
.
body
());
if
(
accessTokenObject
.
containsKey
(
"error"
))
{
throw
new
AuthException
(
"Unable to get token from oschina using code ["
+
code
+
"]"
);
}
return
accessTokenObject
.
getString
(
"access_token"
);
return
AuthToken
.
builder
()
.
accessToken
(
accessTokenObject
.
getString
(
"access_token"
))
.
build
();
}
@Override
protected
AuthUser
getUserInfo
(
String
accessToken
)
{
protected
AuthUser
getUserInfo
(
AuthToken
authToken
)
{
String
accessToken
=
authToken
.
getAccessToken
();
HttpResponse
response
=
HttpRequest
.
get
(
UrlBuilder
.
getOschinaUserInfoUrl
(
accessToken
)).
execute
();
JSONObject
object
=
JSONObject
.
parseObject
(
response
.
body
());
if
(
object
.
containsKey
(
"error"
))
{
...
...
src/main/java/me/zhyd/oauth/request/AuthQqRequest.java
浏览文件 @
188c52ca
...
...
@@ -6,6 +6,7 @@ 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.StringUtils
;
...
...
@@ -24,18 +25,21 @@ public class AuthQqRequest extends BaseAuthRequest {
}
@Override
protected
String
getAccessToken
(
String
code
)
{
protected
AuthToken
getAccessToken
(
String
code
)
{
String
accessTokenUrl
=
UrlBuilder
.
getQqAccessTokenUrl
(
config
.
getClientId
(),
config
.
getClientSecret
(),
code
,
config
.
getRedirectUri
());
HttpResponse
response
=
HttpRequest
.
post
(
accessTokenUrl
).
execute
();
JSONObject
accessTokenObject
=
JSONObject
.
parseObject
(
response
.
body
());
if
(!
accessTokenObject
.
containsKey
(
"access_token"
))
{
throw
new
AuthException
(
"Unable to get token from qq using code ["
+
code
+
"]"
);
}
return
accessTokenObject
.
getString
(
"access_token"
);
return
AuthToken
.
builder
()
.
accessToken
(
accessTokenObject
.
getString
(
"access_token"
))
.
build
();
}
@Override
protected
AuthUser
getUserInfo
(
String
accessToken
)
{
protected
AuthUser
getUserInfo
(
AuthToken
authToken
)
{
String
accessToken
=
authToken
.
getAccessToken
();
String
openId
=
this
.
getOpenId
(
accessToken
);
HttpResponse
response
=
HttpRequest
.
get
(
UrlBuilder
.
getQqUserInfoUrl
(
accessToken
,
openId
)).
execute
();
JSONObject
object
=
JSONObject
.
parseObject
(
response
.
body
());
...
...
src/main/java/me/zhyd/oauth/request/AuthRequest.java
浏览文件 @
188c52ca
...
...
@@ -2,6 +2,7 @@ package me.zhyd.oauth.request;
import
me.zhyd.oauth.exception.AuthException
;
import
me.zhyd.oauth.model.AuthResponse
;
import
me.zhyd.oauth.model.AuthToken
;
/**
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
...
...
@@ -32,20 +33,20 @@ public interface AuthRequest {
/**
* 撤销授权
*
* @param a
ccessToken 登录成功后返回的accessToken
* @param a
uthToken 登录成功后返回的Token信息
* @return AuthResponse
*/
default
AuthResponse
revoke
(
String
access
Token
)
{
default
AuthResponse
revoke
(
AuthToken
auth
Token
)
{
throw
new
AuthException
(
ResponseStatus
.
NOT_IMPLEMENTED
);
}
/**
* 刷新access token (续期)
*
* @param a
ccessToken 登录成功后返回的accessToken
* @param a
uthToken 登录成功后返回的Token信息
* @return AuthResponse
*/
default
AuthResponse
refresh
(
String
access
Token
)
{
default
AuthResponse
refresh
(
AuthToken
auth
Token
)
{
throw
new
AuthException
(
ResponseStatus
.
NOT_IMPLEMENTED
);
}
}
src/main/java/me/zhyd/oauth/request/AuthTencentCloudRequest.java
浏览文件 @
188c52ca
...
...
@@ -6,6 +6,7 @@ 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.UrlBuilder
;
...
...
@@ -24,18 +25,21 @@ public class AuthTencentCloudRequest extends BaseAuthRequest {
}
@Override
protected
String
getAccessToken
(
String
code
)
{
protected
AuthToken
getAccessToken
(
String
code
)
{
String
accessTokenUrl
=
UrlBuilder
.
getTencentCloudAccessTokenUrl
(
config
.
getClientId
(),
config
.
getClientSecret
(),
code
);
HttpResponse
response
=
HttpRequest
.
get
(
accessTokenUrl
).
execute
();
JSONObject
object
=
JSONObject
.
parseObject
(
response
.
body
());
if
(
object
.
getIntValue
(
"code"
)
!=
0
)
{
throw
new
AuthException
(
"Unable to get token from tencent cloud using code ["
+
code
+
"]: "
+
object
.
get
(
"msg"
));
}
return
object
.
getString
(
"access_token"
);
return
AuthToken
.
builder
()
.
accessToken
(
object
.
getString
(
"access_token"
))
.
build
();
}
@Override
protected
AuthUser
getUserInfo
(
String
accessToken
)
{
protected
AuthUser
getUserInfo
(
AuthToken
authToken
)
{
String
accessToken
=
authToken
.
getAccessToken
();
HttpResponse
response
=
HttpRequest
.
get
(
UrlBuilder
.
getTencentCloudUserInfoUrl
(
accessToken
)).
execute
();
JSONObject
object
=
JSONObject
.
parseObject
(
response
.
body
());
if
(
object
.
getIntValue
(
"code"
)
!=
0
)
{
...
...
src/main/java/me/zhyd/oauth/request/AuthWeiboRequest.java
浏览文件 @
188c52ca
...
...
@@ -6,6 +6,7 @@ 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
;
...
...
@@ -28,7 +29,7 @@ public class AuthWeiboRequest extends BaseAuthRequest {
}
@Override
protected
String
getAccessToken
(
String
code
)
{
protected
AuthToken
getAccessToken
(
String
code
)
{
String
accessTokenUrl
=
UrlBuilder
.
getWeiboAccessTokenUrl
(
config
.
getClientId
(),
config
.
getClientSecret
(),
code
,
config
.
getRedirectUri
());
HttpResponse
response
=
HttpRequest
.
post
(
accessTokenUrl
).
execute
();
String
accessTokenStr
=
response
.
body
();
...
...
@@ -38,11 +39,14 @@ public class AuthWeiboRequest extends BaseAuthRequest {
}
String
accessToken
=
accessTokenObject
.
getString
(
"access_token"
);
String
uid
=
accessTokenObject
.
getString
(
"uid"
);
return
String
.
format
(
"uid=%s&access_token=%s"
,
uid
,
accessToken
);
return
AuthToken
.
builder
()
.
accessToken
(
String
.
format
(
"uid=%s&access_token=%s"
,
uid
,
accessToken
))
.
build
();
}
@Override
protected
AuthUser
getUserInfo
(
String
accessToken
)
{
protected
AuthUser
getUserInfo
(
AuthToken
authToken
)
{
String
accessToken
=
authToken
.
getAccessToken
();
HttpResponse
response
=
HttpRequest
.
get
(
UrlBuilder
.
getWeiboUserInfoUrl
(
accessToken
))
.
header
(
"Authorization"
,
"OAuth2 "
+
accessToken
)
.
header
(
"API-RemoteIP"
,
IpUtils
.
getIp
())
...
...
src/main/java/me/zhyd/oauth/request/BaseAuthRequest.java
浏览文件 @
188c52ca
...
...
@@ -5,6 +5,7 @@ import me.zhyd.oauth.config.AuthConfig;
import
me.zhyd.oauth.exception.AuthException
;
import
me.zhyd.oauth.model.AuthResponse
;
import
me.zhyd.oauth.model.AuthSource
;
import
me.zhyd.oauth.model.AuthToken
;
import
me.zhyd.oauth.model.AuthUser
;
import
me.zhyd.oauth.utils.AuthConfigChecker
;
import
me.zhyd.oauth.utils.UrlBuilder
;
...
...
@@ -27,9 +28,9 @@ public abstract class BaseAuthRequest implements AuthRequest {
}
}
protected
abstract
String
getAccessToken
(
String
code
);
protected
abstract
AuthToken
getAccessToken
(
String
code
);
protected
abstract
AuthUser
getUserInfo
(
String
access
Token
);
protected
abstract
AuthUser
getUserInfo
(
AuthToken
auth
Token
);
@Override
public
AuthResponse
login
(
String
code
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录