void Session::establish(int credentialsId) { m_identity = SignOn::Identity::existingIdentity(credentialsId, this); // TODO: if (!m_identity) { SignOn::IdentityInfo info; info.setCaption("Evernote"); info.setMethod("evernote", QStringList() << "AuthLogin"); m_identity = SignOn::Identity::newIdentity(info, this); } m_session = m_identity->createSession("evernote"); qDebug() << Q_FUNC_INFO << m_identity << credentialsId << m_session; connect(m_session, SIGNAL(error(SignOn::Error)), this, SLOT(onError(SignOn::Error))); connect(m_session, SIGNAL(response(SignOn::SessionData)), this, SLOT(onResponse(SignOn::SessionData))); connect(m_session, SIGNAL(stateChanged(AuthSession::AuthSessionState,QString)), this, SLOT(onStateChanged(AuthSession::AuthSessionState,QString))); m_session->process(SignOn::SessionData(), "AuthLogin"); }
void CreateAccount::pluginFinished(const QString &screenName, const QString &secret, const QVariantMap &data) { // Set up the new identity SignOn::IdentityInfo info; info.setStoreSecret(true); info.setUserName(screenName); info.setSecret(secret, true); info.setCaption(m_providerName); info.setAccessControlList(QStringList(QLatin1String("*"))); info.setType(SignOn::IdentityInfo::Application); Q_FOREACH (const QString &key, data.keys()) { // If a key with __service/ prefix exists and its value is false, // add it to m_disabledServices which will later be used for disabling // the services contained in that list if (key.startsWith(QLatin1String("__service/")) && !data.value(key).toBool()) { m_disabledServices << key.mid(10); } m_account->setValue(key, data.value(key).toString()); } m_identity = SignOn::Identity::newIdentity(info, this); connect(m_identity, SIGNAL(info(SignOn::IdentityInfo)), SLOT(info(SignOn::IdentityInfo))); m_done = true; connect(m_identity, &SignOn::Identity::credentialsStored, m_identity, &SignOn::Identity::queryInfo); m_identity->storeCredentials(); }
void CreateAccount::processSession() { m_account = m_manager->createAccount(m_providerName); Accounts::Service service; if (m_account->services().size() == 1) { service = m_account->services().at(0); } m_accInfo = new Accounts::AccountService(m_account, service, this); const QString pluginName = m_account->provider().pluginName(); qDebug() << "Looking for plugin" << pluginName; if (!pluginName.isEmpty()) { loadPluginAndShowDialog(pluginName); } else { SignOn::IdentityInfo info; info.setCaption(m_providerName); info.setAccessControlList(QStringList("*")); info.setType(SignOn::IdentityInfo::Application); info.setStoreSecret(true); m_identity = SignOn::Identity::newIdentity(info, this); m_identity->storeCredentials(); connect(m_identity, SIGNAL(info(SignOn::IdentityInfo)), SLOT(info(SignOn::IdentityInfo))); connect(m_identity, &SignOn::Identity::error, [=](const SignOn::Error &err) { qDebug() << "Error storing identity:" << err.message(); }); QVariantMap data = m_accInfo->authData().parameters(); data.insert("Embedded", false); SignOn::SessionData sessionData(data); SignOn::AuthSessionP session = m_identity->createSession(m_accInfo->authData().method()); qDebug() << "Starting auth session with" << m_accInfo->authData().method(); connect(session, SIGNAL(error(SignOn::Error)), SLOT(sessionError(SignOn::Error))); connect(session, SIGNAL(response(SignOn::SessionData)), SLOT(sessionResponse(SignOn::SessionData))); session->process(sessionData, m_accInfo->authData().mechanism()); } }
void CreateAccount::info(const SignOn::IdentityInfo &info) { qDebug() << "Info:"; qDebug() << "\tId:" << info.id(); qDebug() << "\tcaption:" << info.caption(); qDebug() << "\towner:" << info.owner(); qDebug() << "\tuserName:"******"username", info.userName()); m_account->setCredentialsId(info.id()); Accounts::AuthData authData = m_accInfo->authData(); m_account->setValue("auth/mechanism", authData.mechanism()); m_account->setValue("auth/method", authData.method()); QString base("auth/"); base.append(authData.method()); base.append("/"); base.append(authData.mechanism()); base.append("/"); QVariantMap data = authData.parameters(); QMapIterator<QString, QVariant> i(data); while (i.hasNext()) { i.next(); m_account->setValue(base + i.key(), i.value()); } Accounts::ServiceList services = m_account->services(); Q_FOREACH(const Accounts::Service &service, services) { m_account->selectService(service); m_account->setEnabled(m_disabledServices.contains(service.name()) ? false : true); }