public function deserialize($serializedData) { if (null === ($data = @json_decode($serializedData, true))) { throw new DeserializationException("Error decoding json \"" . $serializedData . "\""); } $msg = Message::createMessageFromArray($data); return $msg; }
public function testPublishBlackWhiteListing() { $publishMessageRawJSON = "[16,12345,{},\"example.topic\"]"; /** @var \Thruway\Message\PublishMessage $publishMessage */ $publishMessage = \Thruway\Message\Message::createMessageFromArray(json_decode($publishMessageRawJSON)); $this->assertInstanceOf('\\Thruway\\Message\\PublishMessage', $publishMessage); $this->assertEquals((object) [], $publishMessage->getOptions()); $this->assertEquals("example.topic", $publishMessage->getTopicName()); }
public function processHello(array $args) { /** @var \Thruway\Message\HelloMessage $helloMessage */ $helloMessage = \Thruway\Message\Message::createMessageFromArray($args[0]); if ($helloMessage->getDetails()->authid == 'authenticate_me') { return ["CHALLENGE", ["challenge_method" => 'extra_auth', "challenge" => '']]; } return ['NOCHALLENGE', (object) ['authid' => 'theauth', '_thruway_authextra' => ['from' => 'hello', 'one' => 1, 'two' => [1, 2]]]]; }
/** * Process HelloMessage * * @param array $args * @return array<string|array> */ public function processHello(array $args) { if (!isset($args[0])) { return ["FAILURE"]; } $helloMessage = \Thruway\Message\Message::createMessageFromArray($args[0]); if ($helloMessage instanceof HelloMessage && isset($helloMessage->getDetails()->transport->query_params->token) && $helloMessage->getDetails()->transport->query_params->token === 'sadfsaf') { return ["NOCHALLENGE", ["authid" => "joe"]]; } return ["FAILURE"]; }
/** * The arguments given by the server are the actual hello message ($args[0]) * and some session information ($args[1]) * * The session information is an associative array that contains the sessionId and realm * * @param array $args * @return array */ 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) || !$this->getUserDb() instanceof WampCraUserDbInterface) { return ["ERROR"]; } $authid = $helloMsg->getDetails()->authid; $user = $this->getUserDb()->get($authid); if (!$user) { return ["FAILURE"]; } // create a challenge $nonce = bin2hex(openssl_random_pseudo_bytes(22)); $authRole = "user"; $authMethod = "wampcra"; $authProvider = "userdb"; $now = new \DateTime(); $timeStamp = $now->format($now::ISO8601); if (!isset($sessionInfo->sessionId)) { return ["ERROR"]; } $sessionId = $sessionInfo->sessionId; $challenge = ["authid" => $authid, "authrole" => $authRole, "authprovider" => $authProvider, "authmethod" => $authMethod, "nonce" => $nonce, "timestamp" => $timeStamp, "session" => $sessionId]; $serializedChallenge = json_encode($challenge); $challengeDetails = ["challenge" => $serializedChallenge, "challenge_method" => $this->getMethodName()]; if ($user['salt'] !== null) { // we are using salty password $saltInfo = ["salt" => $user['salt'], "keylen" => 32, "iterations" => 1000]; $challengeDetails = array_merge($challengeDetails, $saltInfo); } return ["CHALLENGE", (object) $challengeDetails]; }
public function handleRouterStart(RouterStartEvent $event) { /** @var Session $session */ $session = null; // create a new transport for the client side to use $clientTransport = new InternalClientTransport(function ($msg) use(&$session) { $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, Message::createMessageFromArray(json_decode(json_encode($msg)))); }, $this->loop); $transport->setTrusted($this->trusted); $session = $this->router->createNewSession($transport); $this->session = $session; // connect the transport to the Router/Peer $this->router->getEventDispatcher()->dispatch("connection_open", new ConnectionOpenEvent($session)); // open the client side $this->internalClient->onOpen($clientTransport); // internal client shouldn't retry $this->internalClient->setAttemptRetry(false); // tell the internal client to start up $this->internalClient->start(false); }
/** * @expectedException InvalidArgumentException * @throws \Thruway\Message\MessageException */ public function testObjectAsRealmName() { $msg = \Thruway\Message\Message::createMessageFromArray([\Thruway\Message\Message::MSG_HELLO, new stdClass(), new stdClass()]); }