Re-authenticate if session expired.
325812
def authenticated(function):
    """"""
    def wrapped(*args):
        """Wrap function."""
        try:
            return function(*args)
        except FedexError:
            _login(*args)
            return function(*args)
    return wrapped
573609
def _is_expired_response(self, response):
        
        if response.status_code != 401:
            return False
        challenge = response.headers.get('www-authenticate', '')
        return 'error="invalid_token"' in challenge
438065
function getSession(sessions, sessionId) {
  var sess = sessions[sessionId]

  if (!sess) {
    debug('no session in MemoryStore for %s',sessionId);
    return;
  }

  // parse
  sess = JSON.parse(sess)

  var expires = typeof sess.cookie.expires === 'string' ?
    new Date(sess.cookie.expires) :
    sess.cookie.expires

  // destroy expired session
  if (expires && expires <= Date.now()) {
    debug('Session %s is Expired in MemoryStore',sessionId);
    delete sessions[sessionId];
    return;
  }

  return sess
}
356003
def _authenticate(self):
        """"""
        login_info = self._apicall('login')
        self.api_session_id = login_info['apisessionid']
        if not self.api_session_id:
            raise Exception('Login failed')
        # query ttl and verify access to self.domain:
        zone_info = self._apicall('infoDnsZone', domainname=self.domain)
        self.zone_ttl = zone_info['ttl']
818834
def authenticate(self, request, **credentials):
        """"""
        from allauth.account.auth_backends import AuthenticationBackend

        self.pre_authenticate(request, **credentials)
        AuthenticationBackend.unstash_authenticated_user()
        user = authenticate(request, **credentials)
        alt_user = AuthenticationBackend.unstash_authenticated_user()
        user = user or alt_user
        if user and app_settings.LOGIN_ATTEMPTS_LIMIT:
            cache_key = self._get_login_attempts_cache_key(
                request, **credentials)
            cache.delete(cache_key)
        else:
            self.authentication_failed(request, **credentials)
        return user
75387
def www_authenticate(self):
        """"""
        def on_update(www_auth):
            if not www_auth and 'www-authenticate' in self.headers:
                del self.headers['www-authenticate']
            elif www_auth:
                self.headers['WWW-Authenticate'] = www_auth.to_header()
        header = self.headers.get('www-authenticate')
        return parse_www_authenticate_header(header, on_update)
740859
def attempt_reauthorization(blink):
    """"""
    _LOGGER.info("Auth token expired, attempting reauthorization.")
    headers = blink.get_auth_token(is_retry=True)
    return headers
1333971
private void refreshAccessToken() {
    final Long expiresIn = credential.getExpiresInSeconds();

    // trigger refresh if token is about to expire
    String accessToken = credential.getAccessToken();
    if (accessToken == null || expiresIn != null && expiresIn <= 60) {
      try {
        credential.refreshToken();
        accessToken = credential.getAccessToken();
      } catch (final IOException e) {
        log.error("Failed to fetch access token", e);
      }
    }
    if (accessToken != null) {
      this.accessToken = accessToken;
    }
  }
1332475
def clean_expired_tokens(opts):
    '''
    
    '''
    loadauth = salt.auth.LoadAuth(opts)
    for tok in loadauth.list_tokens():
        token_data = loadauth.get_tok(tok)
        if 'expire' not in token_data or token_data.get('expire', 0) < time.time():
            loadauth.rm_token(tok)
850253
def authenticate(self):
        """"""
        if self.__token:
            try:
                resp = self._refresh_token()
            except exceptions.TVDBRequestException as err:
                # if a 401 is the cause try to login
                if getattr(err.response, 'status_code', 0) == 401:
                    resp = self._login()
                else:
                    raise
        else:
            resp = self._login()

        self.__token = resp.get('token')
        self._token_timer = timeutil.utcnow()
1243386
def _authenticate(self):
        """"""
        if not self._get_provider_option(
                'auth_username') or not self._get_provider_option('auth_password'):
            raise Exception(
                'No valid authentication data passed, expected: auth-username and auth-password')
        response = self._request_login(self._get_provider_option('auth_username'),
                                       self._get_provider_option('auth_password'))
        if 'ssid' in response:
            self.ssid = response['ssid']
            domains = self.domains_list()
            if any((domain['name'] == self.domain for domain in domains)):
                self.domain_id = self.domain
            else:
                raise Exception("Unknown domain {}".format(self.domain))
        else:
            raise Exception("No SSID provided by server")
456636
def check_security!
      if controller
        if cookies[:browser_id] != self.browser_id
          invalidate!
          Authie.config.events.dispatch(:browser_id_mismatch_error, self)
          raise BrowserMismatch, "Browser ID mismatch"
        end

        unless self.active?
          invalidate!
          Authie.config.events.dispatch(:invalid_session_error, self)
          raise InactiveSession, "Session is no longer active"
        end

        if self.expired?
          invalidate!
          Authie.config.events.dispatch(:expired_session_error, self)
          raise ExpiredSession, "Persistent session has expired"
        end

        if self.inactive?
          invalidate!
          Authie.config.events.dispatch(:inactive_session_error, self)
          raise InactiveSession, "Non-persistent session has expired"
        end

        if self.host && self.host != controller.request.host
          invalidate!
          Authie.config.events.dispatch(:host_mismatch_error, self)
          raise HostMismatch, "Session was created on #{self.host} but accessed using #{controller.request.host}"
        end
      end
    end
1115790
def expired(self):
        """"""
        self._data["_killed"] = True
        self.save()
        raise SessionExpired(self._config.expired_message)
252144
def authenticated_session(username, password):
    
    session = requests.Session()
    session.headers.update(headers())

    response = session.get(url())
    login_path = path(response.text)
    login_url = urljoin(response.url, login_path)
    login_post_data = post_data(response.text, username, password)

    response = session.post(login_url, data=login_post_data)
    if response.headers['connection'] == 'close':
        raise Exception('Authencation failed')

    return session
306568
def reset_password(token):
    """"""

    expired, invalid, user = reset_password_token_status(token)

    if not user or invalid:
        invalid = True
        do_flash(*get_message('INVALID_RESET_PASSWORD_TOKEN'))

    if expired:
        send_reset_password_instructions(user)
        do_flash(*get_message('PASSWORD_RESET_EXPIRED', email=user.email,
                              within=_security.reset_password_within))
    if invalid or expired:
        return redirect(url_for('forgot_password'))

    form = _security.reset_password_form()

    if form.validate_on_submit():
        after_this_request(_commit)
        update_password(user, form.password.data)
        do_flash(*get_message('PASSWORD_RESET'))
        return redirect(get_url(_security.post_reset_view) or
                        get_url(_security.login_url))

    return _security.render_template(
        config_value('RESET_PASSWORD_TEMPLATE'),
        reset_password_form=form,
        reset_password_token=token,
        **_ctx('reset_password')
    )
319476
function expireSessionIDs(){
    var tssec = Date.now();
    var expired = [];
    for(var sid in sessionIDs){
        if(sessionIDs[sid] < (tssec + 500)){
            expired.push(sid);
        }
    }
    for(var i=0;i<expired.length;i++){
        delete sessionIDs[expired[i]];
        debug('Session ID expired: %s', expired[i]);
    }
}
838927
def process_request(self, request):
        
        
        if django.VERSION < (1, 10):
            is_authenticated = request.user.is_authenticated()
        else:
            is_authenticated = request.user.is_authenticated

        if not is_authenticated:
            return

        now = datetime.now()
        if '_session_security' not in request.session:
            set_last_activity(request.session, now)
            return

        delta = now - get_last_activity(request.session)
        expire_seconds = self.get_expire_seconds(request)
        if delta >= timedelta(seconds=expire_seconds):
            logout(request)
        elif (request.path == reverse('session_security_ping') and
                'idleFor' in request.GET):
            self.update_last_activity(request, now)
        elif not self.is_passive_request(request):
            set_last_activity(request.session, now)