MinecraftConsoles/Minecraft.Client/AuthScreen.h

78 lines
2 KiB
C
Raw Normal View History

#pragma once
using namespace std;
2026-04-03 21:39:59 -04:00
#include <atomic>
#include <thread>
struct AuthProfile
{
2026-04-06 02:33:39 -04:00
enum Type : uint8_t { MICROSOFT, YGGDRASIL, OFFLINE };
Type type;
wstring uid;
wstring username;
wstring token;
wstring clientToken;
2026-04-06 02:33:39 -04:00
wstring variation;
};
class AuthProfileManager
{
private:
static vector<AuthProfile> profiles;
static int selectedProfile;
public:
static void load();
static void save();
2026-04-06 02:33:39 -04:00
static void addProfile(AuthProfile::Type type, const wstring &username, const wstring &uid = L"", const wstring &token = L"", const wstring &clientToken = L"", const wstring &variation = L"");
static void removeSelectedProfile();
static bool applySelectedProfile();
static const vector<AuthProfile> &getProfiles() { return profiles; }
static int getSelectedIndex() { return selectedProfile; }
static void setSelectedIndex(int idx) { selectedProfile = idx; }
};
2026-04-03 21:39:59 -04:00
struct AuthResult
{
bool success;
wstring username;
wstring uuid;
wstring accessToken;
wstring clientToken;
2026-04-03 21:39:59 -04:00
wstring error;
};
enum class AuthFlowState : uint8_t
{
IDLE,
WAITING_FOR_USER,
POLLING,
EXCHANGING,
COMPLETE,
FAILED
};
class AuthFlow
{
private:
static std::thread workerThread;
static std::atomic<AuthFlowState> state;
static std::atomic<bool> cancelRequested;
static AuthResult result;
static wstring userCode;
static wstring verificationUri;
2026-04-06 02:33:39 -04:00
static wstring activeVariation;
2026-04-03 21:39:59 -04:00
static void microsoftFlowThread();
2026-04-06 02:33:39 -04:00
static void yggdrasilFlowThread(const string &username, const string &password, const string &authenticateUrl);
2026-04-03 21:39:59 -04:00
public:
static void startMicrosoft();
2026-04-06 02:33:39 -04:00
static void startYggdrasil(const wstring &username, const wstring &password, const wstring &providerName = L"");
2026-04-03 21:39:59 -04:00
static AuthFlowState getState() { return state.load(); }
static const AuthResult &getResult() { return result; }
static const wstring &getUserCode() { return userCode; }
static const wstring &getVerificationUri() { return verificationUri; }
2026-04-06 02:33:39 -04:00
static const wstring &getActiveVariation() { return activeVariation; }
2026-04-03 21:39:59 -04:00
static void reset();
};