mirror of
https://github.com/PrismLauncher/PrismLauncher.git
synced 2025-06-13 05:37:42 +02:00
Removed AuthRequest and NetAction
Signed-off-by: Trial97 <alexandru.tripon97@gmail.com>
This commit is contained in:
@ -1,16 +1,20 @@
|
||||
#include "EntitlementsStep.h"
|
||||
|
||||
#include <QList>
|
||||
#include <QNetworkRequest>
|
||||
#include <QUrl>
|
||||
#include <QUuid>
|
||||
#include <memory>
|
||||
|
||||
#include "Application.h"
|
||||
#include "Logging.h"
|
||||
#include "minecraft/auth/AuthRequest.h"
|
||||
#include "minecraft/auth/Parsers.h"
|
||||
#include "net/Download.h"
|
||||
#include "net/StaticHeaderProxy.h"
|
||||
#include "tasks/Task.h"
|
||||
|
||||
EntitlementsStep::EntitlementsStep(AccountData* data) : AuthStep(data) {}
|
||||
|
||||
EntitlementsStep::~EntitlementsStep() noexcept = default;
|
||||
|
||||
QString EntitlementsStep::describe()
|
||||
{
|
||||
return tr("Determining game ownership.");
|
||||
@ -19,35 +23,31 @@ QString EntitlementsStep::describe()
|
||||
void EntitlementsStep::perform()
|
||||
{
|
||||
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());
|
||||
AuthRequest* requestor = new AuthRequest(this);
|
||||
connect(requestor, &AuthRequest::finished, this, &EntitlementsStep::onRequestDone);
|
||||
requestor->get(request);
|
||||
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_task = Net::Download::makeByteArray(url, m_response);
|
||||
m_task->addHeaderProxy(new Net::StaticHeaderProxy(headers));
|
||||
|
||||
connect(m_task.get(), &Task::finished, this, &EntitlementsStep::onRequestDone);
|
||||
|
||||
m_task->setNetwork(APPLICATION->network());
|
||||
m_task->start();
|
||||
qDebug() << "Getting entitlements...";
|
||||
}
|
||||
|
||||
void EntitlementsStep::rehydrate()
|
||||
void EntitlementsStep::onRequestDone()
|
||||
{
|
||||
// NOOP, for now. We only save bools and there's nothing to check.
|
||||
}
|
||||
|
||||
void EntitlementsStep::onRequestDone([[maybe_unused]] QNetworkReply::NetworkError error,
|
||||
QByteArray data,
|
||||
[[maybe_unused]] QList<QNetworkReply::RawHeaderPair> headers)
|
||||
{
|
||||
auto requestor = qobject_cast<AuthRequest*>(QObject::sender());
|
||||
requestor->deleteLater();
|
||||
|
||||
qCDebug(authCredentials()) << data;
|
||||
qCDebug(authCredentials()) << *m_response;
|
||||
|
||||
// TODO: check presence of same entitlementsRequestId?
|
||||
// TODO: validate JWTs?
|
||||
Parsers::parseMinecraftEntitlements(data, m_data->minecraftEntitlement);
|
||||
Parsers::parseMinecraftEntitlements(*m_response, m_data->minecraftEntitlement);
|
||||
|
||||
emit finished(AccountTaskState::STATE_WORKING, tr("Got entitlements"));
|
||||
}
|
||||
|
Reference in New Issue
Block a user