#pragma once using namespace std; #include #include struct AuthProfile { enum Type : uint8_t { MICROSOFT, YGGDRASIL, OFFLINE }; Type type; wstring uid; wstring username; wstring token; wstring clientToken; wstring variation; }; class AuthProfileManager { private: static vector profiles; static int selectedProfile; public: static void load(); static void save(); 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 &getProfiles() { return profiles; } static int getSelectedIndex() { return selectedProfile; } static void setSelectedIndex(int idx) { selectedProfile = idx; } }; struct AuthResult { bool success; wstring username; wstring uuid; wstring accessToken; wstring clientToken; 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 state; static std::atomic cancelRequested; static AuthResult result; static wstring userCode; static wstring verificationUri; static wstring activeVariation; static void microsoftFlowThread(); static void yggdrasilFlowThread(const string &username, const string &password, const string &authenticateUrl); public: static void startMicrosoft(); static void startYggdrasil(const wstring &username, const wstring &password, const wstring &providerName = L""); static AuthFlowState getState() { return state.load(); } static const AuthResult &getResult() { return result; } static const wstring &getUserCode() { return userCode; } static const wstring &getVerificationUri() { return verificationUri; } static const wstring &getActiveVariation() { return activeVariation; } static void reset(); };