src/Abstracts/AuthenticationMiddleware.php
public function call() {
        /* If rules say we should not authenticate call next and return. */
        if (false === $this->shouldAuthenticate()) {
            $this->next->call();
            return;
        }

        $this->checkSecure();

        $freePass = $this->hasFreePass();

        /* If userdata cannot be found return with 401 Unauthorized. */
        if ((false === $this->data = $this->fetchData()) && !$freePass) {
            $this->callError();
            return;
        }

        if (false === $this->data && $freePass) {
            $this->next->call();
            return;
        }

        /* Check if user authenticates. */
        $authenticator = $this->options["authenticator"];

        if (false === $authenticator($this->data)) {
            $this->error = $authenticator->getError();
            $this->callError();
            return;
        }

        $this->app->userData = $authenticator->getData();

        if (!$this->customValidation()) {
            $this->callError();
            return;
        }

        /* If callback returns false return with 401 Unauthorized. */
        if (is_callable($this->options["callback"])) {
            $params = $this->getParams();
            if (false === $this->options["callback"]($params)) {
                $this->error = new Error();
                $this->error->setDescription("Callback returned false");
                $this->callError();
                return;
            }
        }

        /* Everything ok, call next middleware. */
        $this->next->call();
    }
public function call() {
        /* If rules say we should not authenticate call next and return. */
        if (false === $this->shouldAuthenticate()) {
            $this->next->call();
            return;
        }

        $this->checkSecure();

        $freePass = $this->hasFreePass();

        /* If userdata cannot be found return with 401 Unauthorized. */
        if ((false === $this->data = $this->fetchData()) && !$freePass) {
            $this->callError();
            return;
        }

        if (false === $this->data && $freePass) {
            $this->next->call();
            return;
        }

        /* Check if user authenticates. */
        $authenticator = $this->options["authenticator"];

        if (false === $authenticator($this->data)) {
            $this->error = $authenticator->getError();
            $this->callError();
            return;
        }

        $this->app->userData = $authenticator->getData();

        if (!$this->customValidation()) {
            $this->callError();
            return;
        }

        /* If callback returns false return with 401 Unauthorized. */
        if (is_callable($this->options["callback"])) {
            $params = $this->getParams();
            if (false === $this->options["callback"]($params)) {
                $this->error = new Error();
                $this->error->setDescription("Callback returned false");
                $this->callError();
                return;
            }
        }

        /* Everything ok, call next middleware. */
        $this->next->call();
    }
public function call ( ) { /* If rules say we should not authenticate call next and return. */ if ( false === $ this -> shouldAuthenticate ( ) ) { $ this -> next -> call ( ) ; return ; } $ this -> checkSecure ( ) ; $ freePass = $ this -> hasFreePass ( ) ; /* If userdata cannot be found return with 401 Unauthorized. */ if ( ( false === $ this -> data = $ this -> fetchData ( ) ) && ! $ freePass ) { $ this -> callError ( ) ; return ; } if ( false === $ this -> data && $ freePass ) { $ this -> next -> call ( ) ; return ; } /* Check if user authenticates. */ $ authenticator = $ this -> options [ "authenticator" ] ; if ( false === $ authenticator ( $ this -> data ) ) { $ this -> error = $ authenticator -> getError ( ) ; $ this -> callError ( ) ; return ; } $ this -> app -> userData = $ authenticator -> getData ( ) ; if ( ! $ this -> customValidation ( ) ) { $ this -> callError ( ) ; return ; } /* If callback returns false return with 401 Unauthorized. */ if ( is_callable ( $ this -> options [ "callback" ] ) ) { $ params = $ this -> getParams ( ) ; if ( false === $ this -> options [ "callback" ] ( $ params ) ) { $ this -> error = new Error ( ) ; $ this -> error -> setDescription ( "Callback returned false" ) ; $ this -> callError ( ) ; return ; } } /* Everything ok, call next middleware. */ $ this -> next -> call ( ) ; }
Call the middleware
Call the middleware