/* RefreshTokenInterface
4977
public function getRefreshToken($refresh_token)
    {
        return isset($this->refreshTokens[$refresh_token]) ? $this->refreshTokens[$refresh_token] : null;
    }
617832
public function setRefreshToken($refreshToken)
    {
        if (in_array('refresh_token', $this->persistantMap)) {
            $this->store->set('refresh_token', $refreshToken);
        }

        $this->refreshToken = $refreshToken;
        return $this;
    }
1281726
public function setRefreshToken($refresh_token)
    {
        $key = array_search('refresh_token', $this->persistantMap);
        if ($key !== false) {
            $this->store->set('refresh_token', $refresh_token);
        }

        $this->refresh_token = $refresh_token;

        return $this;
    }
122117
private HeaderCacheElement updateToken() {
    HeaderCacheElement newToken;
    try {
      LOG.info("Refreshing the OAuth token");
      newToken = new HeaderCacheElement(credentials.refreshAccessToken());
    } catch (Exception e) {
      LOG.warn("Got an unexpected exception while trying to refresh google credentials.", e);
      newToken = new HeaderCacheElement(
          Status.UNAUTHENTICATED
              .withDescription("Unexpected error trying to authenticate")
              .withCause(e)
      );
    }
    synchronized (lock) {
      // Update the token only if the new token is good or the old token is bad
      if (newToken.isValid() || !headerCache.isValid()) {
        headerCache = newToken;
      } else {
        LOG.warn("Failed to refresh the access token. Falling back to existing token. "
            + "New token state: {}, status: {}", newToken.getCacheState(), newToken.getToken().status);
      }
      futureToken = null;

      return headerCache;
    }
  }
1140963
public AuthorizationCodeRefreshRequest.Builder authorizationCodeRefresh() {
    return new AuthorizationCodeRefreshRequest.Builder(clientId, clientSecret)
            .setDefaults(httpManager, scheme, host, port)
            .grant_type("refresh_token")
            .refresh_token(refreshToken);
  }
1217166
public function setRefreshToken($refreshToken)
    {
        if (is_string($refreshToken)) {
            $refreshToken = new AccessToken($refreshToken, 'refresh_token');
        } elseif (!$refreshToken instanceof AccessToken) {
            throw new \InvalidArgumentException('Invalid refresh token');
        }
        $this->refreshToken = $refreshToken;
    }
703044
def refresh_token(self):
        
        self.token = self.oauth.refresh_token(self.access_token_url, refresh_token=self.get_refresh_token())
        self.access_token = self.token.get("access_token")
1145901
@Override
    public synchronized void refreshCredentials() {
        GetSessionTokenResult sessionTokenResult = securityTokenService
                .getSessionToken(new GetSessionTokenRequest().withDurationSeconds(sessionDurationSeconds));
        sessionCredentials = sessionTokenResult.getCredentials();
    }
872911
protected boolean refreshToken() {
		long now = System.currentTimeMillis();
		boolean notExpired = tokenKeyExpires != null && tokenKeyExpires > now;
		boolean canRefresh = tokenKeyNextRefresh != null &&
				(tokenKeyNextRefresh < now || tokenKeyNextRefresh > tokenKeyExpires);
		// token present and NOT expired
		if (tokenKey != null && notExpired && canRefresh) {
			Map<String, Object> result = getEntity(invokeGet(JWT_PATH, null), Map.class);
			if (result != null && result.containsKey("user") && result.containsKey("jwt")) {
				Map<?, ?> jwtData = (Map<?, ?>) result.get("jwt");
				tokenKey = (String) jwtData.get("access_token");
				tokenKeyExpires = (Long) jwtData.get("expires");
				tokenKeyNextRefresh = (Long) jwtData.get("refresh");
				return true;
			} else {
				clearAccessToken();
			}
		}
		return false;
	}
395510
public void revokeToken() {

        URL url = null;
        try {
            url = new URL(this.revokeURL);
        } catch (MalformedURLException e) {
            assert false : "An invalid refresh URL indicates a bug in the SDK.";
            throw new RuntimeException("An invalid refresh URL indicates a bug in the SDK.", e);
        }

        String urlParameters = String.format("token=%s&client_id=%s&client_secret=%s",
                this.accessToken, this.clientID, this.clientSecret);

        BoxAPIRequest request = new BoxAPIRequest(this, url, "POST");
        request.shouldAuthenticate(false);
        request.setBody(urlParameters);

        try {
            request.send();
        } catch (BoxAPIException e) {
            throw e;
        }
    }
327541
public function exchangeRefreshToken($refreshToken)
    {
        return $this->client->exchangeRefreshToken(
            $refreshToken,
            $this->clientId,
            $this->clientSecret
        );
    }
961818
public synchronized void refreshToken()
	{
		final String refreshToken = this.response.refresh_token;

		this.response = null;
		this.cachedInfo = null;

		final String responseStr = authService.getToken(UserManagerOAuthService.GRANT_TYPE_REFRESH_TOKEN,
		                                                null,
		                                                null,
		                                                clientId,
		                                                clientSecret,
		                                                refreshToken,
		                                                null,
		                                                null,
		                                                null);

		loadAuthResponse(responseStr);
	}
565342
public synchronized void refreshWithToken(String clientToken, String accessToken) throws AuthenticationException {
		authResult = authenticationService.refresh(Objects.requireNonNull(clientToken), Objects.requireNonNull(accessToken));
	}
243863
@Restricted(NoExternalUse.class)
    public boolean hasFreshToken(@Nonnull User user, @Nullable ApiTokenProperty.TokenInfoAndStats legacyStats) {
        if (legacyStats == null) {
            return false;
        }
        
        ApiTokenProperty apiTokenProperty = user.getProperty(ApiTokenProperty.class);
        
        return apiTokenProperty.getTokenList().stream()
                .filter(token -> !token.isLegacy)
                .anyMatch(token -> {
                    Date creationDate = token.creationDate;
                    Date lastUseDate = legacyStats.lastUseDate;
                    if (lastUseDate == null) {
                        lastUseDate = legacyStats.creationDate;
                    }
                    return creationDate != null && lastUseDate != null && creationDate.after(lastUseDate);
                });
    }
576849
function() {
        // Get time until expiration minus the refresh offset.
        var waitInterval =
            self.stsTokenManager_.getExpirationTime() - goog.now() -
            fireauth.TokenRefreshTime.OFFSET_DURATION;
        // Set to zero if wait interval is negative.
        return waitInterval > 0 ? waitInterval : 0;
      }
921285
public int refreshToCurrent(int iChangeType, boolean bWarningIfChanged)
    {
        try {
            if ((this.getEditMode() == Constants.EDIT_CURRENT)
                || (this.getEditMode() == Constants.EDIT_IN_PROGRESS))
            {
                Object bookmark = this.getCounterField().getData();
                if (bookmark != null)
                {
                    int iOldOpenMode = this.getOpenMode();
                    this.setOpenMode(Constants.OPEN_REFRESH_TO_CURRENT | (iOldOpenMode/* & Constants.LOCK_TYPE_MASK*/)); // This is only trigger server listeners for changes
                    
                    // First step - backup the current data
                    int iFieldsTypes = BaseBuffer.ALL_FIELDS;
                    BaseBuffer buffer = new VectorBuffer(null, iFieldsTypes);
                    buffer.fieldsToBuffer(this, iFieldsTypes);

                    boolean rgbModified[] = null;
                    if ((iChangeType != Constants.AFTER_DELETE_TYPE)
                        && (this.isModified()))
                    {
                        boolean bLockRecord = this.getEditMode() == Constants.EDIT_IN_PROGRESS;
                        // Second step, save which fields have been modified.
                        rgbModified = new boolean[this.getFieldCount()];
                        for (int iFieldSeq = 0; iFieldSeq < this.getFieldCount(); iFieldSeq++)
                        {
                            rgbModified[iFieldSeq] = this.getField(iFieldSeq).isModified();
                        }
                        // Third step - refresh the record
                        String strOldKey = this.getKeyName();
                        this.setKeyName(Constants.PRIMARY_KEY);
                        this.getCounterField().setData(bookmark);
                        boolean bSuccess = this.getTable().seek(null);
                        this.setKeyName(strOldKey);
                        // Forth step - Move the changed fields to the refreshed record
                        if (!bSuccess)
                            this.getTable().addNew();
                        else
                        {
                            if (bLockRecord)
                                this.getTable().edit();    // If I haven't changed any data, just refresh it.
                            buffer.resetPosition();
                            for (int iFieldSeq = 0; iFieldSeq < this.getFieldCount(); iFieldSeq++)
                            {
                                Object dataScreen = buffer.getNextData();
                                if (rgbModified[iFieldSeq])
                                {
                                    FieldInfo field = this.getField(iFieldSeq);
                                    Object dataUpdated = field.getData();
                                    if (((dataUpdated != null) && (!dataUpdated.equals(dataScreen)))
                                        || ((dataUpdated == null) && (dataScreen != dataUpdated)))
                                            field.setData(dataScreen);
                                }
                            }
                        }
                    }
                    else
                    {
                        this.getTable().addNew();    // Clear current bookmark
                        if (iChangeType != Constants.AFTER_DELETE_TYPE)
                        {
                            String strOldKey = this.getKeyName();
                            this.setKeyName(Constants.PRIMARY_KEY);
                            this.getCounterField().setData(bookmark);
                            this.getTable().seek(null);
                            this.setKeyName(strOldKey);
                        }
                    }
                    this.setOpenMode(iOldOpenMode);
                    buffer.resetPosition();
                    for (int iFieldSeq = 0; iFieldSeq < this.getFieldCount(); iFieldSeq++)
                    {
                        FieldInfo field = this.getField(iFieldSeq);
                        boolean bIsModified = false;
                        if (rgbModified != null)
                            if (rgbModified[iFieldSeq] == false)
                                bIsModified = field.isModified();   // If it wasn't modified until now, flag it.

                        Object dataScreen = buffer.getNextData();
                        Object dataUpdated = field.getData();
                        if (((dataUpdated != null) && (!dataUpdated.equals(dataScreen)))
                            || ((dataUpdated == null) && (dataScreen != dataUpdated)))
                                bIsModified = true;     // Changed somewhere else, better call fieldChanged just in case I read secondary or something.
                        if (bIsModified)
                        {
                            if ((this.getField(iFieldSeq).isVirtual())
                                && (!this.getField(iFieldSeq).isModified())
                                    && (this.getField(iFieldSeq).getData() == this.getField(iFieldSeq).getDefault()))
                            {   // Virtual fields that were not changed, need to be returned to their former value
                                this.getField(iFieldSeq).setData(dataScreen);
                                this.getField(iFieldSeq).setModified(false);
                            }
//                            else
//                                this.getFieldInfo(iFieldSeq).handleFieldChanged(true, Constants.SCREEN_MOVE); // Typical
                        }
                    }
                }
            }
        } catch (DBException ex) {
            ex.printStackTrace();
        }
        return Constants.NORMAL_RETURN;
    }
1202283
def refresh_token!(refresh_token)
      old_token = OAuth2::AccessToken.new(oauth_client,'', refresh_token: refresh_token)
      self.access_token = old_token.refresh!
    end