UBports Robot Logo UBports Forum
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Register
    • Login

    Online Account acces from QT Console Application

    Scheduled Pinned Locked Moved App Development
    2 Posts 1 Posters 289 Views 1 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
      Reply
      • Reply as topic
      Log in to reply
      This topic has been deleted. Only users with topic management privileges can see it.
      • B Offline
        belohoub
        last edited by

        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!

        1 Reply Last reply Reply Quote 0
        • B Offline
          belohoub
          last edited by belohoub

          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()";
          }
          
          1 Reply Last reply Reply Quote 0
          • First post
            Last post