mirror of
https://github.com/PluralKit/PluralKit.git
synced 2026-02-04 04:56:49 +00:00
chore(api): move token auth to rust api service
This commit is contained in:
parent
8210cb23f6
commit
cfde105e19
8 changed files with 83 additions and 27 deletions
|
|
@ -5,4 +5,5 @@ public class ApiConfig
|
|||
public int Port { get; set; } = 5000;
|
||||
public string? ClientId { get; set; }
|
||||
public string? ClientSecret { get; set; }
|
||||
public bool TrustAuth { get; set; } = false;
|
||||
}
|
||||
|
|
@ -13,19 +13,13 @@ public class AuthorizationTokenHandlerMiddleware
|
|||
_next = next;
|
||||
}
|
||||
|
||||
public async Task Invoke(HttpContext ctx, IDatabase db)
|
||||
public async Task Invoke(HttpContext ctx, IDatabase db, ApiConfig cfg)
|
||||
{
|
||||
ctx.Request.Headers.TryGetValue("authorization", out var authHeaders);
|
||||
if (authHeaders.Count > 0)
|
||||
{
|
||||
var systemId = await db.Execute(conn => conn.QuerySingleOrDefaultAsync<SystemId?>(
|
||||
"select id from systems where token = @token",
|
||||
new { token = authHeaders[0] }
|
||||
));
|
||||
|
||||
if (systemId != null)
|
||||
ctx.Items.Add("SystemId", systemId);
|
||||
}
|
||||
if (cfg.TrustAuth
|
||||
&& ctx.Request.Headers.TryGetValue("X-PluralKit-SystemId", out var sidHeaders)
|
||||
&& sidHeaders.Count > 0
|
||||
&& int.TryParse(sidHeaders[0], out var systemId))
|
||||
ctx.Items.Add("SystemId", new SystemId(systemId));
|
||||
|
||||
await _next.Invoke(ctx);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue