2021-12-04 00:18:05 +00:00
|
|
|
#include "EntitlementsStep.h"
|
|
|
|
|
|
|
|
#include <QNetworkRequest>
|
|
|
|
#include <QUuid>
|
|
|
|
|
2022-12-27 16:04:42 +00:00
|
|
|
#include "Logging.h"
|
2021-12-04 00:18:05 +00:00
|
|
|
#include "minecraft/auth/AuthRequest.h"
|
|
|
|
#include "minecraft/auth/Parsers.h"
|
|
|
|
|
|
|
|
EntitlementsStep::EntitlementsStep(AccountData* data) : AuthStep(data) {}
|
|
|
|
|
|
|
|
EntitlementsStep::~EntitlementsStep() noexcept = default;
|
|
|
|
|
2023-08-02 17:35:35 +01:00
|
|
|
QString EntitlementsStep::describe()
|
|
|
|
{
|
2021-12-04 00:18:05 +00:00
|
|
|
return tr("Determining game ownership.");
|
|
|
|
}
|
|
|
|
|
2023-08-02 17:35:35 +01:00
|
|
|
void EntitlementsStep::perform()
|
|
|
|
{
|
2021-12-04 00:18:05 +00:00
|
|
|
auto uuid = QUuid::createUuid();
|
|
|
|
m_entitlementsRequestId = uuid.toString().remove('{').remove('}');
|
|
|
|
auto url = "https://api.minecraftservices.com/entitlements/license?requestId=" + m_entitlementsRequestId;
|
|
|
|
QNetworkRequest request = QNetworkRequest(url);
|
|
|
|
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
|
|
|
|
request.setRawHeader("Accept", "application/json");
|
|
|
|
request.setRawHeader("Authorization", QString("Bearer %1").arg(m_data->yggdrasilToken.token).toUtf8());
|
2023-08-02 17:35:35 +01:00
|
|
|
AuthRequest* requestor = new AuthRequest(this);
|
2021-12-04 00:18:05 +00:00
|
|
|
connect(requestor, &AuthRequest::finished, this, &EntitlementsStep::onRequestDone);
|
|
|
|
requestor->get(request);
|
|
|
|
qDebug() << "Getting entitlements...";
|
|
|
|
}
|
|
|
|
|
2023-08-02 17:35:35 +01:00
|
|
|
void EntitlementsStep::rehydrate()
|
|
|
|
{
|
2021-12-04 00:18:05 +00:00
|
|
|
// NOOP, for now. We only save bools and there's nothing to check.
|
|
|
|
}
|
|
|
|
|
2023-08-02 17:35:35 +01:00
|
|
|
void EntitlementsStep::onRequestDone(QNetworkReply::NetworkError error, QByteArray data, QList<QNetworkReply::RawHeaderPair> headers)
|
|
|
|
{
|
|
|
|
auto requestor = qobject_cast<AuthRequest*>(QObject::sender());
|
2021-12-04 00:18:05 +00:00
|
|
|
requestor->deleteLater();
|
|
|
|
|
2022-12-27 16:04:42 +00:00
|
|
|
qCDebug(authCredentials()) << data;
|
2021-12-04 00:18:05 +00:00
|
|
|
|
|
|
|
// TODO: check presence of same entitlementsRequestId?
|
|
|
|
// TODO: validate JWTs?
|
|
|
|
Parsers::parseMinecraftEntitlements(data, m_data->minecraftEntitlement);
|
|
|
|
|
|
|
|
emit finished(AccountTaskState::STATE_WORKING, tr("Got entitlements"));
|
|
|
|
}
|