Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
符节科技
Jap
提交
fa4eb76d
Jap
项目概览
符节科技
/
Jap
8 个月 前同步成功
通知
90
Star
3
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Jap
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
fa4eb76d
编写于
5月 13, 2021
作者:
智布道
👁
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
✨
`SocialStrategy` provides methods of `refreshToken`, `revokeToken`, and `getUserInfo`
上级
81311ced
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
97 addition
and
16 deletion
+97
-16
jap-social/src/main/java/com/fujieid/jap/social/SocialStrategy.java
.../src/main/java/com/fujieid/jap/social/SocialStrategy.java
+97
-16
未找到文件。
jap-social/src/main/java/com/fujieid/jap/social/SocialStrategy.java
浏览文件 @
fa4eb76d
...
...
@@ -17,6 +17,7 @@ package com.fujieid.jap.social;
import
cn.hutool.core.collection.CollectionUtil
;
import
cn.hutool.core.util.ObjectUtil
;
import
cn.hutool.core.util.ReflectUtil
;
import
cn.hutool.core.util.StrUtil
;
import
com.alibaba.fastjson.JSONObject
;
import
com.fujieid.jap.core.JapUser
;
...
...
@@ -35,11 +36,13 @@ import me.zhyd.oauth.config.AuthConfig;
import
me.zhyd.oauth.config.AuthDefaultSource
;
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.request.AuthRequest
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
java.lang.reflect.Method
;
import
java.util.Map
;
/**
...
...
@@ -102,29 +105,15 @@ public class SocialStrategy extends AbstractJapStrategy {
return
JapResponse
.
success
(
sessionUser
);
}
// Convert AuthenticateConfig to SocialConfig
AuthRequest
authRequest
=
null
;
try
{
this
.
checkAuthenticateConfig
(
config
,
SocialConfig
.
class
);
authRequest
=
this
.
getAuthRequest
(
config
);
}
catch
(
JapException
e
)
{
return
JapResponse
.
error
(
e
.
getErrorCode
(),
e
.
getErrorMessage
());
}
SocialConfig
socialConfig
=
(
SocialConfig
)
config
;
String
source
=
socialConfig
.
getPlatform
();
// Get the AuthConfig of JustAuth
AuthConfig
authConfig
=
socialConfig
.
getJustAuthConfig
();
if
(
ObjectUtil
.
isNull
(
authConfig
))
{
return
JapResponse
.
error
(
JapErrorCode
.
MISS_AUTH_CONFIG
);
}
// Instantiate the AuthRequest of JustAuth
AuthRequest
authRequest
=
null
;
try
{
authRequest
=
JustAuthRequestContext
.
getRequest
(
source
,
socialConfig
,
authConfig
,
authStateCache
);
}
catch
(
JapSocialException
e
)
{
return
JapResponse
.
error
(
e
.
getErrorCode
(),
e
.
getErrorMessage
());
}
AuthCallback
authCallback
=
this
.
parseRequest
(
request
);
// If it is not a callback request, it must be a request to jump to the authorization link
...
...
@@ -140,6 +129,98 @@ public class SocialStrategy extends AbstractJapStrategy {
}
}
public
JapResponse
refreshToken
(
AuthenticateConfig
config
,
AuthToken
authToken
)
{
AuthRequest
authRequest
=
null
;
try
{
authRequest
=
this
.
getAuthRequest
(
config
);
}
catch
(
JapException
e
)
{
return
JapResponse
.
error
(
e
.
getErrorCode
(),
e
.
getErrorMessage
());
}
SocialConfig
socialConfig
=
(
SocialConfig
)
config
;
String
source
=
socialConfig
.
getPlatform
();
AuthResponse
<?>
authUserAuthResponse
=
null
;
try
{
authUserAuthResponse
=
authRequest
.
refresh
(
authToken
);
}
catch
(
Exception
e
)
{
throw
new
JapSocialException
(
"Third party refresh access token of `"
+
source
+
"` failed. "
+
e
.
getMessage
());
}
if
(!
authUserAuthResponse
.
ok
()
||
ObjectUtil
.
isNull
(
authUserAuthResponse
.
getData
()))
{
throw
new
JapUserException
(
"Third party refresh access token of `"
+
source
+
"` failed. "
+
authUserAuthResponse
.
getMsg
());
}
authToken
=
(
AuthToken
)
authUserAuthResponse
.
getData
();
return
JapResponse
.
success
(
authToken
);
}
public
JapResponse
revokeToken
(
AuthenticateConfig
config
,
AuthToken
authToken
)
{
AuthRequest
authRequest
=
null
;
try
{
authRequest
=
this
.
getAuthRequest
(
config
);
}
catch
(
JapException
e
)
{
return
JapResponse
.
error
(
e
.
getErrorCode
(),
e
.
getErrorMessage
());
}
SocialConfig
socialConfig
=
(
SocialConfig
)
config
;
String
source
=
socialConfig
.
getPlatform
();
AuthResponse
<?>
authUserAuthResponse
=
null
;
try
{
authUserAuthResponse
=
authRequest
.
revoke
(
authToken
);
}
catch
(
Exception
e
)
{
throw
new
JapSocialException
(
"Third party refresh access token of `"
+
source
+
"` failed. "
+
e
.
getMessage
());
}
if
(!
authUserAuthResponse
.
ok
()
||
ObjectUtil
.
isNull
(
authUserAuthResponse
.
getData
()))
{
throw
new
JapUserException
(
"Third party refresh access token of `"
+
source
+
"` failed. "
+
authUserAuthResponse
.
getMsg
());
}
return
JapResponse
.
success
();
}
public
JapResponse
getUserInfo
(
AuthenticateConfig
config
,
AuthToken
authToken
)
{
AuthRequest
authRequest
=
null
;
try
{
authRequest
=
this
.
getAuthRequest
(
config
);
}
catch
(
JapException
e
)
{
return
JapResponse
.
error
(
e
.
getErrorCode
(),
e
.
getErrorMessage
());
}
SocialConfig
socialConfig
=
(
SocialConfig
)
config
;
String
source
=
socialConfig
.
getPlatform
();
String
funName
=
"getUserInfo"
;
Method
method
=
null
;
AuthUser
res
=
null
;
JapUserException
japUserException
=
new
JapUserException
(
"Failed to obtain user information on the third-party platform `"
+
source
+
"`"
);
try
{
if
((
method
=
ReflectUtil
.
getMethod
(
authRequest
.
getClass
(),
funName
,
AuthToken
.
class
))
!=
null
)
{
method
.
setAccessible
(
true
);
res
=
ReflectUtil
.
invoke
(
authRequest
,
method
,
authToken
);
if
(
null
==
res
)
{
throw
japUserException
;
}
}
}
catch
(
Exception
e
)
{
throw
japUserException
;
}
AuthUser
authUser
=
res
;
return
JapResponse
.
success
(
authUser
);
}
private
AuthRequest
getAuthRequest
(
AuthenticateConfig
config
)
{
// Convert AuthenticateConfig to SocialConfig
this
.
checkAuthenticateConfig
(
config
,
SocialConfig
.
class
);
SocialConfig
socialConfig
=
(
SocialConfig
)
config
;
String
source
=
socialConfig
.
getPlatform
();
// Get the AuthConfig of JustAuth
AuthConfig
authConfig
=
socialConfig
.
getJustAuthConfig
();
if
(
ObjectUtil
.
isNull
(
authConfig
))
{
throw
new
JapException
(
JapErrorCode
.
MISS_AUTH_CONFIG
);
}
// Instantiate the AuthRequest of JustAuth
return
JustAuthRequestContext
.
getRequest
(
source
,
socialConfig
,
authConfig
,
authStateCache
);
}
/**
* Login with third party authorization
*
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录