diff --git a/README.md b/README.md index 2d51e7a..5b5ed56 100644 --- a/README.md +++ b/README.md @@ -33,10 +33,24 @@ Configure the connection parameters you want your client to use when it connects ### Router ```php -$m = new Minion(): +$m = new Minion(); $m->run(['realm' => 'myrealm', 'host' => 'some.host.ws', 'port' => 8182]); ``` +### Authentication +A basic wampcra authenticator for minion can be enabled by adding the configuration for authentication. + +```php +$m = new Minion(); +$m->run([ + 'realm' => 'secretrealm', + 'auth' => [ + 'authid' => 'minion', + 'secret' => 'ultrasecretkey' + ] +]); +``` + ### Provider Registration ```php @@ -67,6 +81,7 @@ $m->run( ); ``` +### Loop In existing applications it may be useful to be re-use an existing ReactPHP loop. You can pass in a LoopInterface like so: ```php diff --git a/src/Vinelab/Minion/Minion.php b/src/Vinelab/Minion/Minion.php index 28646f5..d09a654 100644 --- a/src/Vinelab/Minion/Minion.php +++ b/src/Vinelab/Minion/Minion.php @@ -4,6 +4,7 @@ use Closure; use Thruway\Transport\PawlTransportProvider; +use Thruway\Authentication\ClientWampCraAuthenticator; use React\EventLoop\LoopInterface; /** @@ -79,6 +80,13 @@ public function run($options = [], LoopInterface $loop = null) $client = $this->newClient($loop); $client->addTransportProvider($this->newTransportProvider()); + $auth = $this->getConfig('auth'); + if (!empty($auth)) { + $client->addClientAuthenticator( + $this->newAuthenticator($auth['authid'], $auth['secret']) + ); + } + return $client->start($this->getConfig('debug')); } @@ -104,6 +112,19 @@ public function newTransportProvider() return new PawlTransportProvider($this->transportUrl()); } + /** + * Get a new wampcra authenticator instance. + * + * @param string $authid + * @param string $secret + * + * @return \Thruway\Authentication\ClientWampCraAuthenticator + */ + public function newAthenticator($authid, $secret) + { + return new ClientWampCraAuthenticator($authid, $secret); + } + /** * Get the transport URL that provider should connect to. *