Check if a refresh of the token is needed
187015
def _requires_refresh_token(self):
        
        expires_on = datetime.datetime.strptime(
            self.login_data['token']['expiresOn'], '%Y-%m-%dT%H:%M:%SZ')
        refresh = datetime.datetime.utcnow() + datetime.timedelta(seconds=30)
        return expires_on < refresh
984289
public function invalidateCurrentRefreshToken()
    {
        if ($this->grant === 'client_credentials') {
            return;
        }

        $token = $this->getAccessToken();
        if ($token) {
            $this->invalidateRefreshToken($token);
        }
    }
534990
def _refresh(self):
        
        # Request and set a new API token.
        new_token = self.authenticate(self._username, self._password)
        self._token = new_token
        logger.info('New API token received: "{}".'.format(new_token))
        return self._token
704110
def needs_refresh(self, source):
        
        now = time.time()
        if source._tok in self:
            s0 = self[source._tok]
            if self[source._tok].metadata.get('ttl', None):
                then = s0.metadata['timestamp']
                if s0.metadata['ttl'] < then - now:
                    return True
            return False
        return True
1289541
def refresh(self):
        
        data = {
            'grant_type': 'refresh_token',
            'refresh_token': self._token.refresh_token
        }

        response = self.http_client.post(self.URL, data=data, auth=(self.client_id, self.client_secret))
        response.raise_for_status()
        self._token = Token.from_json(response.json())
861006
def check_sync(self):
        """"""
        # If refresh interval is not specified, we should refresh every time.
        expiration = utcnow()
        refresh_td = current_app.config.get('GITHUB_REFRESH_TIMEDELTA')
        if refresh_td:
            expiration -= refresh_td
        last_sync = parse_timestamp(self.account.extra_data['last_sync'])
        return last_sync < expiration
721205
def refresh_token(self, request, data, client):
        
        rt = self.get_refresh_token_grant(request, data, client)

        # this must be called first in case we need to purge expired tokens
        self.invalidate_refresh_token(rt)
        self.invalidate_access_token(rt.access_token)

        at = self.create_access_token(request, rt.user, rt.access_token.scope,
                client)
        rt = self.create_refresh_token(request, at.user, at.scope, at, client)

        return self.access_token_response(at)
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'))}
307967
def verify_http_auth_refresh_token(self) -> bool:
        
        authorization_token = self.get_http_token()
        if authorization_token is not None:
            if self.verify_refresh_token(authorization_token):
                if self.data is not None:
                    self.data = self.data['data']
                    return True
                return False
            else:
                return False
        return False
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
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
759881
def stop_refreshing_token(self):
        
        with self.lock:
            self.timer_stopped = True
            self.timer.cancel()
186965
def refresh_session_if_necessary(f):
    

    @functools.wraps(f)
    def wrapped(self, *args, **kwargs):
        try:
            result = f(self, *args, **kwargs)
        except Exception as ex:
            if hasattr(ex, 'code') and ex.code in (401, 403):
                self.refresh_session()
                # retry now
                result = f(self, *args, **kwargs)
            else:
                raise ex

        return result

    return wrapped
447111
def refresh():
    
    old_token = guard.read_token_from_header()
    new_token = guard.refresh_jwt_token(old_token)
    ret = {'access_token': new_token}
    return flask.jsonify(ret), 200
395435
def refresh(self):
        """"""
        if self.refresh_token is None:
            raise InvalidInvocation("refresh token not provided")
        self._request_token(
            grant_type="refresh_token", refresh_token=self.refresh_token
        )
218083
def refresh(self, client_name, refresh_token, **params):
        
        client = self.client(client_name, logger=self.app.logger)
        return client.get_access_token(refresh_token, grant_type='refresh_token', **params)
1374927
def _get_token(self, request, refresh_token=False):
        
        if self.config.cookie_set():
            token = self._get_token_from_cookies(request, refresh_token)
            if token:
                return token

            else:
                if self.config.cookie_strict():
                    raise exceptions.MissingAuthorizationCookie()

        if self.config.query_string_set():
            token = self._get_token_from_query_string(request, refresh_token)
            if token:
                return token

            else:
                if self.config.query_string_strict():
                    raise exceptions.MissingAuthorizationQueryArg()

        token = self._get_token_from_headers(request, refresh_token)

        if token:
            return token

        raise exceptions.MissingAuthorizationHeader()