Commit c46280e9 authored by Quxl's avatar Quxl

x

parent 76b3b60a
......@@ -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);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment