[gnome-online-accounts] exchange, lastfm, owncloud: Use goa_utils_get_credentials
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-online-accounts] exchange, lastfm, owncloud: Use goa_utils_get_credentials
- Date: Thu, 21 Jan 2016 14:12:02 +0000 (UTC)
commit 396ba4158b19233dbd0924adb45a319ba45fb642
Author: Christophe Fergeau <cfergeau redhat com>
Date: Thu Jan 21 13:21:06 2016 +0100
exchange, lastfm, owncloud: Use goa_utils_get_credentials
https://bugzilla.gnome.org/show_bug.cgi?id=755316
src/goabackend/goaexchangeprovider.c | 51 +++-----------------------------
src/goabackend/goalastfmprovider.c | 28 ++----------------
src/goabackend/goaowncloudprovider.c | 53 +++------------------------------
3 files changed, 13 insertions(+), 119 deletions(-)
---
diff --git a/src/goabackend/goaexchangeprovider.c b/src/goabackend/goaexchangeprovider.c
index 05c34b8..4ad96eb 100644
--- a/src/goabackend/goaexchangeprovider.c
+++ b/src/goabackend/goaexchangeprovider.c
@@ -267,7 +267,6 @@ ensure_credentials_sync (GoaProvider *provider,
GCancellable *cancellable,
GError **error)
{
- GVariant *credentials;
GoaAccount *account;
GoaEwsClient *ews_client;
GoaExchange *exchange;
@@ -275,20 +274,16 @@ ensure_credentials_sync (GoaProvider *provider,
gboolean ret;
const gchar *email_address;
const gchar *server;
- const gchar *username;
+ gchar *username;
gchar *password;
- credentials = NULL;
ews_client = NULL;
password = NULL;
+ username = NULL;
ret = FALSE;
- credentials = goa_utils_lookup_credentials_sync (provider,
- object,
- cancellable,
- error);
- if (credentials == NULL)
+ if (!goa_utils_get_credentials (provider, object, "password", &username, &password, cancellable, error))
{
if (error != NULL)
{
@@ -300,20 +295,6 @@ ensure_credentials_sync (GoaProvider *provider,
account = goa_object_peek_account (object);
email_address = goa_account_get_presentation_identity (account);
- username = goa_account_get_identity (account);
-
- if (!g_variant_lookup (credentials, "password", "s", &password))
- {
- if (error != NULL)
- {
- *error = g_error_new (GOA_ERROR,
- GOA_ERROR_NOT_AUTHORIZED,
- _("Did not find password with identity ‘%s’ in credentials"),
- username);
- }
- goto out;
- }
-
exchange = goa_object_peek_exchange (object);
accept_ssl_errors = goa_exchange_get_accept_ssl_errors (exchange);
server = goa_exchange_get_host (exchange);
@@ -352,9 +333,8 @@ ensure_credentials_sync (GoaProvider *provider,
out:
if (ews_client != NULL)
g_object_unref (ews_client);
+ g_free (username);
g_free (password);
- if (credentials != NULL)
- g_variant_unref (credentials);
return ret;
}
@@ -952,9 +932,7 @@ on_handle_get_password (GoaPasswordBased *interface,
GoaAccount *account;
GoaProvider *provider;
GError *error;
- GVariant *credentials;
const gchar *account_id;
- const gchar *identity;
const gchar *method_name;
const gchar *provider_type;
gchar *password;
@@ -962,12 +940,9 @@ on_handle_get_password (GoaPasswordBased *interface,
/* TODO: maybe log what app is requesting access */
password = NULL;
- credentials = NULL;
object = GOA_OBJECT (g_dbus_interface_get_object (G_DBUS_INTERFACE (interface)));
account = goa_object_peek_account (object);
- identity = goa_account_get_identity (account);
-
account_id = goa_account_get_id (account);
provider_type = goa_account_get_provider_type (account);
method_name = g_dbus_method_invocation_get_method_name (invocation);
@@ -976,32 +951,16 @@ on_handle_get_password (GoaPasswordBased *interface,
provider = goa_provider_get_for_provider_type (provider_type);
error = NULL;
- credentials = goa_utils_lookup_credentials_sync (provider,
- object,
- NULL, /* GCancellable* */
- &error);
- if (credentials == NULL)
+ if (!goa_utils_get_credentials (provider, object, "password", NULL, &password, NULL, &error))
{
g_dbus_method_invocation_take_error (invocation, error);
goto out;
}
- if (!g_variant_lookup (credentials, "password", "s", &password))
- {
- g_dbus_method_invocation_return_error (invocation,
- GOA_ERROR,
- GOA_ERROR_FAILED, /* TODO: more specific */
- _("Did not find password with identity ‘%s’ in credentials"),
- identity);
- goto out;
- }
-
goa_password_based_complete_get_password (interface, invocation, password);
out:
g_free (password);
- if (credentials != NULL)
- g_variant_unref (credentials);
g_object_unref (provider);
return TRUE; /* invocation was handled */
}
diff --git a/src/goabackend/goalastfmprovider.c b/src/goabackend/goalastfmprovider.c
index 852c9a2..7ad5bae 100644
--- a/src/goabackend/goalastfmprovider.c
+++ b/src/goabackend/goalastfmprovider.c
@@ -254,17 +254,11 @@ ensure_credentials_sync (GoaProvider *provider,
GCancellable *cancellable,
GError **error)
{
- GVariant *credentials;
- GoaAccount *account;
- const gchar *username;
+ gchar *username = NULL;
gchar *password = NULL;
gboolean ret = FALSE;
- credentials = goa_utils_lookup_credentials_sync (provider,
- object,
- cancellable,
- error);
- if (credentials == NULL)
+ if (!goa_utils_get_credentials (provider, object, "password", &username, &password, cancellable, error))
{
if (error != NULL)
{
@@ -274,21 +268,6 @@ ensure_credentials_sync (GoaProvider *provider,
goto out;
}
- account = goa_object_peek_account (object);
- username = goa_account_get_identity (account);
-
- if (!g_variant_lookup (credentials, "password", "s", &password))
- {
- if (error != NULL)
- {
- *error = g_error_new (GOA_ERROR,
- GOA_ERROR_NOT_AUTHORIZED,
- _("Did not find password with identity ‘%s’ in credentials"),
- username);
- }
- goto out;
- }
-
ret = lastfm_login_sync (provider, username, password, error);
if (!ret)
{
@@ -313,9 +292,8 @@ ensure_credentials_sync (GoaProvider *provider,
*out_expires_in = 0;
out:
+ g_free (username);
g_free (password);
- if (credentials != NULL)
- g_variant_unref (credentials);
return ret;
}
diff --git a/src/goabackend/goaowncloudprovider.c b/src/goabackend/goaowncloudprovider.c
index 2eeb09b..18d57ff 100644
--- a/src/goabackend/goaowncloudprovider.c
+++ b/src/goabackend/goaowncloudprovider.c
@@ -343,29 +343,23 @@ ensure_credentials_sync (GoaProvider *provider,
GCancellable *cancellable,
GError **error)
{
- GVariant *credentials;
- GoaAccount *account;
GoaHttpClient *http_client;
gboolean accept_ssl_errors;
gboolean ret;
- const gchar *username;
+ gchar *username;
gchar *password;
gchar *uri;
gchar *uri_webdav;
- credentials = NULL;
http_client = NULL;
password = NULL;
uri = NULL;
uri_webdav = NULL;
+ username = NULL;
ret = FALSE;
- credentials = goa_utils_lookup_credentials_sync (provider,
- object,
- cancellable,
- error);
- if (credentials == NULL)
+ if (!goa_utils_get_credentials (provider, object, "password", &username, &password, cancellable, error))
{
if (error != NULL)
{
@@ -379,21 +373,6 @@ ensure_credentials_sync (GoaProvider *provider,
uri = goa_util_lookup_keyfile_string (object, "Uri");
uri_webdav = g_strconcat (uri, WEBDAV_ENDPOINT, NULL);
- account = goa_object_peek_account (object);
- username = goa_account_get_identity (account);
-
- if (!g_variant_lookup (credentials, "password", "s", &password))
- {
- if (error != NULL)
- {
- *error = g_error_new (GOA_ERROR,
- GOA_ERROR_NOT_AUTHORIZED,
- _("Did not find password with identity ‘%s’ in credentials"),
- username);
- }
- goto out;
- }
-
http_client = goa_http_client_new ();
ret = goa_http_client_check_sync (http_client,
uri_webdav,
@@ -426,11 +405,10 @@ ensure_credentials_sync (GoaProvider *provider,
out:
g_clear_object (&http_client);
+ g_free (username);
g_free (password);
g_free (uri);
g_free (uri_webdav);
- if (credentials != NULL)
- g_variant_unref (credentials);
return ret;
}
@@ -1103,9 +1081,7 @@ on_handle_get_password (GoaPasswordBased *interface,
GoaAccount *account;
GoaProvider *provider;
GError *error;
- GVariant *credentials;
const gchar *account_id;
- const gchar *identity;
const gchar *method_name;
const gchar *provider_type;
gchar *password;
@@ -1113,12 +1089,9 @@ on_handle_get_password (GoaPasswordBased *interface,
/* TODO: maybe log what app is requesting access */
password = NULL;
- credentials = NULL;
object = GOA_OBJECT (g_dbus_interface_get_object (G_DBUS_INTERFACE (interface)));
account = goa_object_peek_account (object);
- identity = goa_account_get_identity (account);
-
account_id = goa_account_get_id (account);
provider_type = goa_account_get_provider_type (account);
method_name = g_dbus_method_invocation_get_method_name (invocation);
@@ -1127,32 +1100,16 @@ on_handle_get_password (GoaPasswordBased *interface,
provider = goa_provider_get_for_provider_type (provider_type);
error = NULL;
- credentials = goa_utils_lookup_credentials_sync (provider,
- object,
- NULL, /* GCancellable* */
- &error);
- if (credentials == NULL)
+ if (!goa_utils_get_credentials (provider, object, "password", NULL, &password, NULL, &error))
{
g_dbus_method_invocation_take_error (invocation, error);
goto out;
}
- if (!g_variant_lookup (credentials, "password", "s", &password))
- {
- g_dbus_method_invocation_return_error (invocation,
- GOA_ERROR,
- GOA_ERROR_FAILED, /* TODO: more specific */
- _("Did not find password with identity ‘%s’ in credentials"),
- identity);
- goto out;
- }
-
goa_password_based_complete_get_password (interface, invocation, password);
out:
g_free (password);
- if (credentials != NULL)
- g_variant_unref (credentials);
g_object_unref (provider);
return TRUE; /* invocation was handled */
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]