Online Account acces from QT Console Application
-
I'm currently working on the redesign of the Ubsync app to bring multi-user support and improve the application architecture. The QML part is almost done, however, an important subtask is to remove plain passwords from the config file. The current version of the application stores the username/password to the config file to provide it to the backend (online accounts are only implemented in QML), however, this is not a very good approach.
I was able to access account details using libaccounts-qt5, but I'm stuck with authentication with signond to get username/password.
I'm not very experienced in QT and my knowledge about signond is limited (causing great confusion even I tried to learn from the poor docs and accounts-qml-module code
).Working code snippet is below:
#include <Accounts/Account> #include <Accounts/Application> #include <Accounts/Manager> #include <Accounts/AccountService> ... #include <SignOn/AuthSession> #include <SignOn/Identity> ... Accounts::Manager *manager = new Accounts::Manager(); Accounts::Account * account = manager->account(accountID); qDebug() << " - Account: " << account->displayName(); qDebug() << " - Keys: " << account->allKeys(); qDebug() << " - Host: " << account->value("host"); qDebug() << " - CredentialsId: " << account->value("CredentialsId"); qDebug() << " - enabled: " << account->value("enabled"); qDebug() << " - name: " << account->value("name"); qDebug() << " - auth/method: " << account->value("auth/method"); qDebug() << " - auth/mechanism: " << account->value("auth/mechanism"); qDebug() << " - ChildKeys: " << account->childKeys(); Accounts::ServiceList services = account->enabledServices(); foreach (Accounts::Service service, services) { qDebug() << " - Service: " << service.displayName(); if (QString::compare(service.displayName(), "Owncloud", Qt::CaseInsensitive)) { qDebug() << " -> owncloud "; Accounts::AccountService * as = new Accounts::AccountService(account, service); Accounts::AuthData ad = as->authData(); qDebug() << " -> authData " << ad.parameters().keys(); qDebug() << " -> cID " << ad.credentialsId(); qDebug() << " -> DOM: " << service.domDocument().toString(); // TODO - get username and password from libsignond using ad.credentialsId() } else if (QString::compare(service.displayName(), "Nextcloud", Qt::CaseInsensitive)) { qDebug() << " -> nextcloud "; // TODO } }Could anyone provide a minimal example to access password using libsignon-qt5?
Thank you! -
I found some time for further study, so I have the minimal working example, as I requested several days ago:
..... if (QString::compare(service.displayName(), "Owncloud", Qt::CaseInsensitive)) { // Initialize SignOn QPointer<SignOn::AuthSession> authSession; SignOn::IdentityInfo identityInfo; identityInfo.setId(ad.credentialsId()); SignOn::Identity * identity = SignOn::Identity::newIdentity(identityInfo); authSession = identity->createSession(ad.method()); SignOn::SessionData sessionData(ad.parameters()); // connect response and error signals connect(authSession, SIGNAL(response(SignOn::SessionData)), SLOT(signOnResponse(SignOn::SessionData))); connect(authSession, SIGNAL(error(SignOn::Error)), SLOT(signOnError(SignOn::Error))); // request secret and wait for response signal authSession->request(sessionData, ad.method()); } ..... /** * @brief Accounts reponse * */ void OwncloudSyncd::signOnResponse(const SignOn::SessionData &sessionData) { qDebug() << "Online Accounts response()"; qDebug() << " -> login: " << sessionData.UserName(); qDebug() << " -> password: " << sessionData.Secret(); } /** * @brief Accounts reponse * */ void OwncloudSyncd::signOnError(const SignOn::Error &error) { qDebug() << "Online Accounts response()"; }
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login