diff --git a/src/MatrixClient.php b/src/MatrixClient.php index f8e0ac3..6639b91 100644 --- a/src/MatrixClient.php +++ b/src/MatrixClient.php @@ -185,6 +185,42 @@ class MatrixClient { '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->token = array_get($response, 'access_token'); $this->hs = array_get($response, 'home_server'); @@ -540,4 +576,4 @@ class MatrixClient { return $this->cacheLevel; } -} \ No newline at end of file +} diff --git a/src/MatrixHttpApi.php b/src/MatrixHttpApi.php index d5af85e..d86df7b 100644 --- a/src/MatrixHttpApi.php +++ b/src/MatrixHttpApi.php @@ -20,6 +20,8 @@ use GuzzleHttp\Exception\GuzzleException; * $response = $matrix.sync(); * $response = $matrix->sendMessage("!roomid:matrix.org", "Hello!"); * + * @see https://matrix.org/docs/spec/client_server/latest + * * @package Aryess\PhpMatrixSdk */ class MatrixHttpApi {