Commit c46280e9 authored by Quxl's avatar Quxl

x

parent 76b3b60a
...@@ -301,8 +301,11 @@ public interface OAuthApi { ...@@ -301,8 +301,11 @@ public interface OAuthApi {
* <p>一旦出现token过期的情况,可调用此方法进行刷新</p> * <p>一旦出现token过期的情况,可调用此方法进行刷新</p>
* <p>此方法的具体操作就是通过refresh_token去更新access_token, 通常情况下, refresh_token的有效期时长,会比access_token的有效期时长长很多</p> * <p>此方法的具体操作就是通过refresh_token去更新access_token, 通常情况下, refresh_token的有效期时长,会比access_token的有效期时长长很多</p>
* <p>如果refresh_token也过期了,那么就需要通过 doRedirectOAuthLogin 进行重新授权了</p> * <p>如果refresh_token也过期了,那么就需要通过 doRedirectOAuthLogin 进行重新授权了</p>
*
* @return 返回刷新后的 OAuthToken
*
*/ */
default void refreshOAuthToken() { default OAuthToken refreshOAuthToken() {
try { try {
HttpServletRequest request = this.getHttpServletRequest(); HttpServletRequest request = this.getHttpServletRequest();
HttpSession session = request.getSession(); HttpSession session = request.getSession();
...@@ -327,6 +330,7 @@ public interface OAuthApi { ...@@ -327,6 +330,7 @@ public interface OAuthApi {
OAuthToken newToken = new OAuthToken(accessToken, refreshToken, idToken, tokenType, expiresIn); OAuthToken newToken = new OAuthToken(accessToken, refreshToken, idToken, tokenType, expiresIn);
logger.debug("oauth refresh result: " + JSON.toJSONString(newToken)); logger.debug("oauth refresh result: " + JSON.toJSONString(newToken));
this.saveOAuthToken(newToken); this.saveOAuthToken(newToken);
return newToken;
} catch (OAuthApiException e) { } catch (OAuthApiException e) {
throw e; throw e;
} catch (Throwable e) { } catch (Throwable e) {
...@@ -348,9 +352,8 @@ public interface OAuthApi { ...@@ -348,9 +352,8 @@ public interface OAuthApi {
logger.debug("oauth post headers: " + JSON.toJSONString(headers)); logger.debug("oauth post headers: " + JSON.toJSONString(headers));
logger.debug("oauth post data: " + jsonData); logger.debug("oauth post data: " + jsonData);
OAuthToken token = this.getOAuthToken(); OAuthToken token = this.getOAuthToken();
if(System.currentTimeMillis() - token.getCreateMillis() > ((token.getExpiresIn()-5) * 1000)) { if(System.currentTimeMillis() - token.getCreateMillis() > ((token.getExpiresIn()-5) * 60 * 1000)) {
this.refreshOAuthToken(); token = this.refreshOAuthToken();
token = this.getOAuthToken();
} }
OAuthClient oAuthClient = new OAuthClient(new URLConnectionClient()); OAuthClient oAuthClient = new OAuthClient(new URLConnectionClient());
String accessToken = token.getAccessToken(); String accessToken = token.getAccessToken();
...@@ -368,7 +371,4 @@ public interface OAuthApi { ...@@ -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