diff options
| author | Daniel Weipert <git@mail.dweipert.de> | 2025-08-14 14:37:56 +0200 | 
|---|---|---|
| committer | Daniel Weipert <git@mail.dweipert.de> | 2025-08-14 14:37:56 +0200 | 
| commit | c135fcf9041c604b32827a1cb027010bca5915ab (patch) | |
| tree | 95a2331d5f0bc4a736aa0e716330c39b3fa1ea26 /src/Controllers | |
| parent | 3f4b51b99a4f4dc41dbdce7f34afe7e15d3d426e (diff) | |
POST login possible
Diffstat (limited to 'src/Controllers')
| -rw-r--r-- | src/Controllers/LoginController.php | 25 | 
1 files changed, 24 insertions, 1 deletions
diff --git a/src/Controllers/LoginController.php b/src/Controllers/LoginController.php index f5ca3be..d48628b 100644 --- a/src/Controllers/LoginController.php +++ b/src/Controllers/LoginController.php @@ -2,6 +2,8 @@  namespace App\Controllers; +use App\Errors\UnknownError; +use App\Support\Parser;  use App\Types\LoginFlow;  use App\Types\LoginType;  use Symfony\Component\HttpFoundation\Request; @@ -10,6 +12,10 @@ use Symfony\Component\HttpFoundation\JsonResponse;  class LoginController  { +  /** +   * GET /_matrix/client/r0/login +   * GET /_matrix/client/v3/login +   */    public function supportedLoginTypes(): Response    {      return new JsonResponse([ @@ -19,16 +25,33 @@ class LoginController      ]);    } +  /** +   * POST /_matrix/client/v3/login +   */    public function login(): Response    {      $request = Request::createFromGlobals(); +    $content = json_decode($request->getContent(), true); + +    // validate login type +    $loginType = null; +    try { +      $loginType = LoginType::from($content["type"]); +    } catch (\ValueError $error) { +      throw new UnknownError("Bad login type.", Response::HTTP_BAD_REQUEST); +    } + +    // get user name +    $user = Parser::parseUser($content["identifier"]["user"]); + +    #if ($loginType == LoginType::PASSWORD) {}      return new JsonResponse([        "access_token" => "abc123",        "device_id" => "ABC",        "expires_in_ms" => 60000,        "refresh_token" => "def456", -      "user_id" => "@php:localhost", +      "user_id" => "@{$user["username"]}:{$_ENV["DOMAIN"]}",        #"well_known" => [],      ]);    }  | 
