summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Readme.md1
-rw-r--r--src/Controllers/LoginController.php35
-rw-r--r--src/ErrorCode.php38
-rw-r--r--src/Support/ArrayTransformable.php11
-rw-r--r--src/Types/IdentifierType.php10
-rw-r--r--src/Types/LoginFlow.php27
-rw-r--r--src/Types/LoginType.php9
-rw-r--r--src/routes.php14
8 files changed, 144 insertions, 1 deletions
diff --git a/Readme.md b/Readme.md
new file mode 100644
index 0000000..fda8853
--- /dev/null
+++ b/Readme.md
@@ -0,0 +1 @@
+Matrix Specification: https://spec.matrix.org/v1.5/
diff --git a/src/Controllers/LoginController.php b/src/Controllers/LoginController.php
new file mode 100644
index 0000000..f5ca3be
--- /dev/null
+++ b/src/Controllers/LoginController.php
@@ -0,0 +1,35 @@
+<?php
+
+namespace App\Controllers;
+
+use App\Types\LoginFlow;
+use App\Types\LoginType;
+use Symfony\Component\HttpFoundation\Request;
+use Symfony\Component\HttpFoundation\Response;
+use Symfony\Component\HttpFoundation\JsonResponse;
+
+class LoginController
+{
+ public function supportedLoginTypes(): Response
+ {
+ return new JsonResponse([
+ "flows" => [
+ (new LoginFlow(LoginType::PASSWORD))->toArray(),
+ ],
+ ]);
+ }
+
+ public function login(): Response
+ {
+ $request = Request::createFromGlobals();
+
+ return new JsonResponse([
+ "access_token" => "abc123",
+ "device_id" => "ABC",
+ "expires_in_ms" => 60000,
+ "refresh_token" => "def456",
+ "user_id" => "@php:localhost",
+ #"well_known" => [],
+ ]);
+ }
+}
diff --git a/src/ErrorCode.php b/src/ErrorCode.php
index 7a99374..2149d37 100644
--- a/src/ErrorCode.php
+++ b/src/ErrorCode.php
@@ -6,6 +6,42 @@ enum ErrorCode: string
{
case FORBIDDEN = "M_FORBIDDEN";
case UNKNOWN_TOKEN = "M_UNKNOWN_TOKEN";
-
+ case MISSING_TOKEN = "M_MISSING_TOKEN";
+ case USER_LOCKED = "M_USER_LOCKED";
+ case USER_SUSPENDED = "M_USER_SUSPENDED";
+ case BAD_JSON = "M_BAD_JSON";
+ case NOT_JSON = "M_NOT_JSON";
+ case NOT_FOUND = "M_NOT_FOUND";
+ case LIMIT_EXCEEDED = "M_LIMIT_EXCEEDED";
+ case UNRECOGNIZED = "M_UNRECOGNIZED";
case UNKNOWN = "M_UNKNOWN";
+
+ case UNAUTHORIZED = "M_UNAUTHORIZED";
+ case USER_DEACTIVATED = "M_USER_DEACTIVATED";
+ case USER_IN_USE = "M_USER_IN_USE";
+ case INVALID_USERNAME = "M_INVALID_USERNAME";
+ case ROOM_IN_USE = "M_ROOM_IN_USE";
+ case INVALID_ROOM_STATE = "M_INVALID_ROOM_STATE";
+
+ case THREEPID_IN_USE = "M_THREEPID_IN_USE";
+ case THREEPID_NOT_FOUND = "M_THREEPID_NOT_FOUND";
+ case THREEPID_AUTH_FAILED = "M_THREEPID_AUTH_FAILED";
+ case THREEPID_DENIED = "M_THREEPID_DENIED";
+ case THREEPID_MEDIUM_NOT_SUPPORTED = "M_THREEPID_MEDIUM_NOT_SUPPORTED";
+
+ case SERVER_NOT_TRUSTED = "M_SERVER_NOT_TRUSTED";
+ case UNSUPPORTED_ROOM_VERSION = "M_UNSUPPORTED_ROOM_VERSION";
+ case INCOMPATIBLE_ROOM_VERSION = "M_INCOMPATIBLE_ROOM_VERSION";
+ case BAD_STATE = "M_BAD_STATE";
+ case GUEST_ACCESS_FORBIDDEN = "M_GUEST_ACCESS_FORBIDDEN";
+
+ case CAPTCHA_NEEDED = "M_CAPTCHA_NEEDED";
+ case CAPTCHA_INVALID = "M_CAPTCHA_INVALID";
+
+ case MISSING_PARAM = "M_MISSING_PARAM";
+ case INVALID_PARAM = "M_INVALID_PARAM";
+ case TOO_LARGE = "M_TOO_LARGE";
+ case EXCLUSIVE = "M_EXCLUSIVE";
+ case RESOURCE_LIMIT_EXCEEDED = "M_RESOURCE_LIMIT_EXCEEDED";
+ case CANNOT_LEAVE_SERVER_NOTICE_ROOM = "M_CANNOT_LEAVE_SERVER_NOTICE_ROOM";
}
diff --git a/src/Support/ArrayTransformable.php b/src/Support/ArrayTransformable.php
new file mode 100644
index 0000000..f1adf81
--- /dev/null
+++ b/src/Support/ArrayTransformable.php
@@ -0,0 +1,11 @@
+<?php
+
+namespace App\Support;
+
+interface ArrayTransformable
+{
+ /**
+ * @return array
+ */
+ public function toArray(): array;
+}
diff --git a/src/Types/IdentifierType.php b/src/Types/IdentifierType.php
new file mode 100644
index 0000000..93396fa
--- /dev/null
+++ b/src/Types/IdentifierType.php
@@ -0,0 +1,10 @@
+<?php
+
+namespace App\Types;
+
+enum IdentifierType: string
+{
+ case USER = "m.id.user";
+ case THIRDPARTY = "m.id.thirdparty";
+ case PHONE = "m.id.phone";
+}
diff --git a/src/Types/LoginFlow.php b/src/Types/LoginFlow.php
new file mode 100644
index 0000000..bd948a8
--- /dev/null
+++ b/src/Types/LoginFlow.php
@@ -0,0 +1,27 @@
+<?php
+
+namespace App\Types;
+
+use App\Support\ArrayTransformable;
+
+class LoginFlow implements ArrayTransformable
+{
+ public function __construct(
+ private LoginType $type,
+ private bool $get_login_token = false,
+ )
+ {}
+
+ public function toArray(): array
+ {
+ $flow = [
+ "type" => $this->type,
+ ];
+
+ if ($this->type == LoginType::TOKEN) {
+ $flow["get_login_token"] = $this->get_login_token;
+ }
+
+ return $flow;
+ }
+}
diff --git a/src/Types/LoginType.php b/src/Types/LoginType.php
new file mode 100644
index 0000000..a5e3d8b
--- /dev/null
+++ b/src/Types/LoginType.php
@@ -0,0 +1,9 @@
+<?php
+
+namespace App\Types;
+
+enum LoginType: string
+{
+ case PASSWORD = "m.login.password";
+ case TOKEN = "m.login.token";
+}
diff --git a/src/routes.php b/src/routes.php
index 21113dc..2d1c3e0 100644
--- a/src/routes.php
+++ b/src/routes.php
@@ -2,6 +2,7 @@
namespace App;
+use App\Controllers\LoginController;
use App\Controllers\ServerDiscoveryController;
use App\Controllers\ServerImplementationController;
use Symfony\Component\Routing\Loader\Configurator\RouteConfigurator;
@@ -37,5 +38,18 @@ return function (RouteConfigurator $routes): void
# /_matrix/key/v2/query
# /_matrix/key/v2/query/{serverName}
+ $supportedLoginTypes = [LoginController::class, "supportedLoginTypes"];
+ $routes
+ ->add("matrix_client_r0_login_types", "/_matrix/client/r0/login")
+ ->controller($supportedLoginTypes)
+ ->methods(["GET"]);
+ $routes
+ ->add("matrix_client_v3_login_types", "/_matrix/client/v3/login")
+ ->controller($supportedLoginTypes)
+ ->methods(["GET"]);
+ $routes
+ ->add("matrix_client_v3_login", "/_matrix/client/v3/login")
+ ->controller($supportedLoginTypes)
+ ->methods(["POST"]);
};