src/Authenticator/JwtAuthenticator.php
public function authenticate(ServerRequestInterface $request, ResponseInterface $response)
    {
        try {
            $result = $this->getPayload($request);
        } catch (Exception $e) {
            return new Result(
                null,
                Result::FAILURE_CREDENTIALS_INVALID,
                [
                    'message' => $e->getMessage(),
                    'exception' => $e
                ]
            );
        }

        if (!($result instanceof stdClass)) {
            return new Result(null, Result::FAILURE_CREDENTIALS_INVALID);
        }

        $result = json_decode(json_encode($result), true);

        $key = IdentifierInterface::CREDENTIAL_JWT_SUBJECT;
        if (empty($result[$key])) {
            return new Result(null, Result::FAILURE_CREDENTIALS_MISSING);
        }

        if ($this->getConfig('returnPayload')) {
            $user = new ArrayObject($result);

            return new Result($user, Result::SUCCESS);
        }

        $user = $this->_identifier->identify([
            $key => $result[$key]
        ]);

        if (empty($user)) {
            return new Result(null, Result::FAILURE_IDENTITY_NOT_FOUND, $this->_identifier->getErrors());
        }

        return new Result($user, Result::SUCCESS);
    }
public function authenticate(ServerRequestInterface $request, ResponseInterface $response)
    {
        try {
            $result = $this->getPayload($request);
        } catch (Exception $e) {
            return new Result(
                null,
                Result::FAILURE_CREDENTIALS_INVALID,
                [
                    'message' => $e->getMessage(),
                    'exception' => $e
                ]
            );
        }

        if (!($result instanceof stdClass)) {
            return new Result(null, Result::FAILURE_CREDENTIALS_INVALID);
        }

        $result = json_decode(json_encode($result), true);

        $key = IdentifierInterface::CREDENTIAL_JWT_SUBJECT;
        if (empty($result[$key])) {
            return new Result(null, Result::FAILURE_CREDENTIALS_MISSING);
        }

        if ($this->getConfig('returnPayload')) {
            $user = new ArrayObject($result);

            return new Result($user, Result::SUCCESS);
        }

        $user = $this->_identifier->identify([
            $key => $result[$key]
        ]);

        if (empty($user)) {
            return new Result(null, Result::FAILURE_IDENTITY_NOT_FOUND, $this->_identifier->getErrors());
        }

        return new Result($user, Result::SUCCESS);
    }
public function authenticate ( ServerRequestInterface $ request , ResponseInterface $ response ) { try { $ result = $ this -> getPayload ( $ request ) ; } catch ( Exception $ e ) { return new Result ( null , Result :: FAILURE_CREDENTIALS_INVALID , [ 'message' => $ e -> getMessage ( ) , 'exception' => $ e ] ) ; } if ( ! ( $ result instanceof stdClass ) ) { return new Result ( null , Result :: FAILURE_CREDENTIALS_INVALID ) ; } $ result = json_decode ( json_encode ( $ result ) , true ) ; $ key = IdentifierInterface :: CREDENTIAL_JWT_SUBJECT ; if ( empty ( $ result [ $ key ] ) ) { return new Result ( null , Result :: FAILURE_CREDENTIALS_MISSING ) ; } if ( $ this -> getConfig ( 'returnPayload' ) ) { $ user = new ArrayObject ( $ result ) ; return new Result ( $ user , Result :: SUCCESS ) ; } $ user = $ this -> _identifier -> identify ( [ $ key => $ result [ $ key ] ] ) ; if ( empty ( $ user ) ) { return new Result ( null , Result :: FAILURE_IDENTITY_NOT_FOUND , $ this -> _identifier -> getErrors ( ) ) ; } return new Result ( $ user , Result :: SUCCESS ) ; }
Authenticates the identity based on a JWT token contained in a request.

@link https://jwt.io/
@param \Psr\Http\Message\ServerRequestInterface $request The request that contains login information.
@param \Psr\Http\Message\ResponseInterface $response Unused response object.
@return \Authentication\Authenticator\ResultInterface
Authenticates the identity based on a JWT token contained in a request .