mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2026-02-01 08:29:53 +00:00
WIP: basic server, no features
This commit is contained in:
43
dWeb/AuthMiddleware.h
Normal file
43
dWeb/AuthMiddleware.h
Normal file
@@ -0,0 +1,43 @@
|
||||
#pragma once
|
||||
|
||||
#include "IHTTPMiddleware.h"
|
||||
#include <vector>
|
||||
|
||||
/**
|
||||
* Authentication Middleware
|
||||
*
|
||||
* Verifies JWT tokens from:
|
||||
* - Query parameter: ?token=...
|
||||
* - Cookie: dashboardToken=...
|
||||
* - Authorization header: Bearer <token> or Token <token>
|
||||
*
|
||||
* Populates HTTPContext with authentication information if valid.
|
||||
* Does NOT fail on missing auth - that's left to specific routes.
|
||||
*/
|
||||
class AuthMiddleware : public IHTTPMiddleware {
|
||||
public:
|
||||
AuthMiddleware() = default;
|
||||
|
||||
bool Process(HTTPContext& context, HTTPReply& reply) override;
|
||||
|
||||
std::string GetName() const override { return "AuthMiddleware"; }
|
||||
|
||||
private:
|
||||
/**
|
||||
* Extract token from query string
|
||||
* Expected format: "?token=eyJhbGc..." or "&token=eyJhbGc..."
|
||||
*/
|
||||
static std::string ExtractTokenFromQueryString(const std::string& queryString);
|
||||
|
||||
/**
|
||||
* Extract token from Cookie header
|
||||
* Looks for "dashboardToken=..." cookie
|
||||
*/
|
||||
static std::string ExtractTokenFromCookies(const std::string& cookieHeader);
|
||||
|
||||
/**
|
||||
* Extract token from Authorization header
|
||||
* Supports: "Bearer <token>", "Token <token>", or raw token
|
||||
*/
|
||||
static std::string ExtractTokenFromAuthHeader(const std::string& authHeader);
|
||||
};
|
||||
Reference in New Issue
Block a user