update oidc client secret auth

This commit is contained in:
Jehan Monnier 2025-05-26 13:07:02 +02:00 committed by Gaelle Braud
parent 3240f0f757
commit 12dfd2403f

View file

@ -75,10 +75,19 @@ OIDCModel::OIDCModel(const std::shared_ptr<linphone::AuthInfo> &authInfo, QObjec
lInfo() << "OIDC Client ID set to [" << clientid << "]"; lInfo() << "OIDC Client ID set to [" << clientid << "]";
// find an auth info from LinphoneCore where username = clientid // find an auth info from LinphoneCore where username = clientid
auto clientSecret = CoreModel::getInstance()->getCore()->findAuthInfo("", clientid.toStdString(), ""); std::shared_ptr<linphone::AuthInfo> 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) { if (clientSecret != nullptr) {
lInfo() << "client secret found for client id [" << clientid << "]"; lInfo() << "client secret found for client id [" << clientid << "]";
mOidc.setClientIdentifierSharedKey(clientSecret->getPassword().c_str()); mOidc.setClientIdentifierSharedKey(clientSecret->getClientSecret().c_str());
} }
QSet<QByteArray> scopeTokens; QSet<QByteArray> scopeTokens;
@ -223,7 +232,8 @@ OIDCModel::OIDCModel(const std::shared_ptr<linphone::AuthInfo> &authInfo, QObjec
// for (auto it = tokens.cbegin(); it != tokens.cend(); ++it) { // for (auto it = tokens.cbegin(); it != tokens.cend(); ++it) {
// qDebug() << "Token key:" << it.key() << ", value:" << it.value().toString(); // 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(); auto idToken = tokens["id_token"].toString();
qDebug() << "ID Token received:" << idToken.left(3) + "..." + idToken.right(3); qDebug() << "ID Token received:" << idToken.left(3) + "..." + idToken.right(3);
mIdToken = idToken; mIdToken = idToken;
@ -368,7 +378,15 @@ void OIDCModel::setBearers() {
} }
QString OIDCModel::idToken() const { QString OIDCModel::idToken() const {
#if QT_VERSION >= QT_VERSION_CHECK(6, 9, 0) #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 #else
return mIdToken; return mIdToken;
#endif #endif