summaryrefslogtreecommitdiff
path: root/src/Controllers/AccountController.php
diff options
context:
space:
mode:
Diffstat (limited to 'src/Controllers/AccountController.php')
-rwxr-xr-xsrc/Controllers/AccountController.php35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/Controllers/AccountController.php b/src/Controllers/AccountController.php
new file mode 100755
index 0000000..858a6b5
--- /dev/null
+++ b/src/Controllers/AccountController.php
@@ -0,0 +1,35 @@
+<?php
+
+namespace App\Controllers;
+
+use App\Errors\UnauthorizedError;
+use App\Models\Device;
+use App\Models\User;
+use Symfony\Component\HttpFoundation\Request;
+use Symfony\Component\HttpFoundation\Response;
+use Symfony\Component\HttpFoundation\JsonResponse;
+
+class AccountController
+{
+ /**
+ * GET /_matrix/client/v3/account/whoami
+ *
+ * @see https://spec.matrix.org/v1.15/client-server-api/#get_matrixclientv3accountwhoami
+ */
+ public function whoami(Request $request): Response
+ {
+ $accessToken = str_replace("Bearer ", "", $request->headers->get("authorization") ?: "");
+ $user = User::fetchWithAccessToken($accessToken);
+
+ if (empty($user)) {
+ throw new UnauthorizedError();
+ }
+
+ $device = Device::fetch(userId: $user->getId());
+
+ return new JsonResponse([
+ "device_id" => $device->getId(),
+ "user_id" => $user->getId(),
+ ]);
+ }
+}