Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable using authentication for minion clients. #22

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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