Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
My_csdo
JustAuth
提交
9aa693d2
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看板
提交
9aa693d2
编写于
7月 18, 2019
作者:
H
Hongwei Peng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add refresh token method
上级
a6f25ec3
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
28 addition
and
14 deletion
+28
-14
src/main/java/me/zhyd/oauth/request/AuthRenrenRequest.java
src/main/java/me/zhyd/oauth/request/AuthRenrenRequest.java
+28
-14
未找到文件。
src/main/java/me/zhyd/oauth/request/AuthRenrenRequest.java
浏览文件 @
9aa693d2
...
...
@@ -7,6 +7,7 @@ import com.alibaba.fastjson.JSONObject;
import
me.zhyd.oauth.config.AuthConfig
;
import
me.zhyd.oauth.exception.AuthException
;
import
me.zhyd.oauth.model.AuthCallback
;
import
me.zhyd.oauth.model.AuthResponse
;
import
me.zhyd.oauth.model.AuthToken
;
import
me.zhyd.oauth.model.AuthUser
;
import
me.zhyd.oauth.model.AuthUserGender
;
...
...
@@ -16,6 +17,7 @@ import me.zhyd.oauth.url.entity.AuthUserInfoEntity;
import
java.util.Objects
;
import
static
me
.
zhyd
.
oauth
.
config
.
AuthSource
.
RENREN
;
import
static
me
.
zhyd
.
oauth
.
model
.
AuthResponseStatus
.
SUCCESS
;
/**
* 人人登录
...
...
@@ -32,26 +34,14 @@ public class AuthRenrenRequest extends AuthDefaultRequest {
@Override
protected
AuthToken
getAccessToken
(
AuthCallback
authCallback
)
{
String
accessTokenUrl
=
this
.
urlBuilder
.
getAccessTokenUrl
(
authCallback
.
getCode
());
HttpResponse
response
=
HttpRequest
.
post
(
accessTokenUrl
).
execute
();
JSONObject
accessTokenObject
=
JSONObject
.
parseObject
(
response
.
body
());
if
(!
response
.
isOk
())
{
throw
new
AuthException
(
"Unable to get token from renren using code ["
+
authCallback
.
getCode
()
+
"]: "
+
accessTokenObject
);
}
return
AuthToken
.
builder
()
.
accessToken
(
accessTokenObject
.
getString
(
"access_token"
))
.
refreshToken
(
accessTokenObject
.
getString
(
"refresh_token"
))
.
openId
(
accessTokenObject
.
getJSONObject
(
"user"
).
getString
(
"id"
))
.
build
();
return
getToken
(
this
.
urlBuilder
.
getAccessTokenUrl
(
authCallback
.
getCode
()));
}
@Override
protected
AuthUser
getUserInfo
(
AuthToken
authToken
)
{
String
accessToken
=
authToken
.
getAccessToken
();
HttpResponse
response
=
HttpRequest
.
get
(
this
.
urlBuilder
.
getUserInfoUrl
(
AuthUserInfoEntity
.
builder
()
.
openId
(
authToken
.
getOpenId
())
.
accessToken
(
a
ccessToken
)
.
accessToken
(
a
uthToken
.
getAccessToken
()
)
.
build
())).
execute
();
JSONObject
userObj
=
JSONObject
.
parseObject
(
response
.
body
()).
getJSONObject
(
"response"
);
...
...
@@ -66,6 +56,30 @@ public class AuthRenrenRequest extends AuthDefaultRequest {
.
build
();
}
@Override
public
AuthResponse
refresh
(
AuthToken
authToken
)
{
return
AuthResponse
.
builder
()
.
code
(
SUCCESS
.
getCode
())
.
data
(
getToken
(
this
.
urlBuilder
.
getRefreshUrl
(
authToken
.
getRefreshToken
())))
.
build
();
}
private
AuthToken
getToken
(
String
url
)
{
HttpResponse
response
=
HttpRequest
.
post
(
url
).
execute
();
JSONObject
jsonObject
=
JSONObject
.
parseObject
(
response
.
body
());
if
(!
response
.
isOk
())
{
throw
new
AuthException
(
"Failed to get token from Renren: "
+
jsonObject
);
}
return
AuthToken
.
builder
()
.
tokenType
(
jsonObject
.
getString
(
"token_type"
))
.
expireIn
(
jsonObject
.
getIntValue
(
"expires_in"
))
.
accessToken
(
jsonObject
.
getString
(
"access_token"
))
.
refreshToken
(
jsonObject
.
getString
(
"refresh_token"
))
.
openId
(
jsonObject
.
getJSONObject
(
"user"
).
getString
(
"id"
))
.
build
();
}
private
String
getAvatarUrl
(
JSONObject
userObj
)
{
JSONArray
jsonArray
=
userObj
.
getJSONArray
(
"avatar"
);
if
(
Objects
.
isNull
(
jsonArray
)
||
jsonArray
.
isEmpty
())
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录