2026-03-28 00:52:17 -04:00
|
|
|
#pragma once
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
#include <vector>
|
|
|
|
|
#include <utility>
|
|
|
|
|
|
2026-04-03 21:39:59 -04:00
|
|
|
inline string narrowStr(const wstring &w)
|
|
|
|
|
{
|
|
|
|
|
return string(w.begin(), w.end());
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-28 00:52:17 -04:00
|
|
|
class AuthModule
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
virtual ~AuthModule() = default;
|
|
|
|
|
|
|
|
|
|
virtual const wchar_t *schemeName() = 0;
|
|
|
|
|
virtual vector<wstring> supportedVariations() = 0;
|
|
|
|
|
virtual vector<pair<wstring, wstring>> getSettings(const wstring &variation) = 0;
|
|
|
|
|
virtual bool onAuthData(const vector<pair<wstring, wstring>> &fields, wstring &outUid, wstring &outUsername) = 0;
|
|
|
|
|
|
|
|
|
|
bool validate(const wstring &uid, const wstring &username);
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
bool extractIdentity(const vector<pair<wstring, wstring>> &fields, wstring &outUid, wstring &outUsername);
|
|
|
|
|
};
|
2026-04-06 02:33:39 -04:00
|
|
|
|
|
|
|
|
class KeypairOfflineAuthModule : public AuthModule
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
const wchar_t *schemeName() override { return L"mcconsoles:keypair_offline"; }
|
|
|
|
|
vector<wstring> supportedVariations() override { return {L"rsa2048", L"ed25519"}; }
|
|
|
|
|
vector<pair<wstring, wstring>> getSettings(const wstring &variation) override { return {{L"key_type", variation}}; }
|
|
|
|
|
bool onAuthData(const vector<pair<wstring, wstring>> &fields, wstring &outUid, wstring &outUsername) override { return extractIdentity(fields, outUid, outUsername); }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class OfflineAuthModule : public AuthModule
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
const wchar_t *schemeName() override { return L"mcconsoles:offline"; }
|
|
|
|
|
vector<wstring> supportedVariations() override { return {}; }
|
|
|
|
|
vector<pair<wstring, wstring>> getSettings(const wstring &) override { return {}; }
|
|
|
|
|
bool onAuthData(const vector<pair<wstring, wstring>> &fields, wstring &outUid, wstring &outUsername) override { return extractIdentity(fields, outUid, outUsername); }
|
|
|
|
|
};
|