Skip to content
Snippets Groups Projects
Commit 8ba00fd9 authored by Nicolas Werner's avatar Nicolas Werner
Browse files

Add .well-known support

parent 25034aca
No related branches found
No related tags found
No related merge requests found
......@@ -5,6 +5,7 @@
#include <mtx/identifiers.hpp>
#include "client.h"
#include "debug_out.h"
#include "settings.h"
Login::Login(QObject *parent) : QObject(parent) {}
......@@ -41,7 +42,31 @@ void Login::mxidEntered(QString mxid) {
}
QString server = QString::fromStdString(user.hostname());
this->validateServer(server);
http::client().well_known([this, server](const mtx::responses::WellKnown &well_known, mtx::http::RequestErr err) {
if (err) {
using namespace boost::beast::http;
if (err->status_code == status::not_found) {
qDebug() << "Autodiscovery: No .well-known.";
this->validateServer(server);
return;
}
if (!err->parse_error.empty()) {
emit homeserverInvalid(server, tr("Autodiscovery failed. Received malformed response."));
qDebug() << "Autodiscovery failed. Received malformed response." << *err;
return;
}
emit homeserverInvalid(server, tr("Autodiscovery failed. Unknown error when requesting .well-known."));
qDebug() << "Autodiscovery failed. Unknown error when requesting .weel-known.";
return;
}
qDebug() << "Autodiscovery: Discovered '" << QString::fromStdString(well_known.homeserver.base_url) << "'";
this->validateServer(QString::fromStdString(well_known.homeserver.base_url));
});
}
void Login::homeserverEntered(QString server) { this->validateServer(server); }
......@@ -122,11 +147,17 @@ void Login::login(QString mxid, QString password, QString server) {
qDebug() << "Access token:" << QString::fromStdString(response.access_token)
<< " , device: " << QString::fromStdString(response.device_id);
if (response.well_known) {
qDebug() << "Login response requested to migrate to: "
<< QString::fromStdString(response.well_known->homeserver.base_url);
http::client().set_server(response.well_known->homeserver.base_url);
}
Settings s;
s.access_token(response.access_token);
s.device_id(response.device_id);
s.user(response.user_id);
s.server(homeserver);
s.server(http::client().server());
s.server_port(http::client().port());
emit loginSuccess();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment