public function authenticate(TokenInterface $token = null)
    {
        // If no token is passed in, try and find one from the authenticator
        $token = $token ?: $this->authenticator->present();

        if ( ! $token instanceof TokenInterface) {
            return new Result(Result::FAILURE_NO_TOKEN);
        }

        $result = new Result();

        try {
            $token = $this->authenticator->authenticate($token);
        } catch (AuthenticationException $e) {
            $result->setCode($e->getCode());
            $result->setException($e);
            $result->setToken($e->getToken());

            return $result;
        }

        $result->setCode(Result::SUCCESS);
        $result->setToken($token);

        if ( ! $token instanceof StatelessTokenInterface) {
            $this->storage->write($token);
        }

        $this->setToken($token);

        return $result;
    }