mirror of
https://github.com/CyberL1/Minecraft-Realms-Emulator.git
synced 2026-09-15 19:25:48 -04:00
feat(Core): add Authorization middlware
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
namespace Core.Middlewares;
|
||||
|
||||
public class AuthorizationMiddleware(RequestDelegate next)
|
||||
{
|
||||
public Task Invoke(HttpContext httpContext)
|
||||
{
|
||||
var cookieHeader = httpContext.Request.Headers.Cookie.ToString();
|
||||
|
||||
if (cookieHeader.Trim() == "")
|
||||
{
|
||||
httpContext.Response.StatusCode = 401;
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
var hasSid = httpContext.Request.Cookies.ContainsKey("sid");
|
||||
var hasUser = httpContext.Request.Cookies.ContainsKey("user");
|
||||
var hasVersion = httpContext.Request.Cookies.ContainsKey("version");
|
||||
|
||||
if (!(hasSid && hasUser && hasVersion))
|
||||
{
|
||||
httpContext.Response.StatusCode = 401;
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
return next(httpContext);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user