Commit eaf76c26 authored by Thomas Perl's avatar Thomas Perl

Merge pull request #26 from kananoja/store_credentials_api

[ssu] Expose new dbus API for updating the store credentials.
parents 4b4afe97 38a30520
...@@ -88,6 +88,10 @@ ...@@ -88,6 +88,10 @@
</method> </method>
<method name="updateRepos"> <method name="updateRepos">
</method> </method>
<method name="updateStoreCredentials">
<arg direction="in" type="s" name="userName" />
<arg direction="in" type="s" name="accessToken" />
</method>
<method name="error"> <method name="error">
<arg direction="out" type="b" name="status"/> <arg direction="out" type="b" name="status"/>
......
...@@ -609,23 +609,13 @@ void Ssu::updateCredentials(bool force){ ...@@ -609,23 +609,13 @@ void Ssu::updateCredentials(bool force){
manager->get(request); manager->get(request);
} }
void Ssu::updateStoreCredentials(){ void Ssu::updateStoreCredentials(const QString &userName, const QString &accessToken){
QDBusMessage message = QDBusMessage::createMethodCall("com.jolla.jollastore",
"/StoreClient",
"com.jolla.jollastore",
"storeCredentials");
QDBusPendingReply<QString, QString> reply = QDBusConnection::sessionBus().asyncCall(message);
reply.waitForFinished();
if (reply.isError()) {
setError(QString("Store credentials not received. %1").arg(reply.error().message()));
} else {
SsuCoreConfig *settings = SsuCoreConfig::instance(); SsuCoreConfig *settings = SsuCoreConfig::instance();
settings->beginGroup("credentials-store"); settings->beginGroup("credentials-store");
settings->setValue("username", reply.argumentAt<0>()); settings->setValue("username", userName);
settings->setValue("password", reply.argumentAt<1>()); settings->setValue("password", accessToken);
settings->endGroup(); settings->endGroup();
settings->sync(); settings->sync();
}
} }
void Ssu::unregister(){ void Ssu::unregister(){
......
...@@ -180,7 +180,7 @@ class Ssu: public QObject { ...@@ -180,7 +180,7 @@ class Ssu: public QObject {
/** /**
* Try to update credentials for (Jolla) store * Try to update credentials for (Jolla) store
*/ */
void updateStoreCredentials(); void updateStoreCredentials(const QString &userName, const QString &accessToken);
signals: signals:
/** /**
......
...@@ -194,3 +194,8 @@ void Ssud::updateRepos(){ ...@@ -194,3 +194,8 @@ void Ssud::updateRepos(){
repoManager.update(); repoManager.update();
autoclose.start(); autoclose.start();
} }
void Ssud::updateStoreCredentials(const QString &userName, const QString &accessToken){
ssu.updateStoreCredentials(userName, accessToken);
autoclose.start();
}
...@@ -42,6 +42,7 @@ class Ssud: public QObject { ...@@ -42,6 +42,7 @@ class Ssud: public QObject {
void modifyRepo(int action, const QString &repo); void modifyRepo(int action, const QString &repo);
void addRepo(const QString &repo, const QString &url); void addRepo(const QString &repo, const QString &url);
void updateRepos(); void updateRepos();
void updateStoreCredentials(const QString &userName, const QString &accessToken);
bool error(); bool error();
QString lastError(); QString lastError();
......
...@@ -139,11 +139,12 @@ void SsuUrlResolver::run(){ ...@@ -139,11 +139,12 @@ void SsuUrlResolver::run(){
// store-auth-repos domain setting use store credentials. Refresh // store-auth-repos domain setting use store credentials. Refresh
// here, as we only know after checking scope if we need to have // here, as we only know after checking scope if we need to have
// store credentials at all // store credentials at all
if (credentialsScope == "store"){
ssu.updateStoreCredentials(); // store-client updates the store credentials via dbus call on
if (ssu.error()) // every startup (or sign in to be precise).
error (ssu.lastError()); // TODO: Is there need to check that the credentials were really
} // set by store-client?
headerList.append(QString("credentials=%1").arg(credentialsScope)); headerList.append(QString("credentials=%1").arg(credentialsScope));
writeZyppCredentialsIfNeeded(credentialsScope); writeZyppCredentialsIfNeeded(credentialsScope);
} else } else
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment