ShatteredPrism/launcher/minecraft/auth/steps/EntitlementsStep.cpp
Trial97 061fdc1ada
Merge branch 'develop' of https://github.com/PrismLauncher/PrismLauncher into clean_net
Signed-off-by: Trial97 <alexandru.tripon97@gmail.com>
2024-07-09 18:36:23 +03:00

58 lines
1.8 KiB
C++

#include "EntitlementsStep.h"
#include <QList>
#include <QNetworkRequest>
#include <QUrl>
#include <QUuid>
#include <memory>
#include "Application.h"
#include "Logging.h"
#include "minecraft/auth/Parsers.h"
#include "net/Download.h"
#include "net/NetJob.h"
#include "net/RawHeaderProxy.h"
#include "tasks/Task.h"
EntitlementsStep::EntitlementsStep(AccountData* data) : AuthStep(data) {}
QString EntitlementsStep::describe()
{
return tr("Determining game ownership.");
}
void EntitlementsStep::perform()
{
auto uuid = QUuid::createUuid();
m_entitlements_request_id = uuid.toString().remove('{').remove('}');
QUrl url("https://api.minecraftservices.com/entitlements/license?requestId=" + m_entitlements_request_id);
auto headers = QList<Net::HeaderPair>{ { "Content-Type", "application/json" },
{ "Accept", "application/json" },
{ "Authorization", QString("Bearer %1").arg(m_data->yggdrasilToken.token).toUtf8() } };
m_response.reset(new QByteArray());
m_request = Net::Download::makeByteArray(url, m_response);
m_request->addHeaderProxy(new Net::RawHeaderProxy(headers));
m_task.reset(new NetJob("EntitlementsStep", APPLICATION->network()));
m_task->setAskRetry(false);
m_task->addNetAction(m_request);
connect(m_task.get(), &Task::finished, this, &EntitlementsStep::onRequestDone);
m_task->start();
qDebug() << "Getting entitlements...";
}
void EntitlementsStep::onRequestDone()
{
qCDebug(authCredentials()) << *m_response;
// TODO: check presence of same entitlementsRequestId?
// TODO: validate JWTs?
Parsers::parseMinecraftEntitlements(*m_response, m_data->minecraftEntitlement);
emit finished(AccountTaskState::STATE_WORKING, tr("Got entitlements"));
}