Handles an authentication failure and returns the Response for the
GuardAuthenticator.
180617
public function handleAuthenticationFailure(AuthenticationException $authenticationException, Request $request, AuthenticatorInterface $guardAuthenticator, string $providerKey): ?Response
    {
        $response = $guardAuthenticator->onAuthenticationFailure($request, $authenticationException);
        if ($response instanceof Response || null === $response) {
            // returning null is ok, it means they want the request to continue
            return $response;
        }

        throw new \UnexpectedValueException(sprintf('The %s::onAuthenticationFailure method must return null or a Response object. You returned %s.', \get_class($guardAuthenticator), \is_object($response) ? \get_class($response) : \gettype($response)));
    }
578944
def respond_unauthorized(self, request_authentication=False):
		
		headers = {}
		if request_authentication:
			headers['WWW-Authenticate'] = 'Basic realm="' + self.__config['server_version'] + '"'
		self.send_response_full(b'Unauthorized', status=401, headers=headers)
		return
302626
def _handle_response(self, response):
        
        status = response.status_code
        if status == 400:
          msg = u"bad request"
          raise exceptions.BadRequest(status, msg)
        elif status == 401:
          msg = u"authorization failed user:%s" % (self.sk_user)
          raise exceptions.Unauthorized(status, msg)
        elif status == 404:
          raise exceptions.NotFound()
        elif status == 422:
          msg = u"bad request"
          raise exceptions.BadRequest(status, msg)
        elif status in range(400, 500):
          msg = u"unexpected bad request"
          raise exceptions.BadRequest(status, msg) 
        elif status in range(500, 600):
          raise exceptions.ServerError()
        return response
1086157
function(params, stateData) {
          // Handle an error response from the OAuth server
          if (params.error) {
            authLogger.log("RedirectLoginService.finish(), error", params.error, params.error_description, params.error_uri);
            return $q.reject({
              error: params.error,
              error_description: params.error_description,
              error_uri: params.error_uri
            });
          }

          // Handle an access_token fragment response
          if (params.access_token) {
            return $q.when({
              token: params.access_token,
              ttl: params.expires_in,
              then: stateData.then,
              verified: stateData.verified
            });
          }

          // No token and no error is invalid
          return $q.reject({
            error: "invalid_request",
            error_description: "No API token returned"
          });
        }
723422
private void handleAuthorizationFailure(Response response, Throwable t, JSONObject extendedInfo) {
        logger.error("authorization process failed");

        if (t != null) {
            t.printStackTrace();
        }

        Iterator<ResponseListener> iterator = authorizationQueue.iterator();

        while(iterator.hasNext()) {
            ResponseListener next = iterator.next();
            next.onFailure(response, t, extendedInfo);
            iterator.remove();
        }
    }
45788
public function onAuthenticationFailure(Request $request, AuthenticationException $exception)
    {
        $data = array(
            'message' => strtr($exception->getMessageKey(), $exception->getMessageData())
        );
        $def_response = new JsonResponse($data, 403);

        $event = new CASAuthenticationFailureEvent($request,$exception, $def_response);
        $this->eventDispatcher->dispatch(CASAuthenticationFailureEvent::POST_MESSAGE, $event);

        return $event->getResponse();
    }
1130411
def authenticate(self, request):
        
        authenticators = self._meta.authenticators

        if request.method == 'OPTIONS' and ADREST_ALLOW_OPTIONS:
            self.auth = AnonimousAuthenticator(self)
            return True

        error_message = "Authorization required."
        for authenticator in authenticators:
            auth = authenticator(self)
            try:
                if not auth.authenticate(request):
                    raise AssertionError(error_message)

                self.auth = auth
                auth.configure(request)
                return True
            except AssertionError, e:
                error_message = str(e)

        raise HttpError(error_message, status=status.HTTP_401_UNAUTHORIZED)
912295
def _handle_response(self, response):
        
        if response.status_code == requests.codes.ok or response.status_code == requests.codes.created:
            try:
                return response.json()
            except ValueError:
                return response
        else:
            return self._handle_failed_response(response)
874455
def validate_authentication(self, username, password, handler):
        
        user = authenticate(
            **{self.username_field: username, 'password': password}
        )
        account = self.get_account(username)
        if not (user and account):
            raise AuthenticationFailed("Authentication failed.")
450958
def _handleAuthenticationEvents(self, requestdata, requestaction,
                                    clientuuid, sock):
        """"""

        # TODO: Move this stuff over to ./auth.py
        if requestaction in ("login", "autologin"):
            try:
                self.log("Login request", lvl=verbose)

                if requestaction == "autologin":
                    username = password = None
                    requestedclientuuid = requestdata
                    auto = True

                    self.log("Autologin for", requestedclientuuid, lvl=debug)
                else:
                    username = requestdata['username']
                    password = requestdata['password']

                    if 'clientuuid' in requestdata:
                        requestedclientuuid = requestdata['clientuuid']
                    else:
                        requestedclientuuid = None
                    auto = False

                    self.log("Auth request by", username, lvl=verbose)

                self.fireEvent(authenticationrequest(
                    username,
                    password,
                    clientuuid,
                    requestedclientuuid,
                    sock,
                    auto,
                ), "auth")
                return
            except Exception as e:
                self.log("Login failed: ", e, type(e), lvl=warn, exc=True)
        elif requestaction == "logout":
            self.log("User logged out, refreshing client.", lvl=network)
            try:
                if clientuuid in self._clients:
                    client = self._clients[clientuuid]
                    user_id = client.useruuid
                    if client.useruuid:
                        self.log("Logout client uuid: ", clientuuid)
                        self._logoutclient(client.useruuid, clientuuid)
                    self.fireEvent(clientdisconnect(clientuuid))
                else:
                    self.log("Client is not connected!", lvl=warn)
            except Exception as e:
                self.log("Error during client logout: ", e, type(e),
                         lvl=error, exc=True)
        else:
            self.log("Unsupported auth action requested:",
                     requestaction, lvl=warn)
1063849
protected void handle(Authentication authentication) throws IOException, ServletException {
        HttpServletRequest request = http.getCurrentRequest();
        HttpServletResponse response = http.getCurrentResponse();
        String targetUrl = determineTargetUrl(request, response);

        if (response.isCommitted()) {
            logger.debug("Response has already been committed. Unable to redirect to " + targetUrl);
            return;
        } else {
            logger.debug("Redirecting to " + targetUrl);
        }

        redirectStrategy.sendRedirect(targetUrl);
    }
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);
    }
360933
def handle_exception(self, exc):
        
        if isinstance(exc, (exceptions.NotAuthenticated,
                            exceptions.AuthenticationFailed)):
            # WWW-Authenticate header for 401 responses, else coerce to 403
            auth_header = self.get_authenticate_header(self.request)

            if auth_header:
                exc.auth_header = auth_header
            else:
                exc.status_code = status.HTTP_403_FORBIDDEN

        exception_handler = self.settings.EXCEPTION_HANDLER

        context = self.get_exception_handler_context()
        response = exception_handler(exc, context)

        if response is None:
            raise

        response.exception = True
        return response
415380
private function _handleAutoLogin()
    {
        $credentials = $this->_getRememberMeCredentials();

        if (!empty($credentials)) {
            if ($this->_authenticate($credentials)) {
                $this->_login($credentials);
            }
        }
    }
1253446
def authenticate(self):
        
        if request.headers.get('Authorization') or request.args.get('access_token'):
            realm = 'Bearer realm="%s", error="invalid_token"' % __package__
        else:
            realm = 'Bearer realm="%s"' % __package__
        resp = Response(None, 401, {'WWW-Authenticate': realm})
        abort(401, description='Please provide proper credentials', response=resp)
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
412630
public function authenticate()
    {
        if (!is_null($this->token)) {
            return;
        }

        $response = $this->authenticationResponse();

        if (!$response->hasHeader('X-Auth-Token')) {
            throw new AuthenticationFailedException('Given credentials are wrong.', 403);
        }

        if (!$response->hasHeader('X-Storage-Url')) {
            throw new RuntimeException('Storage URL is missing.', 500);
        }

        $this->token = $response->getHeaderLine('X-Auth-Token');
        $this->storageUrl = $response->getHeaderLine('X-Storage-Url');
    }