diff --git a/src/lib/getcredentialsjob.h b/src/lib/getcredentialsjob.h --- a/src/lib/getcredentialsjob.h +++ b/src/lib/getcredentialsjob.h @@ -60,6 +60,26 @@ GetCredentialsJob(const Accounts::AccountId &id, const QString &authMethod = QString(), const QString &authMechanism = QString(), QObject *parent = 0); /** + * This version of the constructor allow passing specific auth method and mechanism + * for which we want the credentials as well as additional custom parameters for the + * authentication. + * + * For example some account has OAuth token and username-password credentials, + * by setting both method and mechanism to "password", only the password will be + * retrieved. Otherwise it depends on the passed serviceType - if there's no serviceType + * set, it will use the default service for the given AccountId and will obtain + * the credentials needed for that service + * + * @param id AccountId for which the credentials will be obtained + * @param authMethod Auth method for which the credentials will be obtained + * @param authMechanism Auth mechanism for which the credentials will be obtained + * @param parameters Dictionary with additional parameters to be passed to the authentication + * service. + */ + GetCredentialsJob(const Accounts::AccountId &id, const QString &authMethod = QString(), const QString &authMechanism = QString(), + const QVariantMap ¶meters = QVariantMap(), QObject *parent = 0); + + /** * Starts the credentials job */ virtual void start(); diff --git a/src/lib/getcredentialsjob.cpp b/src/lib/getcredentialsjob.cpp --- a/src/lib/getcredentialsjob.cpp +++ b/src/lib/getcredentialsjob.cpp @@ -70,7 +70,7 @@ Accounts::AccountService *service = new Accounts::AccountService(acc, manager->service(serviceType), q); Accounts::AuthData serviceAuthData = service->authData(); - authData = serviceAuthData.parameters(); + authData.unite(serviceAuthData.parameters()); SignOn::Identity *identity = SignOn::Identity::existingIdentity(acc->credentialsId(), q); if (!identity) { @@ -81,7 +81,9 @@ return; } - authData["AccountUsername"] = acc->value(QLatin1String("username")).toString(); + if (!authData.contains("AccountUsername")) { + authData["AccountUsername"] = acc->value(QLatin1String("username")).toString(); + } QPointer authSession = identity->createSession(authMethod.isEmpty() ? serviceAuthData.method() : authMethod); if (!authSession) { qWarning() << "Unable to create auth session for" << authMethod << serviceAuthData.method(); @@ -105,7 +107,7 @@ q->emitResult(); }); - authSession->process(serviceAuthData.parameters(), authMechanism.isEmpty() ? serviceAuthData.mechanism() : authMechanism); + authSession->process(authData, authMechanism.isEmpty() ? serviceAuthData.mechanism() : authMechanism); } GetCredentialsJob::GetCredentialsJob(const Accounts::AccountId &id, QObject *parent) @@ -131,6 +133,20 @@ d->serviceType = QString(); } +GetCredentialsJob::GetCredentialsJob(const Accounts::AccountId &id, const QString &authMethod, const QString &authMechanism, + const QVariantMap ¶meters, QObject *parent) + : KJob(parent) + , d(new Private(this)) +{ + d->id = id; + d->manager = KAccounts::accountsManager(); + d->authMechanism = authMechanism; + d->authMethod = authMethod; + d->repeatedTries = 0; + d->serviceType = QString(); + d->authData = parameters; +} + void GetCredentialsJob::start() { QMetaObject::invokeMethod(this, "getCredentials", Qt::QueuedConnection);