Monday, 21 January 2019

How to get the caller ID on a RPC inside an internal client?

What I'm trying to do is to know who is calling a remote procedure, that I registered using an internal client so I can apply logic based on that info.

On the client side I'm using autobahn-js and going through the documentation I found that using the argument disclose_me should give me the info I need:

session.call('com.myapp.procedure1', ['Hello, world!'], {}, {disclose_me: true});

So now going to the server side of this, I have an internal client class:

class InternalClient extends Thruway\Peer\Client {

    public function __construct(&$db) {
        parent::__construct("realm");
        $this->setAuthId('Internal');
        $this->setAuthMethods(['myCustomMethod']);
    }

    /**
     * @param \Thruway\ClientSession $session
     * @param \Thruway\Transport\TransportInterface $transport
     */
    public function onSessionStart($session, $transport) {

        $session->setAuthenticated(true);
        $session->register('com.realm.rpc', function($args) {

            //logic goes here, I need to know who is the caller for this RPC

            return [array];
        });

    }    
}

So I instanciate my router, add the client to it and start the router on port 9090:

$router = new \Thruway\Peer\Router();    
$router->addInternalClient(new InternalClient());
$router->registerModule(new \Thruway\Transport\RatchetTransportProvider("0.0.0.0", 9090));
$router->start();

I've looked inside the Thruway\Peer\Client class which is extended by the client and inside what appears to be the message itself inside the function onMessage and strill trying to track down this information but I just can't put my finger on it...

All I get is my own session info which is useless... Thanks in advance.



from How to get the caller ID on a RPC inside an internal client?

No comments:

Post a Comment