private function onHelloAuthHandler($authMethod, $authMethodInfo, Realm $realm, Session $session, HelloMessage $msg)
    {

        $authDetails = new AuthenticationDetails();
        $authDetails->setAuthMethod($authMethod);

        $helloDetails = $msg->getDetails();
        if (isset($helloDetails->authid)) {
            $authDetails->setAuthId($helloDetails->authid);
        }

        $session->setAuthenticationDetails($authDetails);

        $sessionInfo = ['sessionId' => $session->getSessionId(), 'realm' => $realm->getRealmName()];

        $onHelloSuccess = function ($res) use ($realm, $session, $msg) {
            // this is handling the return of the onhello RPC call

            if (isset($res[0]) && $res[0] === 'FAILURE') {
                $this->abortSessionUsingResponse($session, $res);

                return;
            }

            if (count($res) < 2) {
                $session->abort(new \stdClass(), 'thruway.auth.invalid_response_to_hello');

                return;
            }

            switch ($res[0]) {
                case 'CHALLENGE':
                    // TODO: validate challenge message
                    $authMethod = $res[1]->challenge_method;
                    $challenge  = $res[1]->challenge;

                    $session->getAuthenticationDetails()->setChallenge($challenge);
                    $session->getAuthenticationDetails()->setChallengeDetails($res[1]);

                    $challengeDetails = $session->getAuthenticationDetails()->getChallengeDetails();
                    $session->sendMessage(new ChallengeMessage($authMethod, $challengeDetails));
                    break;

                case 'NOCHALLENGE':
                    $details             = $res[1];
                    $details->authmethod = $session->getAuthenticationDetails()->getAuthMethod();

                    $this->sendWelcomeMessage($session, $details);
                    break;

                default:
                    $session->abort(new \stdClass(), "thruway.error.authentication_failure");
            }

        };

        $onHelloError = function () use ($session) {
            Logger::error($this, 'onhello rejected the promise');
            $session->abort(new \stdClass(), 'thruway.error.unknown');
        };

        $onHelloAuthHandler = $authMethodInfo['handlers']->onhello;

        //Make the OnHello Call
        $this->session->call($onHelloAuthHandler, [$msg, $sessionInfo])
            ->then($onHelloSuccess, $onHelloError);

    }