From 9c60bc8ce4a0990c228d2cd746791b88c41532b8 Mon Sep 17 00:00:00 2001 From: ConfuSomu Date: Thu, 24 Aug 2023 18:43:15 -0400 Subject: Implement basic Mastodon API support Implement support for OAuth 2.0 code entry, which is then used to retrieve a token that is stored in the application's settings. Authentification allowed the implementation of a basic "get post from URL" feature mostly made for testing. --- src/settingsdialog.cpp | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) (limited to 'src/settingsdialog.cpp') diff --git a/src/settingsdialog.cpp b/src/settingsdialog.cpp index 213859a..051091f 100644 --- a/src/settingsdialog.cpp +++ b/src/settingsdialog.cpp @@ -1,6 +1,14 @@ #include "settingsdialog.h" +#include "src/net/instance.h" +#include "src/settings_interface.h" + #include #include +#include +#include +#include +#include +#include SettingsDialog::SettingsDialog(QWidget* parent) : QDialog(parent, Qt::Dialog), ui(new Ui::SettingsDialog) @@ -64,7 +72,24 @@ void SettingsDialog::on_instanceActionsLabel_linkActivated(const QString& link) ui->instanceAddressLineEdit->setText(instance_address); update_ui_in_progress = false; } else if (link == "action:request-token") { - // TODO: open browser with token request URL + Instance* instance = Instance::create_instance((AppSettingsTypes::InstanceType)ui->instanceTypeComboBox->currentIndex()); + + QString url = instance->oauth2_step1(); + if (not QDesktopServices::openUrl(url)) + QMessageBox::information(this, tr("Navigate to this URL"), tr("Please open the following URL in your browser: %1").arg(1)); + + Instance::OAuth2Step2 step2 = {.ok = false}; + while (not step2.ok) { + bool ok; + QString code = QInputDialog::getText(this, tr("Enter authorization code"), tr("Enter the code given during the authentification flow:"), QLineEdit::Normal, "", &ok); + + if (code.isEmpty()) return; // User canceled + if (ok) step2 = instance->oauth2_step2(code); + } + + // Do not set update_ui_in_progress as we want the new text to be seen as new text by settings_interface (through on_tokenLineEdit_editingFinished()) + ui->tokenLineEdit->setText(step2.token); + on_tokenLineEdit_editingFinished(); // Make sure that the change has been noticed as sometimes it isn't } } -- cgit v1.2.3-54-g00ecf