Takes the given response and tries digest-auth, if needed.
330111
def handle_401(self, response, exc=None):
        """"""
        if response.status_code == 401:
            s_auth = response.headers.get('www-authenticate', '')
            if 'digest' not in s_auth.lower():
                return
            request = response.request
            if not request.headers.get('authorization'):
                self.options = parse_dict_header(s_auth.replace('Digest ', ''))
                authorization = self.encode(request.method, request.url)
                params = request.inp_params.copy()
                headers = params.pop('headers', [])
                headers.append(('authorization', authorization))
                params['headers'] = headers
                response.request_again = request_again(request.method,
                                                       request.url,
                                                       params)
1060447
function authorize (req, res, next) {
  var params = req.connectParams
  var responseTypes = params.response_type.trim().split(' ')
  var responseMode = (params.response_mode && params.response_mode.trim()) ||
    (params.response_type === 'code' ||
      params.response_type === 'none') ? '?' : '#'

  // ACCESS GRANTED
  if (params.authorize === 'true') {
    // compose the response
    async.waterfall([

      function includeAccessToken (callback) {
        if (responseTypes.indexOf('token') !== -1) {
          AccessToken.issue(req, function (err, response) {
            if (err) { return callback(err) }
            callback(null, response)
          })

        // initialize an empty response
        } else {
          callback(null, {})
        }
      },

      function includeAuthorizationCode (response, callback) {
        if (responseTypes.indexOf('code') !== -1) {
          AuthorizationCode.insert({
            client_id: req.client._id,
            redirect_uri: params.redirect_uri,
            nonce: params.nonce,
            max_age: parseInt(params.max_age, 10) || req.client.default_max_age,
            user_id: req.user._id,
            scope: req.scope

          }, function (err, ac) {
            if (err) { return callback(err) }
            response.code = ac.code
            callback(null, response)
          })

        // pass through to next
        } else {
          callback(null, response)
        }
      },

      function includeIDToken (response, callback) {
        if (responseTypes.indexOf('id_token') !== -1) {
          var shasum, hash, atHash

          if (response.access_token) {
            shasum = crypto.createHash('sha256')
            shasum.update(response.access_token)
            hash = shasum.digest('hex')
            atHash = hash.slice(0, hash.length / 2)
          }

          var idToken = new IDToken({
            iss: settings.issuer,
            sub: req.user._id,
            aud: req.client._id,
            exp: nowSeconds(response.expires_in),
            nonce: params.nonce,
            at_hash: atHash,
            amr: req.session.amr
          })

          response.id_token = idToken.encode(settings.keys.sig.prv)
        }

        callback(null, response)
      }

    ], function (err, response) {
      if (err) { return next(err) }

      if (params.state) {
        response.state = params.state
      }

      // Set the OP browser state.
      var opbs = req.session.opbs

      // if responseTypes includes id_token or token
      // calculate session_state and add to response
      if (responseTypes.indexOf('id_token') !== -1 ||
        responseTypes.indexOf('token') !== -1) {
        var session = sessionState(req.client, req.client.client_uri, opbs)
        response.session_state = session
      }

      res.redirect(
        params.redirect_uri + responseMode + qs.stringify(response)
      )
    })

  // ACCESS DENIED
  } else {
    res.redirect(params.redirect_uri + '?error=access_denied')
  }
}
1222580
def process_response(self, request, response):
        
        if not self.should_cache(request, response):
            # We don't need to update the cache, just return
            return response 

        response = self.patch_headers(response)
        self.set_cache(request, response)

        return response
1841
public Request processAuthChallenge(Response response, Request req_msg) {
    return processAuthChallenge(response, req_msg, null, null);
  }
11943
def authenticated?(attribute, token)
      return false unless respond_to?("#{attribute}_digest")
      digest = send("#{attribute}_digest")
      return false if digest.blank?
      BCrypt::Password.new(digest).is_password?(token)
    end
752036
def authenticate(self):
        """"""
        endpoint = os.path.join(self.config.get('napps', 'api'), 'auth', '')
        username = self.config.get('auth', 'user')
        password = getpass("Enter the password for {}: ".format(username))
        response = requests.get(endpoint, auth=(username, password))
        if response.status_code != 201:
            LOG.error(response.content)
            LOG.error('ERROR: %s: %s', response.status_code, response.reason)
            sys.exit(1)
        else:
            data = response.json()
            KytosConfig().save_token(username, data.get('hash'))
            return data.get('hash')
365097
function(realm, err, cbreqauth) {
        if (!(err instanceof Exc.jsDAV_Exception))
            err = new Exc.NotAuthenticated(err);

        var currQop = "";
        switch (this.qop) {
            case QOP_AUTH:
                currQop = "auth";
                break;
            case QOP_AUTHINT:
                currQop = "auth-int";
                break;
            case QOP_AUTH | QOP_AUTHINT:
                currQop = "auth,auth-int";
                break;
        }

        err.addHeader("WWW-Authenticate", "Digest realm=\"" + realm + 
            "\",qop=\"" + currQop + "\",nonce=\"" + this.nonce + 
            "\",opaque=\"" + this.opaque + "\"");
        cbreqauth(err, false);
    }
561495
def handle_authn_response(self, context, internal_resp, extra_id_token_claims=None):
        

        auth_req = self._get_authn_request_from_state(context.state)

        attributes = self.converter.from_internal("openid", internal_resp.attributes)
        self.user_db[internal_resp.subject_id] = {k: v[0] for k, v in attributes.items()}
        auth_resp = self.provider.authorize(
            auth_req,
            internal_resp.subject_id,
            extra_id_token_claims=extra_id_token_claims,
        )

        del context.state[self.name]
        http_response = auth_resp.request(auth_req["redirect_uri"], should_fragment_encode(auth_req))
        return SeeOther(http_response)
1094672
def digest_auth(user, password)
      builder.insert(0, Faraday::Request::DigestAuth, user, password)
    end
925263
def digest_auth(realm, auth_func):
    
    def digest_auth_decorator(func):
        def func_replacement(self, *args, **kwargs):
            # 'self' here is the RequestHandler object, which is inheriting
            # from DigestAuthMixin to get 'get_authenticated_user'
            if self.get_authenticated_user(auth_func, realm):
                return func(self, *args, **kwargs)
        return func_replacement
    return digest_auth_decorator
173440
def process_auth_plain(session, encoded_auth_response)
      begin
        # extract auth id (and password)
        @auth_values = Base64.decode64(encoded_auth_response).split("\x00")
        # check for valid credentials parameters
        raise Smtpd500Exception unless @auth_values.length == 3
        # call event function to test credentials
        return_value = on_auth_event(session[:ctx], @auth_values[0], @auth_values[1], @auth_values[2])
        if return_value
          # overwrite data with returned value as authorization id
          @auth_values[0] = return_value
        end
        # save authentication information to ctx
        session[:ctx][:server][:authorization_id] = @auth_values[0].to_s.empty? ? @auth_values[1] : @auth_values[0]
        session[:ctx][:server][:authentication_id] = @auth_values[1]
        session[:ctx][:server][:authenticated] = Time.now.utc
        # response code
        return '235 OK'

      ensure
        # whatever happens in this check, reset next sequence
        session[:cmd_sequence] = :CMD_RSET
      end
    end
1244235
def authenticate(self):
        
        resp = self.session.get(self.api_url, auth=self.auth)
        resp = self._process_response(resp)
        return resp
560317
def process_response(self, request, response):
        """"""

        # never cache headers + ETag
        add_never_cache_headers(response)

        if not hasattr(request, '_cache_update_cache') or not request._cache_update_cache:
            # We don't need to update the cache, just return.
            return response
        if request.method != 'GET':
            # This is a stronger requirement than above. It is needed
            # because of interactions between this middleware and the
            # HTTPMiddleware, which throws the body of a HEAD-request
            # away before this middleware gets a chance to cache it.
            return response
        if not response.status_code == 200:
            return response

        # use the precomputed cache_key
        if request._cache_middleware_key:
            cache_key = request._cache_middleware_key
        else:
            cache_key = learn_cache_key(request, response, self.cache_timeout, self.key_prefix)

        # include the orig_time information within the cache
        cache.set(cache_key, (time.time(), response), self.cache_timeout)
        return response
730105
function authenticateUser (req, res, next) {
  // Check for verified access token
  if (req.claims && req.claims.sub) {
    User.get(req.claims.sub, function (err, user) {
      if (err) {
        return next(err)
      }

      if (!user) {
        return next(new UnauthorizedError({
          realm: 'user',
          error: 'unknown_user',
          error_description: 'Unknown user',
          statusCode: 401
        }))
      }

      req.user = user
      next()
    })

  // User is not authenticated.
  } else if (!req.user) {
    next(new UnauthorizedError({
      statusCode: 401
    }))

  // User is authenticated.
  } else {
    next()
  }
}
1203046
def process(self, request, response, environ):
        
        data = self.authorize(request, response, environ,
                              self.scope_handler.scopes)

        if isinstance(data, Response):
            return data

        code = self.token_generator.generate()
        expires = int(time.time()) + self.token_expiration

        auth_code = AuthorizationCode(client_id=self.client.identifier,
                                      code=code, expires_at=expires,
                                      redirect_uri=self.client.redirect_uri,
                                      scopes=self.scope_handler.scopes,
                                      data=data[0], user_id=data[1])

        self.auth_code_store.save_code(auth_code)

        response.add_header("Location", self._generate_location(code))
        response.body = ""
        response.status_code = 302

        return response
430904
def after_request(response)
      @response = HTTParty::Response.new(self, response, -> { HTTParty::Parser.new(response.body, Jiralicious::Session.format).parse }, body: response.body)
    end
113446
def handle_401(self, response, **kwargs):
        """"""

        log.debug("handle_401(): Handling: 401")
        if _negotiate_value(response) is not None:
            _r = self.authenticate_user(response, **kwargs)
            log.debug("handle_401(): returning {0}".format(_r))
            return _r
        else:
            log.debug("handle_401(): Kerberos is not supported")
            log.debug("handle_401(): returning {0}".format(response))
            return response