Thruway\Session::setAuthenticated PHP Method

setAuthenticated() public method

Set authenticated state
public setAuthenticated ( boolean $authenticated )
$authenticated boolean
    public function setAuthenticated($authenticated)
    {
        // make sure the metaevent is only sent when changing from
        // not-authenticate to authenticated
        if ($authenticated && !$this->authenticated) {
            // metaevent
            $metaInfo = $this->getMetaInfo();
            $this->getRealm()->publishMeta('wamp.metaevent.session.on_join', [$metaInfo]);
            Logger::info($this, "Session joined: " . json_encode($metaInfo));
        }
        parent::setAuthenticated($authenticated);
    }

Usage Example

 /**
  * Call the handler that was registered to handle the Authenticate Message
  *
  * @param $authMethod
  * @param $authMethodInfo
  * @param Realm $realm
  * @param Session $session
  * @param AuthenticateMessage $msg
  */
 private function onAuthenticateHandler($authMethod, $authMethodInfo, Realm $realm, Session $session, AuthenticateMessage $msg)
 {
     $onAuthenticateSuccess = function ($res) use($realm, $session) {
         if (count($res) < 1) {
             $session->abort(new \stdClass(), "thruway.error.authentication_failure");
             return;
         }
         // we should figure out a way to have the router send the welcome
         // message so that the roles and extras that go along with it can be
         // filled in
         if ($res[0] == "SUCCESS") {
             $welcomeDetails = new \stdClass();
             if (isset($res[1]->authid)) {
                 $session->getAuthenticationDetails()->setAuthId($res[1]->authid);
             } else {
                 $session->getAuthenticationDetails()->setAuthId('authenticated_user');
             }
             $authRole = 'authenticated_user';
             $session->getAuthenticationDetails()->addAuthRole($authRole);
             if (isset($res[1]->authroles)) {
                 $session->getAuthenticationDetails()->addAuthRole($res[1]->authroles);
             }
             if (isset($res[1]->authrole)) {
                 $session->getAuthenticationDetails()->addAuthRole($res[1]->authrole);
             }
             if (isset($res[1]->_thruway_authextra)) {
                 $session->getAuthenticationDetails()->setAuthExtra($res[1]->_thruway_authextra);
             }
             if (isset($res[1]) && is_object($res[1])) {
                 $res[1]->authrole = $session->getAuthenticationDetails()->getAuthRole();
                 $res[1]->authroles = $session->getAuthenticationDetails()->getAuthRoles();
                 $res[1]->authid = $session->getAuthenticationDetails()->getAuthId();
                 foreach ($res[1] as $k => $v) {
                     $welcomeDetails->{$k} = $v;
                 }
             }
             $session->setAuthenticated(true);
             $session->sendMessage(new WelcomeMessage($session->getSessionId(), $welcomeDetails));
         } else {
             $session->abort(new \stdClass(), "thruway.error.authentication_failure");
         }
     };
     $onAuthenticateError = function () use($session) {
         Logger::error($this, "onauthenticate rejected the promise");
         $session->abort("thruway.error.unknown");
     };
     $extra = new \stdClass();
     $extra->challenge_details = $session->getAuthenticationDetails()->getChallengeDetails();
     $arguments = new \stdClass();
     $arguments->extra = $extra;
     $arguments->authid = $session->getAuthenticationDetails()->getAuthId();
     $arguments->challenge = $session->getAuthenticationDetails()->getChallenge();
     $arguments->signature = $msg->getSignature();
     $arguments->authmethod = $authMethod;
     $arguments->hello_message = $session->getHelloMessage();
     // now we send our authenticate information to the RPC
     $onAuthenticateHandler = $authMethodInfo['handlers']->onauthenticate;
     $this->session->call($onAuthenticateHandler, [$arguments])->then($onAuthenticateSuccess, $onAuthenticateError);
 }
All Usage Examples Of Thruway\Session::setAuthenticated