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:
@ -3,28 +3,21 @@
|
||||
#include <QNetworkRequest>
|
||||
#include <QUrlQuery>
|
||||
|
||||
#include "Application.h"
|
||||
#include "Logging.h"
|
||||
#include "minecraft/auth/AuthRequest.h"
|
||||
#include "minecraft/auth/Parsers.h"
|
||||
#include "net/NetUtils.h"
|
||||
#include "net/StaticHeaderProxy.h"
|
||||
|
||||
XboxProfileStep::XboxProfileStep(AccountData* data) : AuthStep(data) {}
|
||||
|
||||
XboxProfileStep::~XboxProfileStep() noexcept = default;
|
||||
|
||||
QString XboxProfileStep::describe()
|
||||
{
|
||||
return tr("Fetching Xbox profile.");
|
||||
}
|
||||
|
||||
void XboxProfileStep::rehydrate()
|
||||
{
|
||||
// NOOP, for now. We only save bools and there's nothing to check.
|
||||
}
|
||||
|
||||
void XboxProfileStep::perform()
|
||||
{
|
||||
auto url = QUrl("https://profile.xboxlive.com/users/me/profile/settings");
|
||||
QUrl url("https://profile.xboxlive.com/users/me/profile/settings");
|
||||
QUrlQuery q;
|
||||
q.addQueryItem("settings",
|
||||
"GameDisplayName,AppDisplayName,AppDisplayPicRaw,GameDisplayPicRaw,"
|
||||
@ -33,36 +26,38 @@ void XboxProfileStep::perform()
|
||||
"PreferredColor,Location,Bio,Watermarks,"
|
||||
"RealName,RealNameOverride,IsQuarantined");
|
||||
url.setQuery(q);
|
||||
auto headers = QList<Net::HeaderPair>{
|
||||
{ "Content-Type", "application/json" },
|
||||
{ "Accept", "application/json" },
|
||||
{ "x-xbl-contract-version", "3" },
|
||||
{ "Authorization", QString("XBL3.0 x=%1;%2").arg(m_data->userToken.extra["uhs"].toString(), m_data->xboxApiToken.token).toUtf8() }
|
||||
};
|
||||
|
||||
QNetworkRequest request = QNetworkRequest(url);
|
||||
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
|
||||
request.setRawHeader("Accept", "application/json");
|
||||
request.setRawHeader("x-xbl-contract-version", "3");
|
||||
request.setRawHeader("Authorization",
|
||||
QString("XBL3.0 x=%1;%2").arg(m_data->userToken.extra["uhs"].toString(), m_data->xboxApiToken.token).toUtf8());
|
||||
AuthRequest* requestor = new AuthRequest(this);
|
||||
connect(requestor, &AuthRequest::finished, this, &XboxProfileStep::onRequestDone);
|
||||
requestor->get(request);
|
||||
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, &XboxProfileStep::onRequestDone);
|
||||
|
||||
m_task->setNetwork(APPLICATION->network());
|
||||
m_task->start();
|
||||
qDebug() << "Getting Xbox profile...";
|
||||
}
|
||||
|
||||
void XboxProfileStep::onRequestDone(QNetworkReply::NetworkError error, QByteArray data, QList<QNetworkReply::RawHeaderPair> headers)
|
||||
void XboxProfileStep::onRequestDone()
|
||||
{
|
||||
auto requestor = qobject_cast<AuthRequest*>(QObject::sender());
|
||||
requestor->deleteLater();
|
||||
|
||||
if (error != QNetworkReply::NoError) {
|
||||
qWarning() << "Reply error:" << error;
|
||||
qCDebug(authCredentials()) << data;
|
||||
if (Net::isApplicationError(error)) {
|
||||
emit finished(AccountTaskState::STATE_FAILED_SOFT, tr("Failed to retrieve the Xbox profile: %1").arg(requestor->errorString_));
|
||||
if (m_task->error() != QNetworkReply::NoError) {
|
||||
qWarning() << "Reply error:" << m_task->error();
|
||||
qCDebug(authCredentials()) << *m_response;
|
||||
if (Net::isApplicationError(m_task->error())) {
|
||||
emit finished(AccountTaskState::STATE_FAILED_SOFT, tr("Failed to retrieve the Xbox profile: %1").arg(m_task->errorString()));
|
||||
} else {
|
||||
emit finished(AccountTaskState::STATE_OFFLINE, tr("Failed to retrieve the Xbox profile: %1").arg(requestor->errorString_));
|
||||
emit finished(AccountTaskState::STATE_OFFLINE, tr("Failed to retrieve the Xbox profile: %1").arg(m_task->errorString()));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
qCDebug(authCredentials()) << "XBox profile: " << data;
|
||||
qCDebug(authCredentials()) << "XBox profile: " << *m_response;
|
||||
|
||||
emit finished(AccountTaskState::STATE_WORKING, tr("Got Xbox profile"));
|
||||
}
|
||||
|
Reference in New Issue
Block a user