Add JWT login method
This commit is contained in:
parent
9de988b660
commit
a002615d40
|
@ -185,6 +185,42 @@ class MatrixClient {
|
||||||
'device_id' => $deviceId
|
'device_id' => $deviceId
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
return $this->finalizeLogin($response, $sync, $limit);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Log in with a JWT.
|
||||||
|
*
|
||||||
|
* @param string $token JWT token.
|
||||||
|
* @param bool $sync Indicator whether to sync.
|
||||||
|
* @param int $limit Sync limit.
|
||||||
|
*
|
||||||
|
* @return string Access token.
|
||||||
|
*
|
||||||
|
* @throws \Aryess\PhpMatrixSdk\Exceptions\MatrixException
|
||||||
|
*/
|
||||||
|
public function jwtLogin(string $token, bool $sync = true, int $limit = 10): ?string {
|
||||||
|
$response = $this->api->login(
|
||||||
|
'org.matrix.login.jwt',
|
||||||
|
['token' => $token]
|
||||||
|
);
|
||||||
|
|
||||||
|
return $this->finalizeLogin($response, $sync, $limit);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Finalize login, e.g. after password or JWT login.
|
||||||
|
*
|
||||||
|
* @param array $response Login response array.
|
||||||
|
* @param bool $sync Sync flag.
|
||||||
|
* @param int $limit Sync limit.
|
||||||
|
*
|
||||||
|
* @return string Access token.
|
||||||
|
*
|
||||||
|
* @throws \Aryess\PhpMatrixSdk\Exceptions\MatrixException
|
||||||
|
* @throws \Aryess\PhpMatrixSdk\Exceptions\MatrixRequestException
|
||||||
|
*/
|
||||||
|
protected function finalizeLogin(array $response, bool $sync, int $limit): string {
|
||||||
$this->userId = array_get($response, 'user_id');
|
$this->userId = array_get($response, 'user_id');
|
||||||
$this->token = array_get($response, 'access_token');
|
$this->token = array_get($response, 'access_token');
|
||||||
$this->hs = array_get($response, 'home_server');
|
$this->hs = array_get($response, 'home_server');
|
||||||
|
@ -540,4 +576,4 @@ class MatrixClient {
|
||||||
return $this->cacheLevel;
|
return $this->cacheLevel;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,8 @@ use GuzzleHttp\Exception\GuzzleException;
|
||||||
* $response = $matrix.sync();
|
* $response = $matrix.sync();
|
||||||
* $response = $matrix->sendMessage("!roomid:matrix.org", "Hello!");
|
* $response = $matrix->sendMessage("!roomid:matrix.org", "Hello!");
|
||||||
*
|
*
|
||||||
|
* @see https://matrix.org/docs/spec/client_server/latest
|
||||||
|
*
|
||||||
* @package Aryess\PhpMatrixSdk
|
* @package Aryess\PhpMatrixSdk
|
||||||
*/
|
*/
|
||||||
class MatrixHttpApi {
|
class MatrixHttpApi {
|
||||||
|
|
Loading…
Reference in New Issue