Determines if this connection's access token has expired and needs to be refreshed.
@return true if the access token needs to be refreshed; otherwise false.
336128
public boolean needsRefresh() {
        boolean needsRefresh;

        this.refreshLock.readLock().lock();
        long now = System.currentTimeMillis();
        long tokenDuration = (now - this.lastRefresh);
        needsRefresh = (tokenDuration >= this.expires - REFRESH_EPSILON);
        this.refreshLock.readLock().unlock();

        return needsRefresh;
    }
545531
private String getRefreshToken(Token accessToken) {
    JSONObject rawJson = JSONObject.fromObject(accessToken.getRawResponse());
    return rawJson.getString("refresh_token");
  }
1175934
private AccessToken getAccessToken() throws IOException {
    // synchronize attempts to refresh the accessToken
    synchronized (credentials) {
      if (needsRefresh(credentials.getAccessToken())) {
        credentialRefresher.refresh(credentials);
      }
    }
    return credentials.getAccessToken();
  }
1372330
private function refresh(): bool
    {
        //check for login data on in current session
        if (empty($this->session->login)) {
            return false;
        }

        //take time
        $time = \time();

        //check if login expired
        if (($this->session->loginTime + $this->session->expire) < $time) {
            return false;
        }

        //update login data
        $this->session->loginTime = $time;
        $this->data = $this->session->login;

        return true;
    }
357672
protected int getRefreshTokenValiditySeconds(OAuth2Request clientAuth) {
		if (clientDetailsService != null) {
			ClientDetails client = clientDetailsService.loadClientByClientId(clientAuth.getClientId());
			Integer validity = client.getRefreshTokenValiditySeconds();
			if (validity != null) {
				return validity;
			}
		}
		return refreshTokenValiditySeconds;
	}
94427
def _check_token(self):
        
        need_token = (self._token_info is None or
                      self.auth_handler.is_token_expired(self._token_info))
        if need_token:
            new_token = \
                self.auth_handler.refresh_access_token(
                    self._token_info['refresh_token'])
            # skip when refresh failed
            if new_token is None:
                return

            self._token_info = new_token
            self._auth_header = {"content-type": "application/json",
                                 "Authorization": "Bearer {}".format(
                                     self._token_info.get('access_token'))}
583415
public synchronized boolean isClientAuthenticationEnabled() {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            Tr.entry(tc, "isClientAuthenticationEnabled");
        boolean auth = false;

        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            Tr.exit(tc, "isClientAuthenticationEnabled", Boolean.valueOf(auth));
        return auth;
    }
825500
private function getAccessToken($expired = false) {
        // Refresh the access token if force refresh or the expiretime has passed
        if ($expired || isset($this->expireTime) && $this->expireTime <= time()) {
            // If there is no refresh token throw exception
            if (!isset($this->refreshToken)) {
                throw new OAuthException('Token expired but no refresh token found');
            }

            $this->refreshAccessToken();
        }
        // If there no access token fetch one
        else if (!$expired && !isset($this->accessToken)) {
            $this->fetchAccessToken();
        }

        // If there still is no access token at this point. Throw exception
        if (!isset($this->accessToken)) {
            throw new OAuthException('No access token found');
        }

        return $this->accessToken;
    }
1370482
protected boolean isRefreshTokenSupported(String grantType, Set<String> scope) {
        if (!isRestrictRefreshGrant) {
            return GRANT_TYPE_AUTHORIZATION_CODE.equals(grantType) ||
                GRANT_TYPE_PASSWORD.equals(grantType) ||
                GRANT_TYPE_USER_TOKEN.equals(grantType) ||
                GRANT_TYPE_REFRESH_TOKEN.equals(grantType) ||
                GRANT_TYPE_SAML2_BEARER.equals(grantType);
        } else {
            return scope.contains(UAA_REFRESH_TOKEN);
        }
    }
790674
@Restricted(NoExternalUse.class)
    public boolean hasMoreRecentlyUsedToken(@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 currentLastUseDate = token.lastUseDate;
                    Date legacyLastUseDate = legacyStats.lastUseDate;
                    if (legacyLastUseDate == null) {
                        legacyLastUseDate = legacyStats.creationDate;
                    }
                    return currentLastUseDate != null && legacyLastUseDate != null && currentLastUseDate.after(legacyLastUseDate);
                });
    }
1018037
def refresh(self):
        
        endpoint = '/refresh'

        payload = {
            'accessToken': self.access_token,
            'clientToken': self.client_token,
        }
        rep = self._ygg_req(endpoint, payload)
        if not rep or 'error' in rep:
            return False

        self.access_token = rep['accessToken']
        self.client_token = rep['clientToken']
        self.selected_profile = rep['selectedProfile']
        return True
1190459
def refresh_token
      debug { "Performing token refresh" }
      return false if token.nil?
      return false if token['refresh_token'].nil?
      uri = URI.parse(token_account['token_endpoint'])
      endpoint_data = { path: uri.path }
      endpoint_data[:host] = uri.host if uri.host
      endpoint_data[:port] = uri.port if uri.port

      debug { "Token refresh endpoint: #{endpoint_data.inspect}" }

      return false unless endpoint_data[:path]

      response = request(
        {
          http_method: token_account['token_method'].downcase.to_sym,
          body: refresh_request_params,
          headers: {
            CONTENT_TYPE => token_account['token_post_content_type']
          }.merge(
            token_account['code_requires_basic_auth'] ? basic_auth_header : {}
          ),
          expects: [200, 201, 400, 401, 403],
          auth: false
        }.merge(endpoint_data)
      )

      if response && response['access_token']
        debug { "Got response to refresh request" }
        token['access_token']  = response['access_token']
        token['refresh_token'] = response['refresh_token']
        token['expires_at'] = in_to_at(response['expires_in'])
        token.config.write if token.respond_to?(:config)
        true
      else
        debug { "Got null or bad response to refresh request: #{last_response.inspect}" }
        false
      end
    rescue => ex
      error { "Access token refresh exception" }
      error { ex }
      false
    end
483287
protected Boolean needAuth() {
        if (isBceKey.get()) {
            return false;
        }
        Calendar c = Calendar.getInstance();
        c.add(Calendar.DATE, 1);
        return !isAuthorized.get() || c.after(expireDate);
    }
1178562
def is_authorization_expired(self):
        
        if not self.auth.token_expiration:
            return True
        return (datetime.datetime.utcnow() > self.auth.token_expiration)
1142546
public function refreshIfExpired()
    {
        $user = $this->getFrameworkBridge()->getCurrentUser();

        if (! $user) {
            return null;
        }

        $token = $user->getOAuthToken();
        if ($token && $token->hasExpired()) {
            $this->refreshAccessToken($token);
        }
    }
461732
def refresh!
      raise CredentialsMissingError.new("No credentials to refresh") unless access_token
      raise CredentialsMissingError.new("No refresh_token provided") unless access_token.refresh_token

      do_request do
        @access_token = access_token.refresh!
        Credentials.new(@access_token)
      end
    end
362695
@JsonIgnore
    protected boolean isAccessTokenExpired(final TicketState ticketState) {
        val currentSystemTime = ZonedDateTime.now(ZoneOffset.UTC);
        val creationTime = ticketState.getCreationTime();

        var expirationTime = creationTime.plus(this.maxTimeToLiveInSeconds, ChronoUnit.SECONDS);
        if (currentSystemTime.isAfter(expirationTime)) {
            LOGGER.debug("Access token is expired because the time since creation is greater than maxTimeToLiveInSeconds");
            return true;
        }

        val expirationTimeToKill = ticketState.getLastTimeUsed().plus(this.timeToKillInSeconds, ChronoUnit.SECONDS);
        if (currentSystemTime.isAfter(expirationTimeToKill)) {
            LOGGER.debug("Access token is expired because the time since last use is greater than timeToKillInSeconds");
            return true;
        }
        return false;
    }