diff --git a/Linphone/core/App.cpp b/Linphone/core/App.cpp index fcc5d033f..a731911ec 100644 --- a/Linphone/core/App.cpp +++ b/Linphone/core/App.cpp @@ -338,6 +338,9 @@ App::App(int &argc, char *argv[]) mEventCountNotifier = new EventCountNotifier(this); mDateUpdateTimer.start(); + mOIDCRefreshTimer.setInterval(1000); + mOIDCRefreshTimer.setSingleShot(false); + #ifdef Q_OS_LINUX exportDesktopFile(); #endif diff --git a/Linphone/model/auth/OIDCModel.cpp b/Linphone/model/auth/OIDCModel.cpp index aff4858c0..48b0c23aa 100644 --- a/Linphone/model/auth/OIDCModel.cpp +++ b/Linphone/model/auth/OIDCModel.cpp @@ -305,8 +305,16 @@ void OIDCModel::stopTimeoutTimer() { void OIDCModel::openIdConfigReceived() { auto reply = dynamic_cast(sender()); - auto document = QJsonDocument::fromJson(reply->readAll()); - if (document.isNull()) return; + auto replyArray = reply->readAll(); + lInfo() << log().arg("Reply :") << replyArray; + auto document = QJsonDocument::fromJson(replyArray); + if (document.isNull()) { + lWarning() << log().arg("Reply is empty"); + //: OIDC reply is empty ! + emit requestFailed(tr("oidc_authentication_empty_reply_error")); + emit finished(); + return; + } auto rootArray = document.toVariant().toMap(); if (rootArray.contains("authorization_endpoint")) { mOidc.setAuthorizationUrl(QUrl(rootArray["authorization_endpoint"].toString())); diff --git a/Linphone/model/core/CoreModel.cpp b/Linphone/model/core/CoreModel.cpp index 54dd1b039..7900406b9 100644 --- a/Linphone/model/core/CoreModel.cpp +++ b/Linphone/model/core/CoreModel.cpp @@ -59,6 +59,10 @@ CoreModel::CoreModel(const QString &configPath, QThread *parent) } CoreModel::~CoreModel() { + for (auto &oidc : mOpenIdConnections) { + oidc->deleteLater(); + } + mOpenIdConnections.clear(); } std::shared_ptr CoreModel::create(const QString &configPath, QThread *parent) { @@ -417,7 +421,7 @@ void CoreModel::onAuthenticationRequested(const std::shared_ptr qDebug() << "onAuthenticationRequested for Bearer. Initialize OpenID connection for " << username << "@" << realm << " at " << serverUrl; QString key = username + '@' + realm + ' ' + serverUrl; - if (mOpenIdConnections.contains(key)) mOpenIdConnections[key]->deleteLater(); + // if (mOpenIdConnections.contains(key)) mOpenIdConnections[key]->deleteLater(); auto oidcModel = new OIDCModel(authInfo, this); mOpenIdConnections[key] = oidcModel; connect(oidcModel, &OIDCModel::timeoutTimerStarted, this, [this] { @@ -425,6 +429,16 @@ void CoreModel::onAuthenticationRequested(const std::shared_ptr emit timeoutTimerStarted(); qDebug() << "start refresh timer"; }); + connect(oidcModel, &OIDCModel::requestFailed, this, [this, oidcModel](const QString &error) { + mustBeInLinphoneThread(log().arg(Q_FUNC_INFO)); + lWarning() << log().arg("Request failed") << error; + emit oidcRequestFailed(error); + oidcModel->forceTimeout(); + }); + connect(oidcModel, &OIDCModel::finished, this, [this, oidcModel] { + mustBeInLinphoneThread(log().arg(Q_FUNC_INFO)); + lInfo() << log().arg("Request finished"); + }); if (oidcModel->isTimerRunning()) { emit timeoutTimerStarted(); } @@ -660,4 +674,4 @@ void CoreModel::onAudioDevicesListUpdated(const std::shared_ptr void CoreModel::onAudioDeviceChanged(const std::shared_ptr &core, const std::shared_ptr &device) { emit audioDeviceChanged(core, device); -} \ No newline at end of file +} diff --git a/Linphone/model/core/CoreModel.hpp b/Linphone/model/core/CoreModel.hpp index 8170da951..33f2392fa 100644 --- a/Linphone/model/core/CoreModel.hpp +++ b/Linphone/model/core/CoreModel.hpp @@ -103,6 +103,7 @@ signals: void forceOidcTimeout(); void timeoutTimerStarted(); void timeoutTimerStopped(); + void oidcRequestFailed(QString error); private: QString mConfigPath;