Blame SOURCES/google-drop-password-based.patch

c7c487
From 34b900e7e4aad8b0454649dab0b4ebaaddb2adc4 Mon Sep 17 00:00:00 2001
c7c487
From: Debarshi Ray <debarshir@gnome.org>
c7c487
Date: Tue, 11 Jun 2013 16:58:21 +0200
c7c487
Subject: [PATCH 1/3] google: Bump credentials generation
c7c487
c7c487
Access to the following were turned on in the Google APIs Console:
c7c487
 - Calendar API
c7c487
 - Google Calendar CalDAV API
c7c487
 - Google Contacts CardDAV API
c7c487
c7c487
Of these, only the last two are new. We were already requesting the
c7c487
scope for Calendar API, but looks like the APIs Console is the way
c7c487
to go now. Interestingly the APIs Console does not list all the other
c7c487
services that we are interested in, or it is does but is not obvious
c7c487
to me.
c7c487
c7c487
In any case we need access to their new CalDAV API which works with
c7c487
OAuth2 because that would let us work with 2-factor authenticated
c7c487
accounts again.
c7c487
c7c487
See: https://bugzilla.gnome.org/show_bug.cgi?id=686804
c7c487
     https://bugzilla.gnome.org/show_bug.cgi?id=688364
c7c487
---
c7c487
 src/goabackend/goagoogleprovider.c | 2 +-
c7c487
 1 file changed, 1 insertion(+), 1 deletion(-)
c7c487
c7c487
diff --git a/src/goabackend/goagoogleprovider.c b/src/goabackend/goagoogleprovider.c
c7c487
index b3accdb..1c5c04b 100644
c7c487
--- a/src/goabackend/goagoogleprovider.c
c7c487
+++ b/src/goabackend/goagoogleprovider.c
c7c487
@@ -137,7 +137,7 @@ get_scope (GoaOAuth2Provider *provider)
c7c487
 static guint
c7c487
 get_credentials_generation (GoaProvider *provider)
c7c487
 {
c7c487
-  return 3;
c7c487
+  return 4;
c7c487
 }
c7c487
 
c7c487
 static const gchar *
c7c487
-- 
c7c487
1.8.4.2
c7c487
c7c487
c7c487
From 930a86add739b065b2cc43e2efae7fa30dfeee07 Mon Sep 17 00:00:00 2001
c7c487
From: Debarshi Ray <debarshir@gnome.org>
c7c487
Date: Wed, 19 Jun 2013 17:04:38 +0200
c7c487
Subject: [PATCH 2/3] google: Export CalDAV and CardDAV endpoints
c7c487
c7c487
According to:
c7c487
https://developers.google.com/google-apps/calendar/caldav/v2/guide/
c7c487
https://developers.google.com/google-apps/carddav/
c7c487
c7c487
See: https://bugzilla.gnome.org/show_bug.cgi?id=686804
c7c487
     https://bugzilla.gnome.org/show_bug.cgi?id=688364
c7c487
---
c7c487
 src/goabackend/goagoogleprovider.c | 18 ++++++++++++++++--
c7c487
 1 file changed, 16 insertions(+), 2 deletions(-)
c7c487
c7c487
diff --git a/src/goabackend/goagoogleprovider.c b/src/goabackend/goagoogleprovider.c
c7c487
index 1c5c04b..5b413f7 100644
c7c487
--- a/src/goabackend/goagoogleprovider.c
c7c487
+++ b/src/goabackend/goagoogleprovider.c
c7c487
@@ -355,6 +355,7 @@ build_object (GoaProvider         *provider,
c7c487
   gboolean contacts_enabled;
c7c487
   gboolean chat_enabled;
c7c487
   gboolean documents_enabled;
c7c487
+  const gchar *email_address;
c7c487
 
c7c487
   account = NULL;
c7c487
   mail = NULL;
c7c487
@@ -389,6 +390,7 @@ build_object (GoaProvider         *provider,
c7c487
     }
c7c487
 
c7c487
   account = goa_object_get_account (GOA_OBJECT (object));
c7c487
+  email_address = goa_account_get_identity (account);
c7c487
 
c7c487
   /* Email */
c7c487
   mail = goa_object_get_mail (GOA_OBJECT (object));
c7c487
@@ -397,8 +399,6 @@ build_object (GoaProvider         *provider,
c7c487
     {
c7c487
       if (mail == NULL)
c7c487
         {
c7c487
-          const gchar *email_address;
c7c487
-          email_address = goa_account_get_identity (account);
c7c487
           mail = goa_mail_skeleton_new ();
c7c487
           g_object_set (G_OBJECT (mail),
c7c487
                         "email-address",   email_address,
c7c487
@@ -428,8 +428,19 @@ build_object (GoaProvider         *provider,
c7c487
     {
c7c487
       if (calendar == NULL)
c7c487
         {
c7c487
+          gchar *uri_caldav;
c7c487
+
c7c487
+          uri_caldav = g_strconcat ("https://apidata.googleusercontent.com/caldav/v2/",
c7c487
+                                    email_address,
c7c487
+                                    "/user",
c7c487
+                                    NULL);
c7c487
+
c7c487
           calendar = goa_calendar_skeleton_new ();
c7c487
+          g_object_set (G_OBJECT (calendar),
c7c487
+                        "uri", uri_caldav,
c7c487
+                        NULL);
c7c487
           goa_object_skeleton_set_calendar (object, calendar);
c7c487
+          g_free (uri_caldav);
c7c487
         }
c7c487
     }
c7c487
   else
c7c487
@@ -446,6 +457,9 @@ build_object (GoaProvider         *provider,
c7c487
       if (contacts == NULL)
c7c487
         {
c7c487
           contacts = goa_contacts_skeleton_new ();
c7c487
+          g_object_set (G_OBJECT (contacts),
c7c487
+                        "uri", "https://www.googleapis.com/.well-known/carddav",
c7c487
+                        NULL);
c7c487
           goa_object_skeleton_set_contacts (object, contacts);
c7c487
         }
c7c487
     }
c7c487
-- 
c7c487
1.8.4.2
c7c487
c7c487
c7c487
From e3a72091bca2d48ee3c87530b0d8b30d87c21ff0 Mon Sep 17 00:00:00 2001
c7c487
From: Debarshi Ray <debarshir@gnome.org>
c7c487
Date: Fri, 28 Jun 2013 14:22:07 +0200
c7c487
Subject: [PATCH 3/3] google: Don't offer a PasswordBased interface
c7c487
c7c487
This was a temporary measure back when Google did not support OAuth2
c7c487
for CalDAV. Now that they do, we can drop this.
c7c487
c7c487
In any case, the workaround didn't work with accounts using 2-factor
c7c487
authentication. This will make those people happy.
c7c487
c7c487
This reverts 89c335479c1bb8409af8296c99ffea602a28b71f
c7c487
c7c487
See: https://bugzilla.gnome.org/show_bug.cgi?id=686804
c7c487
     https://bugzilla.gnome.org/show_bug.cgi?id=688364
c7c487
---
c7c487
 src/goabackend/goagoogleprovider.c | 215 -------------------------------------
c7c487
 1 file changed, 215 deletions(-)
c7c487
c7c487
diff --git a/src/goabackend/goagoogleprovider.c b/src/goabackend/goagoogleprovider.c
c7c487
index 5b413f7..065845d 100644
c7c487
--- a/src/goabackend/goagoogleprovider.c
c7c487
+++ b/src/goabackend/goagoogleprovider.c
c7c487
@@ -32,8 +32,6 @@
c7c487
 #include "goaprovider-priv.h"
c7c487
 #include "goaoauth2provider.h"
c7c487
 #include "goagoogleprovider.h"
c7c487
-#include "goahttpclient.h"
c7c487
-#include "goautils.h"
c7c487
 
c7c487
 /**
c7c487
  * GoaGoogleProvider:
c7c487
@@ -71,8 +69,6 @@ G_DEFINE_TYPE_WITH_CODE (GoaGoogleProvider, goa_google_provider, GOA_TYPE_OAUTH2
c7c487
 
c7c487
 /* ---------------------------------------------------------------------------------------------------- */
c7c487
 
c7c487
-static const gchar *CALDAV_ENDPOINT = "https://www.google.com/calendar/dav/%s/events/";
c7c487
-
c7c487
 static const gchar *
c7c487
 get_provider_type (GoaProvider *_provider)
c7c487
 {
c7c487
@@ -291,48 +287,8 @@ is_identity_node (GoaOAuth2Provider *provider, WebKitDOMHTMLInputElement *elemen
c7c487
   return ret;
c7c487
 }
c7c487
 
c7c487
-static gboolean
c7c487
-is_password_node (GoaOAuth2Provider *provider, WebKitDOMHTMLInputElement *element)
c7c487
-{
c7c487
-  gboolean ret;
c7c487
-  gchar *element_type;
c7c487
-  gchar *id;
c7c487
-  gchar *name;
c7c487
-
c7c487
-  element_type = NULL;
c7c487
-  id = NULL;
c7c487
-  name = NULL;
c7c487
-
c7c487
-  ret = FALSE;
c7c487
-
c7c487
-  g_object_get (element, "type", &element_type, NULL);
c7c487
-  if (g_strcmp0 (element_type, "password") != 0)
c7c487
-    goto out;
c7c487
-
c7c487
-  id = webkit_dom_html_element_get_id (WEBKIT_DOM_HTML_ELEMENT (element));
c7c487
-  if (g_strcmp0 (id, "Passwd") != 0)
c7c487
-    goto out;
c7c487
-
c7c487
-  name = webkit_dom_html_input_element_get_name (element);
c7c487
-  if (g_strcmp0 (name, "Passwd") != 0)
c7c487
-    goto out;
c7c487
-
c7c487
-  ret = TRUE;
c7c487
-
c7c487
- out:
c7c487
-  g_free (element_type);
c7c487
-  g_free (id);
c7c487
-  g_free (name);
c7c487
-  return ret;
c7c487
-}
c7c487
-
c7c487
 /* ---------------------------------------------------------------------------------------------------- */
c7c487
 
c7c487
-static gboolean on_handle_get_password (GoaPasswordBased      *interface,
c7c487
-                                        GDBusMethodInvocation *invocation,
c7c487
-                                        const gchar           *id,
c7c487
-                                        gpointer               user_data);
c7c487
-
c7c487
 static gboolean
c7c487
 build_object (GoaProvider         *provider,
c7c487
               GoaObjectSkeleton   *object,
c7c487
@@ -348,7 +304,6 @@ build_object (GoaProvider         *provider,
c7c487
   GoaContacts *contacts;
c7c487
   GoaChat *chat;
c7c487
   GoaDocuments *documents;
c7c487
-  GoaPasswordBased *password_based;
c7c487
   gboolean ret;
c7c487
   gboolean mail_enabled;
c7c487
   gboolean calendar_enabled;
c7c487
@@ -375,20 +330,6 @@ build_object (GoaProvider         *provider,
c7c487
                                                                             error))
c7c487
     goto out;
c7c487
 
c7c487
-  password_based = goa_object_get_password_based (GOA_OBJECT (object));
c7c487
-  if (password_based == NULL)
c7c487
-    {
c7c487
-      password_based = goa_password_based_skeleton_new ();
c7c487
-      /* Ensure D-Bus method invocations run in their own thread */
c7c487
-      g_dbus_interface_skeleton_set_flags (G_DBUS_INTERFACE_SKELETON (password_based),
c7c487
-                                           G_DBUS_INTERFACE_SKELETON_FLAGS_HANDLE_METHOD_INVOCATIONS_IN_THREAD);
c7c487
-      goa_object_skeleton_set_password_based (object, password_based);
c7c487
-      g_signal_connect (password_based,
c7c487
-                        "handle-get-password",
c7c487
-                        G_CALLBACK (on_handle_get_password),
c7c487
-                        NULL);
c7c487
-    }
c7c487
-
c7c487
   account = goa_object_get_account (GOA_OBJECT (object));
c7c487
   email_address = goa_account_get_identity (account);
c7c487
 
c7c487
@@ -549,103 +490,6 @@ build_object (GoaProvider         *provider,
c7c487
 /* ---------------------------------------------------------------------------------------------------- */
c7c487
 
c7c487
 static gboolean
c7c487
-ensure_credentials_sync (GoaProvider   *provider,
c7c487
-                         GoaObject     *object,
c7c487
-                         gint          *out_expires_in,
c7c487
-                         GCancellable  *cancellable,
c7c487
-                         GError       **error)
c7c487
-{
c7c487
-  GVariant *credentials;
c7c487
-  GoaAccount *account;
c7c487
-  GoaHttpClient *http_client;
c7c487
-  gboolean ret;
c7c487
-  const gchar *username;
c7c487
-  gchar *password;
c7c487
-  gchar *uri_caldav;
c7c487
-
c7c487
-  credentials = NULL;
c7c487
-  http_client = NULL;
c7c487
-  password = NULL;
c7c487
-  uri_caldav = NULL;
c7c487
-
c7c487
-  ret = FALSE;
c7c487
-
c7c487
-  /* Chain up */
c7c487
-  if (!GOA_PROVIDER_CLASS (goa_google_provider_parent_class)->ensure_credentials_sync (provider,
c7c487
-                                                                                       object,
c7c487
-                                                                                       out_expires_in,
c7c487
-                                                                                       cancellable,
c7c487
-                                                                                       error))
c7c487
-    goto out;
c7c487
-
c7c487
-  credentials = goa_utils_lookup_credentials_sync (provider,
c7c487
-                                                   object,
c7c487
-                                                   cancellable,
c7c487
-                                                   error);
c7c487
-  if (credentials == NULL)
c7c487
-    {
c7c487
-      if (error != NULL)
c7c487
-        {
c7c487
-          (*error)->domain = GOA_ERROR;
c7c487
-          (*error)->code = GOA_ERROR_NOT_AUTHORIZED;
c7c487
-        }
c7c487
-      goto out;
c7c487
-    }
c7c487
-
c7c487
-  account = goa_object_peek_account (object);
c7c487
-  username = goa_account_get_presentation_identity (account);
c7c487
-  uri_caldav = g_strdup_printf (CALDAV_ENDPOINT, username);
c7c487
-
c7c487
-  if (!g_variant_lookup (credentials, "password", "s", &password))
c7c487
-    {
c7c487
-      if (error != NULL)
c7c487
-        {
c7c487
-          *error = g_error_new (GOA_ERROR,
c7c487
-                                GOA_ERROR_NOT_AUTHORIZED,
c7c487
-                                _("Did not find password with identity `%s' in credentials"),
c7c487
-                                username);
c7c487
-        }
c7c487
-      goto out;
c7c487
-    }
c7c487
-
c7c487
-  http_client = goa_http_client_new ();
c7c487
-  ret = goa_http_client_check_sync (http_client,
c7c487
-                                    uri_caldav,
c7c487
-                                    username,
c7c487
-                                    password,
c7c487
-                                    FALSE,
c7c487
-                                    cancellable,
c7c487
-                                    error);
c7c487
-  if (!ret)
c7c487
-    {
c7c487
-      if (error != NULL)
c7c487
-        {
c7c487
-          g_prefix_error (error,
c7c487
-                          /* Translators: the first %s is the username
c7c487
-                           * (eg., debarshi.ray@gmail.com or rishi), and the
c7c487
-                           * (%s, %d) is the error domain and code.
c7c487
-                           */
c7c487
-                          _("Invalid password with username `%s' (%s, %d): "),
c7c487
-                          username,
c7c487
-                          g_quark_to_string ((*error)->domain),
c7c487
-                          (*error)->code);
c7c487
-          (*error)->domain = GOA_ERROR;
c7c487
-          (*error)->code = GOA_ERROR_NOT_AUTHORIZED;
c7c487
-        }
c7c487
-      goto out;
c7c487
-    }
c7c487
-
c7c487
- out:
c7c487
-  g_clear_object (&http_client);
c7c487
-  g_free (password);
c7c487
-  g_free (uri_caldav);
c7c487
-  g_clear_pointer (&credentials, (GDestroyNotify) g_variant_unref);
c7c487
-  return ret;
c7c487
-}
c7c487
-
c7c487
-/* ---------------------------------------------------------------------------------------------------- */
c7c487
-
c7c487
-static gboolean
c7c487
 get_use_mobile_browser (GoaOAuth2Provider *provider)
c7c487
 {
c7c487
   return TRUE;
c7c487
@@ -726,7 +570,6 @@ goa_google_provider_class_init (GoaGoogleProviderClass *klass)
c7c487
   provider_class->get_provider_name          = get_provider_name;
c7c487
   provider_class->get_provider_group         = get_provider_group;
c7c487
   provider_class->build_object               = build_object;
c7c487
-  provider_class->ensure_credentials_sync    = ensure_credentials_sync;
c7c487
   provider_class->show_account               = show_account;
c7c487
   provider_class->get_credentials_generation = get_credentials_generation;
c7c487
 
c7c487
@@ -740,65 +583,7 @@ goa_google_provider_class_init (GoaGoogleProviderClass *klass)
c7c487
   oauth2_class->get_scope                 = get_scope;
c7c487
   oauth2_class->is_deny_node              = is_deny_node;
c7c487
   oauth2_class->is_identity_node          = is_identity_node;
c7c487
-  oauth2_class->is_password_node          = is_password_node;
c7c487
   oauth2_class->get_token_uri             = get_token_uri;
c7c487
   oauth2_class->get_use_mobile_browser    = get_use_mobile_browser;
c7c487
   oauth2_class->add_account_key_values    = add_account_key_values;
c7c487
 }
c7c487
-
c7c487
-/* ---------------------------------------------------------------------------------------------------- */
c7c487
-
c7c487
-/* runs in a thread dedicated to handling @invocation */
c7c487
-static gboolean
c7c487
-on_handle_get_password (GoaPasswordBased      *interface,
c7c487
-                        GDBusMethodInvocation *invocation,
c7c487
-                        const gchar           *id, /* unused */
c7c487
-                        gpointer               user_data)
c7c487
-{
c7c487
-  GoaObject *object;
c7c487
-  GoaAccount *account;
c7c487
-  GoaProvider *provider;
c7c487
-  GError *error;
c7c487
-  GVariant *credentials;
c7c487
-  const gchar *identity;
c7c487
-  gchar *password;
c7c487
-
c7c487
-  /* TODO: maybe log what app is requesting access */
c7c487
-
c7c487
-  password = NULL;
c7c487
-  credentials = NULL;
c7c487
-
c7c487
-  object = GOA_OBJECT (g_dbus_interface_get_object (G_DBUS_INTERFACE (interface)));
c7c487
-  account = goa_object_peek_account (object);
c7c487
-  identity = goa_account_get_identity (account);
c7c487
-  provider = goa_provider_get_for_provider_type (goa_account_get_provider_type (account));
c7c487
-
c7c487
-  error = NULL;
c7c487
-  credentials = goa_utils_lookup_credentials_sync (provider,
c7c487
-                                                   object,
c7c487
-                                                   NULL, /* GCancellable* */
c7c487
-                                                   &error);
c7c487
-  if (credentials == NULL)
c7c487
-    {
c7c487
-      g_dbus_method_invocation_take_error (invocation, error);
c7c487
-      goto out;
c7c487
-    }
c7c487
-
c7c487
-  if (!g_variant_lookup (credentials, "password", "s", &password))
c7c487
-    {
c7c487
-      g_dbus_method_invocation_return_error (invocation,
c7c487
-                                             GOA_ERROR,
c7c487
-                                             GOA_ERROR_FAILED, /* TODO: more specific */
c7c487
-                                             _("Did not find password with identity `%s' in credentials"),
c7c487
-                                             identity);
c7c487
-      goto out;
c7c487
-    }
c7c487
-
c7c487
-  goa_password_based_complete_get_password (interface, invocation, password);
c7c487
-
c7c487
- out:
c7c487
-  g_free (password);
c7c487
-  g_clear_pointer (&credentials, (GDestroyNotify) g_variant_unref);
c7c487
-  g_object_unref (provider);
c7c487
-  return TRUE; /* invocation was handled */
c7c487
-}
c7c487
-- 
c7c487
1.8.4.2
c7c487