/** * Store token data including the expiry date of the access token. * * @param accessToken * @param refreshToken * @param expiry */ public OAuth2Tokens(String accessToken, String refreshToken, Date expiry) { this.accessToken = accessToken; this.refreshToken = refreshToken; this.expiry = expiry; if (refreshToken == null) { throw new IllegalArgumentException( "Null refresh tokens not permitted when constructing " + this.getClass().getName()); } if (accessToken == null) { this.expireAccessToken(); } }
/** * Store token data including the expiry date of the access token. * * @param accessToken * @param refreshToken * @param expiry */ public OAuth2Tokens(String accessToken, String refreshToken, Date expiry) { this.accessToken = accessToken; this.refreshToken = refreshToken; this.expiry = expiry; if (refreshToken == null) { throw new IllegalArgumentException( "Null refresh tokens not permitted when constructing " + this.getClass().getName()); } if (accessToken == null) { this.expireAccessToken(); } }
@Override protected boolean isRecoverable403(HttpUriRequest httpRequest, Exception exception) { if (getProviderCredentials() instanceof OAuth2Credentials) { // Only retry if we're using OAuth2 authentication and can refresh the access token // TODO Any way to distinguish between expired access token and other 403 reasons? OAuth2Tokens tokens; try { tokens = ((OAuth2Credentials)getProviderCredentials()).getOAuth2Tokens(); } catch(IOException e) { return false; } if (tokens != null) { tokens.expireAccessToken(); return true; } } return super.isRecoverable403(httpRequest, exception); }
@Override protected boolean isRecoverable403(HttpUriRequest httpRequest, Exception exception) { if (getProviderCredentials() instanceof OAuth2Credentials) { // Only retry if we're using OAuth2 authentication and can refresh the access token // TODO Any way to distinguish between expired access token and other 403 reasons? OAuth2Tokens tokens; try { tokens = ((OAuth2Credentials)getProviderCredentials()).getOAuth2Tokens(); } catch(IOException e) { return false; } if (tokens != null) { tokens.expireAccessToken(); return true; } } return super.isRecoverable403(httpRequest, exception); }