Skip to content

Commit

Permalink
Serialize and deserialize messages for InternalClients plus some fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mbonneau committed Apr 22, 2015
1 parent 40d2691 commit 2c68b3a
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/Thruway/Authentication/AuthenticationManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ private function onAuthenticateHandler($authMethod, $authMethodInfo, Realm $real
$res[1]->authrole = $session->getAuthenticationDetails()->getAuthRole();
$res[1]->authroles = $session->getAuthenticationDetails()->getAuthRoles();
$res[1]->authid = $session->getAuthenticationDetails()->getAuthId();
if (is_array($res[1])) {
if (is_object($res[1])) {
foreach ($res[1] as $k => $v) {
$welcomeDetails->$k = $v;
}
Expand Down
16 changes: 15 additions & 1 deletion src/Thruway/Authentication/WampCraAuthProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@


use Thruway\Message\HelloMessage;
use Thruway\Message\Message;

/**
* Class WampCraAuthProvider
Expand Down Expand Up @@ -40,6 +41,16 @@ public function processHello(array $args)
$helloMsg = array_shift($args);
$sessionInfo = array_shift($args);

if (!is_array($helloMsg)) {
return ["ERROR"];
}

if (!is_object($sessionInfo)) {
return ["ERROR"];
}

$helloMsg = Message::createMessageFromArray($helloMsg);

if (!$helloMsg instanceof HelloMessage
|| !$sessionInfo
|| !isset($helloMsg->getDetails()->authid)
Expand All @@ -62,7 +73,10 @@ public function processHello(array $args)
$authProvider = "userdb";
$now = new \DateTime();
$timeStamp = $now->format($now::ISO8601);
$sessionId = $sessionInfo['sessionId'];
if (!isset($sessionInfo->sessionId)) {
return ["ERROR"];
}
$sessionId = $sessionInfo->sessionId;

$challenge = [
"authid" => $authid,
Expand Down
6 changes: 4 additions & 2 deletions src/Thruway/Transport/InternalClientTransportProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Thruway\Event\ConnectionOpenEvent;
use Thruway\Event\RouterStartEvent;
use Thruway\Event\RouterStopEvent;
use Thruway\Message\Message;
use Thruway\Peer\ClientInterface;
use Thruway\Session;

Expand Down Expand Up @@ -45,13 +46,14 @@ public function handleRouterStart(RouterStartEvent $event) {

// create a new transport for the client side to use
$clientTransport = new InternalClientTransport(function ($msg) use (&$session) {
$session->dispatchMessage($msg);
$session->dispatchMessage(Message::createMessageFromArray(json_decode(json_encode($msg))));
}, $this->loop);


// create a new transport for the router side to use
$transport = new InternalClientTransport(function ($msg) use ($clientTransport) {
$this->internalClient->onMessage($clientTransport, $msg);
$this->internalClient->onMessage($clientTransport,
Message::createMessageFromArray(json_decode(json_encode($msg))));
}, $this->loop);
$transport->setTrusted($this->trusted);

Expand Down
2 changes: 1 addition & 1 deletion tests/WAMP/WampCraTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ public function testLogin()
$conn = new \Thruway\Connection($this->getOptions());

$conn->on('open', function (ClientSession $session, $transport, $details) {
$session->close();
$this->_result = "logged in";
$this->_authid = $details->authid;
$session->close();
});

$conn->on('error', function ($reason) {
Expand Down

0 comments on commit 2c68b3a

Please sign in to comment.