Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
S
sso
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
曲欣亮
sso
Commits
c46280e9
Commit
c46280e9
authored
Aug 07, 2019
by
Quxl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
x
parent
76b3b60a
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
7 deletions
+7
-7
OAuthApi.java
src/main/java/com/egolm/sso/oauth/OAuthApi.java
+7
-7
No files found.
src/main/java/com/egolm/sso/oauth/OAuthApi.java
View file @
c46280e9
...
...
@@ -301,8 +301,11 @@ public interface OAuthApi {
* <p>一旦出现token过期的情况,可调用此方法进行刷新</p>
* <p>此方法的具体操作就是通过refresh_token去更新access_token, 通常情况下, refresh_token的有效期时长,会比access_token的有效期时长长很多</p>
* <p>如果refresh_token也过期了,那么就需要通过 doRedirectOAuthLogin 进行重新授权了</p>
*
* @return 返回刷新后的 OAuthToken
*
*/
default
void
refreshOAuthToken
()
{
default
OAuthToken
refreshOAuthToken
()
{
try
{
HttpServletRequest
request
=
this
.
getHttpServletRequest
();
HttpSession
session
=
request
.
getSession
();
...
...
@@ -327,6 +330,7 @@ public interface OAuthApi {
OAuthToken
newToken
=
new
OAuthToken
(
accessToken
,
refreshToken
,
idToken
,
tokenType
,
expiresIn
);
logger
.
debug
(
"oauth refresh result: "
+
JSON
.
toJSONString
(
newToken
));
this
.
saveOAuthToken
(
newToken
);
return
newToken
;
}
catch
(
OAuthApiException
e
)
{
throw
e
;
}
catch
(
Throwable
e
)
{
...
...
@@ -348,9 +352,8 @@ public interface OAuthApi {
logger
.
debug
(
"oauth post headers: "
+
JSON
.
toJSONString
(
headers
));
logger
.
debug
(
"oauth post data: "
+
jsonData
);
OAuthToken
token
=
this
.
getOAuthToken
();
if
(
System
.
currentTimeMillis
()
-
token
.
getCreateMillis
()
>
((
token
.
getExpiresIn
()-
5
)
*
1000
))
{
this
.
refreshOAuthToken
();
token
=
this
.
getOAuthToken
();
if
(
System
.
currentTimeMillis
()
-
token
.
getCreateMillis
()
>
((
token
.
getExpiresIn
()-
5
)
*
60
*
1000
))
{
token
=
this
.
refreshOAuthToken
();
}
OAuthClient
oAuthClient
=
new
OAuthClient
(
new
URLConnectionClient
());
String
accessToken
=
token
.
getAccessToken
();
...
...
@@ -368,7 +371,4 @@ public interface OAuthApi {
}
}
public
static
void
main
(
String
[]
args
)
{
System
.
out
.
println
(
3599
/
60
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment