[evolution-data-server] google-backend: Populate [Authentication] group for contacts.



commit 0d22086e7145e544a814764f690f2dd65b352ffb
Author: Matthew Barnes <mbarnes redhat com>
Date:   Sat Dec 29 12:42:24 2012 -0500

    google-backend: Populate [Authentication] group for contacts.
    
    Set the Host to "www.google.com" and Method to either "OAuth2" or
    "ClientLogin", depending on whether EOAuth2Support is available.
    
    A temporary corner case occurs when using an older GNOME Online Accounts
    version, which uses OAuth 1.0a instead of 2.0 for Google authentication.
    In that case, the Method will say "ClientLogin" but the Google address
    book backend will ignore it and use its EGDataGoaAuthorizer.

 modules/google-backend/module-google-backend.c |   40 ++++++++++++++++++++++++
 1 files changed, 40 insertions(+), 0 deletions(-)
---
diff --git a/modules/google-backend/module-google-backend.c b/modules/google-backend/module-google-backend.c
index dd99c4c..99bbb01 100644
--- a/modules/google-backend/module-google-backend.c
+++ b/modules/google-backend/module-google-backend.c
@@ -51,6 +51,7 @@
 
 /* Contacts Configuration Details */
 #define GOOGLE_CONTACTS_BACKEND_NAME	"google"
+#define GOOGLE_CONTACTS_HOST		"www.google.com"
 #define GOOGLE_CONTACTS_RESOURCE_ID	"Contacts"
 
 typedef struct _EGoogleBackend EGoogleBackend;
@@ -94,6 +95,27 @@ G_DEFINE_DYNAMIC_TYPE (
 	E_TYPE_COLLECTION_BACKEND_FACTORY)
 
 static void
+google_backend_contacts_update_auth_method (ESource *source)
+{
+	EOAuth2Support *oauth2_support;
+	ESourceAuthentication *extension;
+	const gchar *extension_name;
+
+	extension_name = E_SOURCE_EXTENSION_AUTHENTICATION;
+	extension = e_source_get_extension (source, extension_name);
+
+	oauth2_support = e_server_side_source_ref_oauth2_support (
+		E_SERVER_SIDE_SOURCE (source));
+	if (oauth2_support != NULL) {
+		e_source_authentication_set_method (extension, "OAuth2");
+		g_object_unref (oauth2_support);
+		return;
+	}
+
+	e_source_authentication_set_method (extension, "ClientLogin");
+}
+
+static void
 google_backend_add_calendar (ECollectionBackend *backend)
 {
 	ESource *source;
@@ -211,6 +233,10 @@ google_backend_add_contacts (ECollectionBackend *backend)
 	extension_name = E_SOURCE_EXTENSION_AUTHENTICATION;
 	extension = e_source_get_extension (source, extension_name);
 
+	e_source_authentication_set_host (
+		E_SOURCE_AUTHENTICATION (extension),
+		GOOGLE_CONTACTS_HOST);
+
 	g_object_bind_property (
 		collection_extension, "identity",
 		extension, "user",
@@ -309,6 +335,20 @@ google_backend_child_added (ECollectionBackend *backend,
 			G_BINDING_SYNC_CREATE);
 	}
 
+	/* Keep the contacts authentication method up-to-date.
+	 *
+	 * XXX Not using a property binding here in case I end up adding
+	 *     other "support" interfaces which influence authentication.
+	 *     Many-to-one property bindings tend not to work so well. */
+	extension_name = E_SOURCE_EXTENSION_ADDRESS_BOOK;
+	if (e_source_has_extension (child_source, extension_name)) {
+		google_backend_contacts_update_auth_method (child_source);
+		g_signal_connect (
+			child_source, "notify::oauth2-support",
+			G_CALLBACK (google_backend_contacts_update_auth_method),
+			NULL);
+	}
+
 	/* Chain up to parent's child_added() method. */
 	E_COLLECTION_BACKEND_CLASS (e_google_backend_parent_class)->
 		child_added (backend, child_source);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]