Skip to content

Commit

Permalink
Enable using authentication for minion clients.
Browse files Browse the repository at this point in the history
Only wampcra is available for now.

fixes Vinelab#3
  • Loading branch information
Devon Bagley committed Apr 28, 2018
1 parent 21d3d4e commit f1ac79d
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
17 changes: 16 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
21 changes: 21 additions & 0 deletions src/Vinelab/Minion/Minion.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Closure;
use Thruway\Transport\PawlTransportProvider;
use Thruway\Authentication\ClientWampCraAuthenticator;
use React\EventLoop\LoopInterface;

/**
Expand Down Expand Up @@ -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'));
}

Expand All @@ -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.
*
Expand Down

0 comments on commit f1ac79d

Please sign in to comment.