Verified Commit 69ae17e9 authored by Daniel Vrátil's avatar Daniel Vrátil 🤖
Browse files

Make it again possible to pass username to AuthJob

parent d54f786a
......@@ -84,6 +84,7 @@ public:
account->setScopes(currentScopes);
}
AuthJob *job = new AuthJob(account, apiKey, apiSecret);
job->setUsername(account->accountName());
connect(job, &AuthJob::finished,
[=]() {
if (job->error() != KGAPI2::NoError) {
......
......@@ -43,6 +43,7 @@ public:
AccountPtr account;
QString apiKey;
QString secretKey;
QString username;
private:
AuthJob * const q;
......@@ -64,8 +65,9 @@ AccountPtr AuthJob::account() const
return d->account;
}
void AuthJob::setUsername(const QString& /*username*/)
void AuthJob::setUsername(const QString& username)
{
d->username = username;
}
void AuthJob::setPassword(const QString& /*password*/)
......@@ -92,6 +94,7 @@ void AuthJob::start()
d->account->addScope(Account::accountInfoEmailScopeUrl());
auto *job = new FullAuthenticationJob(d->account, d->apiKey, d->secretKey, this);
job->setUsername(d->username);
job->setServerPort(kgapiTcpAuthServerPort);
connect(job, &Job::finished, this, [this](Job *job) { d->jobFinished<FullAuthenticationJob>(job); });
} else {
......
......@@ -67,9 +67,7 @@ class KGAPICORE_EXPORT AuthJob : public KGAPI2::Job
* Sets the username that will be used when authenticate is called
*
* @param username username to use
* @deprecated
*/
QT_DEPRECATED_X("It's no longer possible to prefill username")
void setUsername(const QString &username);
/**
......
......@@ -56,7 +56,15 @@ public:
{
Q_ASSERT(mConnection);
const QByteArray data = mConnection->readLine();
mConnection->write("HTTP/1.1 200 OK\n");
const QString title = tr("Authentication successful");
const QString text = tr("You can close this tab and return to the application now.");
mConnection->write("HTTP/1.1 200 OK\n"
"Content-Type: text/html\n"
"\n"
"<!DOCTYPE><html>"
"<head><title>" + title.toUtf8() + "</title></head>"
"<body><h1>" + text.toUtf8() + "</h1></body>"
"</html>\n");
mConnection->flush();
mConnection->deleteLater();
qCDebug(KGAPIDebug) << "Got connection on socket";
......@@ -84,7 +92,6 @@ public:
return;
}
Q_ASSERT(mServerPort != -1);
auto fetch = new KGAPI2::NewTokensFetchJob(code, mApiKey, mSecretKey, mServerPort);
q->connect(fetch, &Job::finished, q, [this](Job *job) { tokensReceived(job); });
}
......@@ -131,6 +138,7 @@ public:
AccountPtr mAccount;
QString mApiKey;
QString mSecretKey;
QString mUsername;
std::unique_ptr<QTcpServer> mServer;
QTcpSocket *mConnection = nullptr;
......@@ -155,6 +163,11 @@ void FullAuthenticationJob::setServerPort(uint16_t port)
d->mServerPort = port;
}
void FullAuthenticationJob::setUsername(const QString &username)
{
d->mUsername = username;
}
AccountPtr FullAuthenticationJob::account() const
{
return d->mAccount;
......@@ -205,6 +218,9 @@ void FullAuthenticationJob::start()
query.addQueryItem(QStringLiteral("redirect_uri"), QStringLiteral("http://127.0.0.1:%1").arg(d->mServerPort));
query.addQueryItem(QStringLiteral("scope"), scopes.join(QLatin1Char(' ')));
query.addQueryItem(QStringLiteral("response_type"), QStringLiteral("code"));
if (!d->mUsername.isEmpty()) {
query.addQueryItem(QStringLiteral("login_hint"), d->mUsername);
}
url.setQuery(query);
QDesktopServices::openUrl(url);
......
......@@ -28,6 +28,8 @@ public:
/** For testing purposes only */
void setServerPort(uint16_t port);
void setUsername(const QString &username);
protected:
void handleReply(const QNetworkReply *reply, const QByteArray &rawData) override;
void dispatchRequest(QNetworkAccessManager *accessManager, const QNetworkRequest &request,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment