Dehardcode account providers (#38)

* Dehardcode account providers

* Fix crash on creation

* Add dynamic 'add account dialog' provider selector

* Fix typo and add newlines

* Rename loginType to provider

* Rename MojangAccount to Account and MojangAccountList to AccountList

* Fix json save error
This commit is contained in:
Max
2021-06-14 12:51:25 +03:00
committed by GitHub
parent 396400b60d
commit 167b6bd405
39 changed files with 398 additions and 261 deletions

View File

@@ -26,7 +26,7 @@
#include "settings/INIFile.h"
#include "BaseVersionList.h"
#include "minecraft/auth/MojangAccount.h"
#include "minecraft/auth/Account.h"
#include "MessageLevel.h"
#include "pathmatcher/IPathMatcher.h"

View File

@@ -201,12 +201,14 @@ set(STATUS_SOURCES
# Support for Minecraft instances and launch
set(MINECRAFT_SOURCES
# Minecraft support
minecraft/auth/AuthProviders.h
minecraft/auth/AuthProviders.cpp
minecraft/auth/AuthSession.h
minecraft/auth/AuthSession.cpp
minecraft/auth/MojangAccountList.h
minecraft/auth/MojangAccountList.cpp
minecraft/auth/MojangAccount.h
minecraft/auth/MojangAccount.cpp
minecraft/auth/AccountList.h
minecraft/auth/AccountList.cpp
minecraft/auth/Account.h
minecraft/auth/Account.cpp
minecraft/auth/YggdrasilTask.h
minecraft/auth/YggdrasilTask.cpp
minecraft/auth/flows/AuthenticateTask.h
@@ -215,6 +217,10 @@ set(MINECRAFT_SOURCES
minecraft/auth/flows/RefreshTask.cpp
minecraft/auth/flows/ValidateTask.h
minecraft/auth/flows/ValidateTask.cpp
minecraft/auth/providers/BaseAuthProvider.h
minecraft/auth/providers/DummyAuthProvider.h
minecraft/auth/providers/ElybyAuthProvider.h
minecraft/auth/providers/MojangAuthProvider.h
minecraft/gameoptions/GameOptions.h
minecraft/gameoptions/GameOptions.cpp

View File

@@ -918,13 +918,10 @@ shared_qobject_ptr<LaunchTask> MinecraftInstance::createLaunchTask(AuthSessionPt
}
// authlib patch
if (session->m_accountPtr->loginType() != "mojang")
if (session->m_accountPtr->provider()->injectorEndpoint() != "")
{
auto step = new InjectAuthlib(pptr, &m_injector);
if(session->m_accountPtr->loginType() == "dummy")
step->setAuthServer(((QString)"http://localhost:%1").arg(localAuthServerPort));
else if(session->m_accountPtr->loginType() == "elyby")
step->setAuthServer(((QString) "ely.by").arg(localAuthServerPort));
step->setAuthServer(session->m_accountPtr->provider()->injectorEndpoint().arg(localAuthServerPort));
process->appendStep(step);
}

View File

@@ -15,7 +15,8 @@
* limitations under the License.
*/
#include "MojangAccount.h"
#include "Account.h"
#include "AuthProviders.h"
#include "flows/RefreshTask.h"
#include "flows/AuthenticateTask.h"
@@ -30,7 +31,7 @@
#include <BuildConfig.h>
MojangAccountPtr MojangAccount::loadFromJson(const QJsonObject &object)
AccountPtr Account::loadFromJson(const QJsonObject &object)
{
// The JSON object must at least have a username for it to be valid.
if (!object.value("username").isString())
@@ -40,7 +41,7 @@ MojangAccountPtr MojangAccount::loadFromJson(const QJsonObject &object)
return nullptr;
}
QString loginType = object.value("loginType").toString("mojang");
QString provider = object.value("loginType").toString("dummy");
QString username = object.value("username").toString("");
QString clientToken = object.value("clientToken").toString("");
QString accessToken = object.value("accessToken").toString("");
@@ -68,7 +69,7 @@ MojangAccountPtr MojangAccount::loadFromJson(const QJsonObject &object)
profiles.append({id, name, legacy});
}
MojangAccountPtr account(new MojangAccount());
AccountPtr account(new Account());
if (object.value("user").isObject())
{
User u;
@@ -85,7 +86,7 @@ MojangAccountPtr MojangAccount::loadFromJson(const QJsonObject &object)
*/
account->m_user = u;
}
account->m_loginType = loginType;
account->m_provider = AuthProviders::lookup(provider);
account->m_username = username;
account->m_clientToken = clientToken;
account->m_accessToken = accessToken;
@@ -99,18 +100,18 @@ MojangAccountPtr MojangAccount::loadFromJson(const QJsonObject &object)
return account;
}
MojangAccountPtr MojangAccount::createFromUsername(const QString &username)
AccountPtr Account::createFromUsername(const QString &username)
{
MojangAccountPtr account(new MojangAccount());
AccountPtr account(new Account());
account->m_clientToken = QUuid::createUuid().toString().remove(QRegExp("[{}-]"));
account->m_username = username;
return account;
}
QJsonObject MojangAccount::saveToJson() const
QJsonObject Account::saveToJson() const
{
QJsonObject json;
json.insert("loginType", m_loginType);
json.insert("loginType", m_provider->id());
json.insert("username", m_username);
json.insert("clientToken", m_clientToken);
json.insert("accessToken", m_accessToken);
@@ -147,18 +148,15 @@ QJsonObject MojangAccount::saveToJson() const
return json;
}
bool MojangAccount::setLoginType(const QString &loginType)
bool Account::setProvider(AuthProviderPtr provider)
{
// TODO: Implement a cleaner validity check
if (loginType == "mojang" || loginType == "dummy" || loginType == "elyby")
{
m_loginType = loginType;
return true;
}
return false;
if (provider == nullptr)
return false;
m_provider = provider;
return true;
}
bool MojangAccount::setCurrentProfile(const QString &profileId)
bool Account::setCurrentProfile(const QString &profileId)
{
for (int i = 0; i < m_profiles.length(); i++)
{
@@ -171,14 +169,14 @@ bool MojangAccount::setCurrentProfile(const QString &profileId)
return false;
}
const AccountProfile *MojangAccount::currentProfile() const
const AccountProfile *Account::currentProfile() const
{
if (m_currentProfile == -1)
return nullptr;
return &m_profiles[m_currentProfile];
}
AccountStatus MojangAccount::accountStatus() const
AccountStatus Account::accountStatus() const
{
if (m_accessToken.isEmpty())
return NotVerified;
@@ -186,32 +184,12 @@ AccountStatus MojangAccount::accountStatus() const
return Verified;
}
QString MojangAccount::authEndpoint() const
{
if(m_loginType == "elyby")
return BuildConfig.AUTH_BASE_ELYBY;
return BuildConfig.AUTH_BASE_MOJANG;
}
QString MojangAccount::displayLoginType() const
{
if(m_loginType == "mojang")
return "Mojang";
if(m_loginType == "dummy")
return "Local";
if(m_loginType == "elyby")
return "Ely.by";
return "Unknown";
}
std::shared_ptr<YggdrasilTask> MojangAccount::login(AuthSessionPtr session, QString password)
std::shared_ptr<YggdrasilTask> Account::login(AuthSessionPtr session, QString password)
{
Q_ASSERT(m_currentTask.get() == nullptr);
// Handling alternative account types
if (m_loginType == "dummy")
if (m_provider->dummyAuth())
{
if (session)
{
@@ -267,7 +245,7 @@ std::shared_ptr<YggdrasilTask> MojangAccount::login(AuthSessionPtr session, QStr
return m_currentTask;
}
void MojangAccount::authSucceeded()
void Account::authSucceeded()
{
auto session = m_currentTask->getAssignedSession();
if (session)
@@ -281,7 +259,7 @@ void MojangAccount::authSucceeded()
emit changed();
}
void MojangAccount::authFailed(QString reason)
void Account::authFailed(QString reason)
{
auto session = m_currentTask->getAssignedSession();
// This is emitted when the yggdrasil tasks time out or are cancelled.
@@ -310,7 +288,7 @@ void MojangAccount::authFailed(QString reason)
m_currentTask.reset();
}
void MojangAccount::fillSession(AuthSessionPtr session)
void Account::fillSession(AuthSessionPtr session)
{
// the user name. you have to have an user name
session->username = m_username;
@@ -344,7 +322,7 @@ void MojangAccount::fillSession(AuthSessionPtr session)
session->m_accountPtr = shared_from_this();
}
void MojangAccount::decrementUses()
void Account::decrementUses()
{
Usable::decrementUses();
if(!isInUse())
@@ -354,7 +332,7 @@ void MojangAccount::decrementUses()
}
}
void MojangAccount::incrementUses()
void Account::incrementUses()
{
bool wasInUse = isInUse();
Usable::incrementUses();
@@ -365,7 +343,7 @@ void MojangAccount::incrementUses()
}
}
void MojangAccount::invalidateClientToken()
void Account::invalidateClientToken()
{
m_clientToken = QUuid::createUuid().toString().remove(QRegExp("[{}-]"));
emit changed();

View File

@@ -24,16 +24,18 @@
#include <memory>
#include "AuthSession.h"
#include "AccountProfile.h"
#include "Usable.h"
#include "providers/BaseAuthProvider.h"
#include "multimc_logic_export.h"
class Task;
class YggdrasilTask;
class MojangAccount;
class Account;
typedef std::shared_ptr<MojangAccount> MojangAccountPtr;
Q_DECLARE_METATYPE(MojangAccountPtr)
typedef std::shared_ptr<Account> AccountPtr;
Q_DECLARE_METATYPE(AccountPtr)
/**
* A profile within someone's Mojang account.
@@ -42,12 +44,6 @@ Q_DECLARE_METATYPE(MojangAccountPtr)
* but we might as well add some things for it in MultiMC right now so
* we don't have to rip the code to pieces to add it later.
*/
struct AccountProfile
{
QString id;
QString name;
bool legacy;
};
enum AccountStatus
{
@@ -61,34 +57,33 @@ enum AccountStatus
* Said information may include things such as that account's username, client token, and access
* token if the user chose to stay logged in.
*/
class MULTIMC_LOGIC_EXPORT MojangAccount :
class MULTIMC_LOGIC_EXPORT Account :
public QObject,
public Usable,
public std::enable_shared_from_this<MojangAccount>
public std::enable_shared_from_this<Account>
{
Q_OBJECT
public: /* construction */
//! Do not copy accounts. ever.
explicit MojangAccount(const MojangAccount &other, QObject *parent) = delete;
explicit Account(const Account &other, QObject *parent) = delete;
//! Default constructor
explicit MojangAccount(QObject *parent = 0) : QObject(parent) {};
explicit Account(QObject *parent = 0) : QObject(parent) {};
//! Creates an empty account for the specified user name.
static MojangAccountPtr createFromUsername(const QString &username);
static AccountPtr createFromUsername(const QString &username);
//! Loads a MojangAccount from the given JSON object.
static MojangAccountPtr loadFromJson(const QJsonObject &json);
//! Loads a Account from the given JSON object.
static AccountPtr loadFromJson(const QJsonObject &json);
//! Saves a MojangAccount to a JSON object and returns it.
//! Saves a Account to a JSON object and returns it.
QJsonObject saveToJson() const;
public: /* manipulation */
/**
* Overrides the login type on the account.
* Accepts "mojang" and "dummy". Returns false if other.
*/
bool setLoginType(const QString &loginType);
bool setProvider(AuthProviderPtr provider);
/**
* Sets the currently selected profile to the profile with the given ID string.
@@ -105,9 +100,9 @@ public: /* manipulation */
void invalidateClientToken();
public: /* queries */
const QString &loginType() const
const AuthProviderPtr provider() const
{
return m_loginType;
return m_provider;
}
const QString &username() const
@@ -141,12 +136,6 @@ public: /* queries */
//! Returns whether the account is NotVerified, Verified or Online
AccountStatus accountStatus() const;
//! Returns endpoint for authentication
QString authEndpoint() const;
// ! Returns login type to display in account list or account chooser
QString displayLoginType() const;
signals:
/**
* This signal is emitted when the account changes
@@ -158,7 +147,7 @@ signals:
protected: /* variables */
// Authentication system used.
// Usable values: "mojang", "dummy", "elyby"
QString m_loginType;
AuthProviderPtr m_provider;
// Username taken by account.
QString m_username;

View File

@@ -13,8 +13,8 @@
* limitations under the License.
*/
#include "MojangAccountList.h"
#include "MojangAccount.h"
#include "AccountList.h"
#include "Account.h"
#include <QIODevice>
#include <QFile>
@@ -31,27 +31,27 @@
#define ACCOUNT_LIST_FORMAT_VERSION 2
MojangAccountList::MojangAccountList(QObject *parent) : QAbstractListModel(parent)
AccountList::AccountList(QObject *parent) : QAbstractListModel(parent)
{
}
MojangAccountPtr MojangAccountList::findAccount(const QString &username) const
AccountPtr AccountList::findAccount(const QString &username) const
{
for (int i = 0; i < count(); i++)
{
MojangAccountPtr account = at(i);
AccountPtr account = at(i);
if (account->username() == username)
return account;
}
return nullptr;
}
const MojangAccountPtr MojangAccountList::at(int i) const
const AccountPtr AccountList::at(int i) const
{
return MojangAccountPtr(m_accounts.at(i));
return AccountPtr(m_accounts.at(i));
}
void MojangAccountList::addAccount(const MojangAccountPtr account)
void AccountList::addAccount(const AccountPtr account)
{
int row = m_accounts.count();
beginInsertRows(QModelIndex(), row, row);
@@ -61,7 +61,7 @@ void MojangAccountList::addAccount(const MojangAccountPtr account)
onListChanged();
}
void MojangAccountList::removeAccount(const QString &username)
void AccountList::removeAccount(const QString &username)
{
int idx = 0;
for (auto account : m_accounts)
@@ -78,7 +78,7 @@ void MojangAccountList::removeAccount(const QString &username)
onListChanged();
}
void MojangAccountList::removeAccount(QModelIndex index)
void AccountList::removeAccount(QModelIndex index)
{
int row = index.row();
if(index.isValid() && row >= 0 && row < m_accounts.size())
@@ -96,19 +96,19 @@ void MojangAccountList::removeAccount(QModelIndex index)
}
}
MojangAccountPtr MojangAccountList::activeAccount() const
AccountPtr AccountList::activeAccount() const
{
return m_activeAccount;
}
void MojangAccountList::setActiveAccount(const QString &username)
void AccountList::setActiveAccount(const QString &username)
{
if (username.isEmpty() && m_activeAccount)
{
int idx = 0;
auto prevActiveAcc = m_activeAccount;
m_activeAccount = nullptr;
for (MojangAccountPtr account : m_accounts)
for (AccountPtr account : m_accounts)
{
if (account == prevActiveAcc)
{
@@ -125,7 +125,7 @@ void MojangAccountList::setActiveAccount(const QString &username)
auto newActiveAccount = m_activeAccount;
int newActiveAccountIdx = -1;
int idx = 0;
for (MojangAccountPtr account : m_accounts)
for (AccountPtr account : m_accounts)
{
if (account->username() == username)
{
@@ -148,13 +148,13 @@ void MojangAccountList::setActiveAccount(const QString &username)
}
}
void MojangAccountList::accountChanged()
void AccountList::accountChanged()
{
// the list changed. there is no doubt.
onListChanged();
}
void MojangAccountList::onListChanged()
void AccountList::onListChanged()
{
if (m_autosave)
// TODO: Alert the user if this fails.
@@ -163,7 +163,7 @@ void MojangAccountList::onListChanged()
emit listChanged();
}
void MojangAccountList::onActiveChanged()
void AccountList::onActiveChanged()
{
if (m_autosave)
saveList();
@@ -171,12 +171,12 @@ void MojangAccountList::onActiveChanged()
emit activeAccountChanged();
}
int MojangAccountList::count() const
int AccountList::count() const
{
return m_accounts.count();
}
QVariant MojangAccountList::data(const QModelIndex &index, int role) const
QVariant AccountList::data(const QModelIndex &index, int role) const
{
if (!index.isValid())
return QVariant();
@@ -184,7 +184,7 @@ QVariant MojangAccountList::data(const QModelIndex &index, int role) const
if (index.row() > count())
return QVariant();
MojangAccountPtr account = at(index.row());
AccountPtr account = at(index.row());
switch (role)
{
@@ -195,7 +195,7 @@ QVariant MojangAccountList::data(const QModelIndex &index, int role) const
return account->username();
case TypeColumn:
return account->displayLoginType();
return account->provider()->displayName();
default:
return QVariant();
@@ -219,7 +219,7 @@ QVariant MojangAccountList::data(const QModelIndex &index, int role) const
}
}
QVariant MojangAccountList::headerData(int section, Qt::Orientation orientation, int role) const
QVariant AccountList::headerData(int section, Qt::Orientation orientation, int role) const
{
switch (role)
{
@@ -254,18 +254,18 @@ QVariant MojangAccountList::headerData(int section, Qt::Orientation orientation,
}
}
int MojangAccountList::rowCount(const QModelIndex &) const
int AccountList::rowCount(const QModelIndex &) const
{
// Return count
return count();
}
int MojangAccountList::columnCount(const QModelIndex &) const
int AccountList::columnCount(const QModelIndex &) const
{
return 3;
}
Qt::ItemFlags MojangAccountList::flags(const QModelIndex &index) const
Qt::ItemFlags AccountList::flags(const QModelIndex &index) const
{
if (index.row() < 0 || index.row() >= rowCount(index) || !index.isValid())
{
@@ -275,7 +275,7 @@ Qt::ItemFlags MojangAccountList::flags(const QModelIndex &index) const
return Qt::ItemIsUserCheckable | Qt::ItemIsEnabled | Qt::ItemIsSelectable;
}
bool MojangAccountList::setData(const QModelIndex &index, const QVariant &value, int role)
bool AccountList::setData(const QModelIndex &index, const QVariant &value, int role)
{
if (index.row() < 0 || index.row() >= rowCount(index) || !index.isValid())
{
@@ -286,7 +286,7 @@ bool MojangAccountList::setData(const QModelIndex &index, const QVariant &value,
{
if(value == Qt::Checked)
{
MojangAccountPtr account = this->at(index.row());
AccountPtr account = this->at(index.row());
this->setActiveAccount(account->username());
}
}
@@ -295,14 +295,14 @@ bool MojangAccountList::setData(const QModelIndex &index, const QVariant &value,
return true;
}
void MojangAccountList::updateListData(QList<MojangAccountPtr> versions)
void AccountList::updateListData(QList<AccountPtr> versions)
{
beginResetModel();
m_accounts = versions;
endResetModel();
}
bool MojangAccountList::loadList(const QString &filePath)
bool AccountList::loadList(const QString &filePath)
{
QString path = filePath;
if (path.isEmpty())
@@ -366,7 +366,7 @@ bool MojangAccountList::loadList(const QString &filePath)
for (QJsonValue accountVal : accounts)
{
QJsonObject accountObj = accountVal.toObject();
MojangAccountPtr account = MojangAccount::loadFromJson(accountObj);
AccountPtr account = Account::loadFromJson(accountObj);
if (account.get() != nullptr)
{
connect(account.get(), SIGNAL(changed()), SLOT(accountChanged()));
@@ -383,7 +383,7 @@ bool MojangAccountList::loadList(const QString &filePath)
return true;
}
bool MojangAccountList::saveList(const QString &filePath)
bool AccountList::saveList(const QString &filePath)
{
QString path(filePath);
if (path.isEmpty())
@@ -417,7 +417,7 @@ bool MojangAccountList::saveList(const QString &filePath)
// Build a list of accounts.
qDebug() << "Building account array.";
QJsonArray accounts;
for (MojangAccountPtr account : m_accounts)
for (AccountPtr account : m_accounts)
{
QJsonObject accountObj = account->saveToJson();
accounts.append(accountObj);
@@ -457,13 +457,13 @@ bool MojangAccountList::saveList(const QString &filePath)
return true;
}
void MojangAccountList::setListFilePath(QString path, bool autosave)
void AccountList::setListFilePath(QString path, bool autosave)
{
m_listFilePath = path;
m_autosave = autosave;
}
bool MojangAccountList::anyAccountIsValid()
bool AccountList::anyAccountIsValid()
{
for(auto account:m_accounts)
{

View File

@@ -15,7 +15,7 @@
#pragma once
#include "MojangAccount.h"
#include "Account.h"
#include <QObject>
#include <QVariant>
@@ -33,7 +33,7 @@
* all have a default implementation, but they can be overridden by subclasses to
* change the behavior of the list.
*/
class MULTIMC_LOGIC_EXPORT MojangAccountList : public QAbstractListModel
class MULTIMC_LOGIC_EXPORT AccountList : public QAbstractListModel
{
Q_OBJECT
public:
@@ -56,10 +56,10 @@ public:
TypeColumn,
};
explicit MojangAccountList(QObject *parent = 0);
explicit AccountList(QObject *parent = 0);
//! Gets the account at the given index.
virtual const MojangAccountPtr at(int i) const;
virtual const AccountPtr at(int i) const;
//! Returns the number of accounts in the list.
virtual int count() const;
@@ -75,7 +75,7 @@ public:
/*!
* Adds a the given Mojang account to the account list.
*/
virtual void addAccount(const MojangAccountPtr account);
virtual void addAccount(const AccountPtr account);
/*!
* Removes the mojang account with the given username from the account list.
@@ -93,7 +93,7 @@ public:
* \return A const pointer to the account with the given username. NULL if
* one doesn't exist.
*/
virtual MojangAccountPtr findAccount(const QString &username) const;
virtual AccountPtr findAccount(const QString &username) const;
/*!
* Sets the default path to save the list file to.
@@ -122,9 +122,9 @@ public:
* \brief Gets a pointer to the account that the user has selected as their "active" account.
* Which account is active can be overridden on a per-instance basis, but this will return the one that
* is set as active globally.
* \return The currently active MojangAccount. If there isn't an active account, returns a null pointer.
* \return The currently active Account. If there isn't an active account, returns a null pointer.
*/
virtual MojangAccountPtr activeAccount() const;
virtual AccountPtr activeAccount() const;
/*!
* Sets the given account as the current active account.
@@ -170,12 +170,12 @@ protected:
*/
void onActiveChanged();
QList<MojangAccountPtr> m_accounts;
QList<AccountPtr> m_accounts;
/*!
* Account that is currently active.
*/
MojangAccountPtr m_activeAccount;
AccountPtr m_activeAccount;
//! Path to the account list file. Empty string if there isn't one.
QString m_listFilePath;
@@ -200,5 +200,5 @@ slots:
* then copies the accounts and sets their parents correctly.
* \param accounts List of accounts whose parents should be set.
*/
virtual void updateListData(QList<MojangAccountPtr> versions);
virtual void updateListData(QList<AccountPtr> versions);
};

View File

@@ -0,0 +1,9 @@
#pragma once
#include <QString>
struct AccountProfile
{
QString id;
QString name;
bool legacy;
};

View File

@@ -0,0 +1,37 @@
#include "AuthProviders.h"
#include "providers/ElybyAuthProvider.h"
#include "providers/DummyAuthProvider.h"
#include "providers/MojangAuthProvider.h"
#define REGISTER_AUTH_PROVIDER(Provider) \
{ \
AuthProviderPtr provider(new Provider()); \
m_providers.insert(provider->id(), provider); \
}
namespace AuthProviders
{
QMap<QString, AuthProviderPtr> m_providers;
void load()
{
REGISTER_AUTH_PROVIDER(ElybyAuthProvider);
REGISTER_AUTH_PROVIDER(DummyAuthProvider);
REGISTER_AUTH_PROVIDER(MojangAuthProvider);
}
AuthProviderPtr lookup(QString id)
{
qDebug() << "LOOKUP AUTH_PROVIDER" << id;
if (m_providers.contains(id))
return m_providers.value(id);
qDebug() << "Lookup failed";
return nullptr;
}
QList<AuthProviderPtr> getAll() {
return m_providers.values();
}
}

View File

@@ -0,0 +1,22 @@
#pragma once
#include <QObject>
#include "QObjectPtr.h"
#include <QDateTime>
#include <QSet>
#include <QProcess>
#include <QMap>
#include "providers/BaseAuthProvider.h"
#include "multimc_logic_export.h"
/*!
* \brief Namespace for auth providers.
* This class main putpose is to handle registration and lookup of auth providers
*/
namespace AuthProviders
{
MULTIMC_LOGIC_EXPORT void load();
MULTIMC_LOGIC_EXPORT AuthProviderPtr lookup(QString id);
MULTIMC_LOGIC_EXPORT QList<AuthProviderPtr> getAll();
}

View File

@@ -6,7 +6,7 @@
#include "multimc_logic_export.h"
class MojangAccount;
class Account;
struct User
{
@@ -48,7 +48,7 @@ struct MULTIMC_LOGIC_EXPORT AuthSession
bool auth_server_online = false;
// Did the user request online mode?
bool wants_online = true;
std::shared_ptr<MojangAccount> m_accountPtr;
std::shared_ptr<Account> m_accountPtr;
};
typedef std::shared_ptr<AuthSession> AuthSessionPtr;

View File

@@ -14,7 +14,7 @@
*/
#include "YggdrasilTask.h"
#include "MojangAccount.h"
#include "Account.h"
#include <QObject>
#include <QString>
@@ -27,7 +27,7 @@
#include <QDebug>
YggdrasilTask::YggdrasilTask(MojangAccount *account, QObject *parent)
YggdrasilTask::YggdrasilTask(Account *account, QObject *parent)
: Task(parent), m_account(account)
{
changeState(STATE_CREATED);
@@ -40,9 +40,8 @@ void YggdrasilTask::executeTask()
// Get the content of the request we're going to send to the server.
QJsonDocument doc(getRequestContent());
QUrl reqUrl(m_account->authEndpoint() + getEndpoint());
qDebug() << m_account->authEndpoint() + getEndpoint();
QNetworkRequest netRequest(reqUrl);
QUrl reqUrl(m_account->provider()->authEndpoint() + getEndpoint());
QNetworkRequest netRequest(reqUrl);
netRequest.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
QByteArray requestData = doc.toJson();

View File

@@ -22,7 +22,7 @@
#include <QTimer>
#include <qsslerror.h>
#include "MojangAccount.h"
#include "Account.h"
class QNetworkReply;
@@ -33,7 +33,7 @@ class YggdrasilTask : public Task
{
Q_OBJECT
public:
explicit YggdrasilTask(MojangAccount * account, QObject *parent = 0);
explicit YggdrasilTask(Account * account, QObject *parent = 0);
virtual ~YggdrasilTask() {};
/**
@@ -137,7 +137,7 @@ slots:
State state();
protected:
// FIXME: segfault disaster waiting to happen
MojangAccount *m_account = nullptr;
Account *m_account = nullptr;
QNetworkReply *m_netReply = nullptr;
std::shared_ptr<Error> m_error;
QTimer timeout_keeper;

View File

@@ -15,7 +15,7 @@
*/
#include "AuthenticateTask.h"
#include "../MojangAccount.h"
#include "../Account.h"
#include <QJsonDocument>
#include <QJsonObject>
@@ -25,7 +25,7 @@
#include <QDebug>
#include <QUuid>
AuthenticateTask::AuthenticateTask(MojangAccount * account, const QString &password,
AuthenticateTask::AuthenticateTask(Account * account, const QString &password,
QObject *parent)
: YggdrasilTask(account, parent), m_password(password)
{
@@ -139,7 +139,7 @@ void AuthenticateTask::processResponse(QJsonObject responseData)
// Now, add a new AccountProfile entry to the list.
loadedProfiles.append({id, name, legacy});
}
// Put the list of profiles we loaded into the MojangAccount object.
// Put the list of profiles we loaded into the Account object.
m_account->m_profiles = loadedProfiles;
// Finally, we set the current profile to the correct value. This is pretty simple.

View File

@@ -22,15 +22,15 @@
#include <QJsonObject>
/**
* The authenticate task takes a MojangAccount with no access token and password and attempts to
* The authenticate task takes a Account with no access token and password and attempts to
* authenticate with Mojang's servers.
* If successful, it will set the MojangAccount's access token.
* If successful, it will set the Account's access token.
*/
class AuthenticateTask : public YggdrasilTask
{
Q_OBJECT
public:
AuthenticateTask(MojangAccount *account, const QString &password, QObject *parent = 0);
AuthenticateTask(Account *account, const QString &password, QObject *parent = 0);
protected:
virtual QJsonObject getRequestContent() const override;

View File

@@ -14,7 +14,7 @@
*/
#include "RefreshTask.h"
#include "../MojangAccount.h"
#include "../Account.h"
#include <QJsonDocument>
#include <QJsonObject>
@@ -23,7 +23,7 @@
#include <QDebug>
RefreshTask::RefreshTask(MojangAccount *account) : YggdrasilTask(account)
RefreshTask::RefreshTask(Account *account) : YggdrasilTask(account)
{
}

View File

@@ -22,7 +22,7 @@
#include <QJsonObject>
/**
* The authenticate task takes a MojangAccount with a possibly timed-out access token
* The authenticate task takes a Account with a possibly timed-out access token
* and attempts to authenticate with Mojang's servers.
* If successful, it will set the new access token. The token is considered validated.
*/
@@ -30,7 +30,7 @@ class RefreshTask : public YggdrasilTask
{
Q_OBJECT
public:
RefreshTask(MojangAccount * account);
RefreshTask(Account * account);
protected:
virtual QJsonObject getRequestContent() const override;

View File

@@ -15,7 +15,7 @@
*/
#include "ValidateTask.h"
#include "../MojangAccount.h"
#include "../Account.h"
#include <QJsonDocument>
#include <QJsonObject>
@@ -24,7 +24,7 @@
#include <QDebug>
ValidateTask::ValidateTask(MojangAccount * account, QObject *parent)
ValidateTask::ValidateTask(Account * account, QObject *parent)
: YggdrasilTask(account, parent)
{
}

View File

@@ -26,13 +26,13 @@
#include <QJsonObject>
/**
* The validate task takes a MojangAccount and checks to make sure its access token is valid.
* The validate task takes a Account and checks to make sure its access token is valid.
*/
class ValidateTask : public YggdrasilTask
{
Q_OBJECT
public:
ValidateTask(MojangAccount *account, QObject *parent = 0);
ValidateTask(Account *account, QObject *parent = 0);
protected:
virtual QJsonObject getRequestContent() const override;

View File

@@ -0,0 +1,52 @@
#pragma once
#include <QObject>
#include "QObjectPtr.h"
#include <QDateTime>
#include <QSet>
#include <QProcess>
#include <QUrl>
#include "multimc_logic_export.h"
#include "minecraft/auth/AccountProfile.h"
class BaseAuthProvider;
typedef std::shared_ptr<BaseAuthProvider> AuthProviderPtr;
/*!
* \brief Base class for auth provider.
* This class implements many functions that are common between providers and
* provides a standard interface for all providers.
*
* To create a new provider, create a new class inheriting from this class,
* implement the pure virtual functions, and
*/
class MULTIMC_LOGIC_EXPORT BaseAuthProvider : public QObject //, public std::enable_shared_from_this<BaseAuthProvider>
{
Q_OBJECT
public:
virtual ~BaseAuthProvider(){};
// Unique id for provider
virtual QString id() { return "base"; };
// Name of provider that displayed in account selector and list
virtual QString displayName() { return "Base"; };
// Use dummy auth on login instead of calling endpoint
virtual bool dummyAuth() { return false; };
// Endpoint for authlib injector (use empty if authlib injector isn't required)
virtual QString injectorEndpoint() { return ""; };
// Endpoint for authentication
virtual QString authEndpoint() { return ""; };
// Function to get url of skin to display in launcher
virtual QUrl resolveSkinUrl(AccountProfile profile) { return QUrl(((QString) "https://crafatar.com/skins/%1.png").arg(profile.id)); };
// Can change skin (currently only mojang support)
virtual bool canChangeSkin() { return false; }
};

View File

@@ -0,0 +1,25 @@
#pragma once
#include <QObject>
#include "QObjectPtr.h"
#include <QDateTime>
#include <QSet>
#include <QProcess>
#include <QDebug>
#include "BaseAuthProvider.h"
class DummyAuthProvider : public BaseAuthProvider
{
Q_OBJECT
public:
QString id()
{
return "dummy";
}
QString displayName() { return "Local"; }
bool dummyAuth() { return true; }
QString injectorEndpoint() { return "http://localhost:%1"; };
};

View File

@@ -0,0 +1,26 @@
#pragma once
#include <QObject>
#include "QObjectPtr.h"
#include <QDateTime>
#include <QSet>
#include <QProcess>
#include <QDebug>
#include "BaseAuthProvider.h"
class ElybyAuthProvider : public BaseAuthProvider
{
Q_OBJECT
public:
QString id()
{
return "elyby";
}
QString displayName() { return "Ely.by"; };
QString injectorEndpoint() { return "ely.by"; };
QString authEndpoint() { return "https://authserver.ely.by/auth/"; };
QUrl resolveSkinUrl(AccountProfile profile) { return QUrl(((QString) "http://skinsystem.ely.by/skins/%1.png").arg(profile.name)); }
};

View File

@@ -0,0 +1,25 @@
#pragma once
#include <QObject>
#include "QObjectPtr.h"
#include <QDateTime>
#include <QSet>
#include <QProcess>
#include <QDebug>
#include "BaseAuthProvider.h"
class MojangAuthProvider : public BaseAuthProvider
{
Q_OBJECT
public:
QString id()
{
return "mojang";
}
QString displayName() { return "Mojang"; };
QString authEndpoint() { return "https://authserver.mojang.com/"; };
bool canChangeSkin() { return true; };
};

View File

@@ -16,7 +16,7 @@
#pragma once
#include <launch/LaunchStep.h>
#include <minecraft/auth/MojangAccount.h>
#include <minecraft/auth/Account.h>
class ClaimAccount: public LaunchStep
{
@@ -33,5 +33,5 @@ public:
}
private:
std::unique_ptr<UseLock> lock;
MojangAccountPtr m_account;
AccountPtr m_account;
};