From 9b999bcc09823d45a7a1dd969091095e6649be68 Mon Sep 17 00:00:00 2001 From: Jehan Monnier Date: Mon, 26 May 2025 13:07:02 +0200 Subject: [PATCH] update oidc client secret auth --- Linphone/model/auth/OIDCModel.cpp | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/Linphone/model/auth/OIDCModel.cpp b/Linphone/model/auth/OIDCModel.cpp index 383b6b4e6..aff4858c0 100644 --- a/Linphone/model/auth/OIDCModel.cpp +++ b/Linphone/model/auth/OIDCModel.cpp @@ -72,13 +72,22 @@ OIDCModel::OIDCModel(const std::shared_ptr &authInfo, QObjec } mOidc.setClientIdentifier(clientid); mAuthInfo->setClientId(clientid.toStdString()); - qDebug() << "OIDC Client ID set to [" << clientid << "]"; + lInfo() << "OIDC Client ID set to [" << clientid << "]"; // find an auth info from LinphoneCore where username = clientid - auto clientSecret = CoreModel::getInstance()->getCore()->findAuthInfo("", clientid.toStdString(), ""); + std::shared_ptr clientSecret = nullptr; + // search for auth info for this client id + for (const auto &authInfo : CoreModel::getInstance()->getCore()->getAuthInfoList()) { + if (authInfo->getClientId() == clientid.toStdString()) { + lInfo() << "AuthInfo found for client id [" << clientid << "]"; + clientSecret = authInfo; + break; + } + } + if (clientSecret != nullptr) { - qDebug() << "client secret found for client id [" << clientid << "]"; - mOidc.setClientIdentifierSharedKey(clientSecret->getPassword().c_str()); + lInfo() << "client secret found for client id [" << clientid << "]"; + mOidc.setClientIdentifierSharedKey(clientSecret->getClientSecret().c_str()); } QSet scopeTokens; @@ -214,7 +223,8 @@ OIDCModel::OIDCModel(const std::shared_ptr &authInfo, QObjec // for (auto it = tokens.cbegin(); it != tokens.cend(); ++it) { // qDebug() << "Token key:" << it.key() << ", value:" << it.value().toString(); // } - if (tokens.contains("id_token")) { + if (tokens.contains("id_token") && + CoreModel::getInstance()->getCore()->getConfig()->getBool("app", "oidc_use_id_token", false)) { auto idToken = tokens["id_token"].toString(); qDebug() << "ID Token received:" << idToken.left(3) + "..." + idToken.right(3); mIdToken = idToken; @@ -349,7 +359,15 @@ void OIDCModel::setBearers() { } QString OIDCModel::idToken() const { #if QT_VERSION >= QT_VERSION_CHECK(6, 9, 0) - return mOidc.idToken().isEmpty() ? mOidc.token() : mOidc.idToken(); + if (CoreModel::getInstance()->getCore()->getConfig()->getBool("app", "oidc_use_id_token", false)) { + if (!mOidc.idToken().isEmpty()) { + return mOidc.idToken(); + } else { + return mOidc.token(); + } + } else { + return mOidc.token(); + } #else return mIdToken; #endif