public function handle($request, Closure $next, ...$guards)
    {
        // If don't has any guard follow the flow
        if (empty($guards)) {
            $this->authenticate($request, $guards);

            // Stop laravel from checking for a token if session is not set
            return $next($request);
        }

        $psrRequest = ServerRequest::createRequest($request);

        try {
            $psrRequest = $this->server->validateAuthenticatedRequest($psrRequest);

            if (! ($accessToken = $this->getAccessTokenFromRequest($psrRequest))) {
                throw new AuthenticationException('Unauthenticated', $guards);
            }

            $guard = $this->getTokenGuard($accessToken, $guards);

            $this->authenticate($request, $guard);
        } catch (OAuthServerException $e) {
            // If has an OAuthServerException check if has unit tests and fake
            // user authenticated.
            if (($user = PassportMultiauth::userActing()) &&
                $this->canBeAuthenticated($user, $guards)
            ) {
                return $next($request);
            }

            // @todo Check if it's the best way to handle with OAuthServerException
            throw new AuthenticationException('Unauthenticated', $guards);
        }

        return $next($request);
    }
public function handle($request, Closure $next, ...$guards)
    {
        // If don't has any guard follow the flow
        if (empty($guards)) {
            $this->authenticate($request, $guards);

            // Stop laravel from checking for a token if session is not set
            return $next($request);
        }

        $psrRequest = ServerRequest::createRequest($request);

        try {
            $psrRequest = $this->server->validateAuthenticatedRequest($psrRequest);

            if (! ($accessToken = $this->getAccessTokenFromRequest($psrRequest))) {
                throw new AuthenticationException('Unauthenticated', $guards);
            }

            $guard = $this->getTokenGuard($accessToken, $guards);

            $this->authenticate($request, $guard);
        } catch (OAuthServerException $e) {
            // If has an OAuthServerException check if has unit tests and fake
            // user authenticated.
            if (($user = PassportMultiauth::userActing()) &&
                $this->canBeAuthenticated($user, $guards)
            ) {
                return $next($request);
            }

            // @todo Check if it's the best way to handle with OAuthServerException
            throw new AuthenticationException('Unauthenticated', $guards);
        }

        return $next($request);
    }
public function handle ( $ request , Closure $ next , ... $ guards ) { // If don't has any guard follow the flow if ( empty ( $ guards ) ) { $ this -> authenticate ( $ request , $ guards ) ; // Stop laravel from checking for a token if session is not set return $ next ( $ request ) ; } $ psrRequest = ServerRequest :: createRequest ( $ request ) ; try { $ psrRequest = $ this -> server -> validateAuthenticatedRequest ( $ psrRequest ) ; if ( ! ( $ accessToken = $ this -> getAccessTokenFromRequest ( $ psrRequest ) ) ) { throw new AuthenticationException ( 'Unauthenticated' , $ guards ) ; } $ guard = $ this -> getTokenGuard ( $ accessToken , $ guards ) ; $ this -> authenticate ( $ request , $ guard ) ; } catch ( OAuthServerException $ e ) { // If has an OAuthServerException check if has unit tests and fake // user authenticated. if ( ( $ user = PassportMultiauth :: userActing ( ) ) && $ this -> canBeAuthenticated ( $ user , $ guards ) ) { return $ next ( $ request ) ; } // @todo Check if it's the best way to handle with OAuthServerException throw new AuthenticationException ( 'Unauthenticated' , $ guards ) ; } return $ next ( $ request ) ; }
Handle an incoming request. Authenticates the guard from access token
used on request.

@param \Illuminate\Http\Request $request
@param \Closure $next
@param string[] ...$guards
@return mixed

@throws \Illuminate\Auth\AuthenticationException
@throws \SMartins\PassportMultiauth\Exceptions\MissingConfigException
Handle an incoming request . Authenticates the guard from access token used on request .