about summary refs log tree commit diff
path: root/Tests/LibMatrix.HomeserverEmulator/Controllers/AuthController.cs
blob: d0496bf31a734096fed71b16591e72fdacf133c8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
using System.Text.Json.Nodes;
using LibMatrix.HomeserverEmulator.Services;
using LibMatrix.Responses;
using LibMatrix.Services;
using Microsoft.AspNetCore.Mvc;

namespace LibMatrix.HomeserverEmulator.Controllers;

[ApiController]
[Route("/_matrix/client/{version}/")]
public class AuthController(ILogger<AuthController> logger, UserStore userStore) : ControllerBase {
    [HttpPost("login")]
    public async Task<LoginResponse> Login(LoginRequest request) {
        var user = await userStore.CreateUser($"@{Guid.NewGuid().ToString()}:{Request.Host}", Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), new Dictionary<string, object>());
        var loginResponse = new LoginResponse {
            AccessToken = user.AccessToken,
            DeviceId = user.DeviceId,
            UserId = user.UserId
        };

        return loginResponse;
    }
}