Skip to content
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
10 changes: 9 additions & 1 deletion src/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ public function __construct(Array $options, LoopInterface $loop = null, Connecto
if (isset($options['authid'])) {
$this->client->setAuthId($options['authid']);
}
//Set Authextra
if (isset($options['authextra'])) {
$this->client->setAuthextra($options['authextra']);
}

//Register Handlers
$this->handleOnChallenge();
Expand Down Expand Up @@ -167,8 +171,12 @@ private function handleOnChallenge()
$this->client->setAuthMethods($options['authmethods']);

$this->client->on('challenge', function (ClientSession $session, ChallengeMessage $msg) use ($options) {
$extra = null;
$token = call_user_func($options['onChallenge'], $session, $msg->getAuthMethod(), $msg);
$session->sendMessage(new AuthenticateMessage($token));
if (is_array($token) && count($token) >= 2) {
[$token, $extra] = $token;
}
$session->sendMessage(new AuthenticateMessage($token, $extra));
});
}
}
Expand Down
25 changes: 25 additions & 0 deletions src/Peer/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,11 @@ class Client implements EventEmitterInterface, ClientInterface
*/
private $attemptRetry = true;

/**
* @var \stdClass|null
*/
private $authextra;


/**
* Constructor
Expand All @@ -143,6 +148,7 @@ public function __construct($realm, LoopInterface $loop = null)
$this->session = null;
$this->clientAuthenticators = [];
$this->authId = 'anonymous';
$this->authextra = null;

$this->reconnectOptions = [
'max_retries' => 15,
Expand Down Expand Up @@ -271,6 +277,9 @@ public function startSession(ClientSession $session)

$details->authmethods = $this->authMethods;
$details->authid = $this->authId;
if ($this->authextra !== null) {
$details->authextra = $this->authextra;
}

$session->setRealm($this->realm);

Expand Down Expand Up @@ -608,6 +617,22 @@ public function setAuthMethods($authMethods)
$this->authMethods = $authMethods;
}

/**
* @return \stdClass|null
*/
public function getAuthextra()
{
return $this->authextra;
}

/**
* @param \stdClass|null $authextra
*/
public function setAuthextra($authextra)
{
$this->authextra = $authextra === null ? null : (object)$authextra;
}

/**
* Get client session
*
Expand Down