blob: 0dcc3bb432335efb1b160d4e029d4dc4a34c35b4 (
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
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
using System.Collections.Concurrent;
using Microsoft.AspNetCore.Mvc;
using MxApiExtensions.Classes.LibMatrix;
using MxApiExtensions.Services;
namespace MxApiExtensions.Controllers.Extensions;
[ApiController]
[Route("/_matrix/client/unstable/gay.rory.mxapiextensions")]
public class ProxyConfigurationController : ControllerBase {
private readonly ILogger _logger;
private readonly MxApiExtensionsConfiguration _config;
private readonly AuthenticationService _authenticationService;
private static ConcurrentDictionary<string, RoomInfoEntry> _roomInfoCache = new();
public ProxyConfigurationController(ILogger<ProxyConfigurationController> logger, MxApiExtensionsConfiguration config, AuthenticationService authenticationService,
AuthenticatedHomeserverProviderService authenticatedHomeserverProviderService) {
_logger = logger;
_config = config;
_authenticationService = authenticationService;
}
[HttpGet("proxy_config")]
public async Task<MxApiExtensionsConfiguration> GetConfig() {
var mxid = await _authenticationService.GetMxidFromToken();
if(!_config.Admins.Contains(mxid)) {
_logger.LogWarning("Got proxy config request for {user}, but they are not an admin", mxid);
Response.StatusCode = StatusCodes.Status403Forbidden;
Response.ContentType = "application/json";
await Response.WriteAsJsonAsync(new {
ErrorCode = "M_FORBIDDEN",
Error = "You are not an admin"
});
await Response.CompleteAsync();
return null;
}
_logger.LogInformation("Got proxy config request for {user}", mxid);
return _config;
}
}
|