[gnome-online-accounts] Add a default implementation for is_deny_node



commit 62c8b943296618cf17f392cb1b6b19c48d288401
Author: Debarshi Ray <debarshir gnome org>
Date:   Tue Feb 24 16:36:17 2015 +0100

    Add a default implementation for is_deny_node
    
    Compliant OAuth2 implementations return access_denied if the user
    denied access through the embedded web view. This is the preferred way
    and we should only parse the DOM if the server does not return a usable
    error code. Therefore there is no point in forcing every provider to
    have a dummy implementation of this method.
    
    Note that the OAuth1 base class does not check the error code. The only
    OAuth1 provider is Flickr and it doesn't send any.

 src/goabackend/goafacebookprovider.c    |    7 ----
 src/goabackend/goafoursquareprovider.c  |    9 -----
 src/goabackend/goagoogleprovider.c      |    7 ----
 src/goabackend/goaoauth2provider.c      |   59 ++++++++++++++++++-------------
 src/goabackend/goaoauth2provider.h      |    6 ++--
 src/goabackend/goaoauthprovider.c       |   57 +++++++++++++++++------------
 src/goabackend/goaoauthprovider.h       |    6 ++--
 src/goabackend/goawindowsliveprovider.c |    7 ----
 src/goabackend/goayahooprovider.c       |    7 ----
 9 files changed, 73 insertions(+), 92 deletions(-)
---
diff --git a/src/goabackend/goafacebookprovider.c b/src/goabackend/goafacebookprovider.c
index 27ccd62..3fe03e1 100644
--- a/src/goabackend/goafacebookprovider.c
+++ b/src/goabackend/goafacebookprovider.c
@@ -282,12 +282,6 @@ get_identity_sync (GoaOAuth2Provider  *provider,
 /* ---------------------------------------------------------------------------------------------------- */
 
 static gboolean
-is_deny_node (GoaOAuth2Provider *provider, WebKitDOMNode *node)
-{
-  return FALSE;
-}
-
-static gboolean
 is_identity_node (GoaOAuth2Provider *provider, WebKitDOMHTMLInputElement *element)
 {
   gboolean ret;
@@ -479,7 +473,6 @@ goa_facebook_provider_class_init (GoaFacebookProviderClass *klass)
   oauth2_class->get_client_secret        = get_client_secret;
   oauth2_class->get_authentication_cookie = get_authentication_cookie;
   oauth2_class->get_identity_sync        = get_identity_sync;
-  oauth2_class->is_deny_node             = is_deny_node;
   oauth2_class->is_identity_node         = is_identity_node;
   oauth2_class->add_account_key_values   = add_account_key_values;
 }
diff --git a/src/goabackend/goafoursquareprovider.c b/src/goabackend/goafoursquareprovider.c
index 0a82b10..19cbc23 100644
--- a/src/goabackend/goafoursquareprovider.c
+++ b/src/goabackend/goafoursquareprovider.c
@@ -285,14 +285,6 @@ get_identity_sync (GoaOAuth2Provider  *provider,
 /* ---------------------------------------------------------------------------------------------------- */
 
 static gboolean
-is_deny_node (GoaOAuth2Provider *provider, WebKitDOMNode *node)
-{
-  return FALSE;
-}
-
-/* ---------------------------------------------------------------------------------------------------- */
-
-static gboolean
 is_identity_node (GoaOAuth2Provider *provider, WebKitDOMHTMLInputElement *element)
 {
   gboolean ret;
@@ -453,7 +445,6 @@ goa_foursquare_provider_class_init (GoaFoursquareProviderClass *klass)
   oauth2_class->get_use_mobile_browser   = get_use_mobile_browser;
   oauth2_class->get_authentication_cookie = get_authentication_cookie;
   oauth2_class->get_identity_sync        = get_identity_sync;
-  oauth2_class->is_deny_node             = is_deny_node;
   oauth2_class->is_identity_node         = is_identity_node;
   oauth2_class->add_account_key_values   = add_account_key_values;
 }
diff --git a/src/goabackend/goagoogleprovider.c b/src/goabackend/goagoogleprovider.c
index c38d69f..cf6d041 100644
--- a/src/goabackend/goagoogleprovider.c
+++ b/src/goabackend/goagoogleprovider.c
@@ -268,12 +268,6 @@ get_identity_sync (GoaOAuth2Provider  *provider,
 /* ---------------------------------------------------------------------------------------------------- */
 
 static gboolean
-is_deny_node (GoaOAuth2Provider *provider, WebKitDOMNode *node)
-{
-  return FALSE;
-}
-
-static gboolean
 is_identity_node (GoaOAuth2Provider *provider, WebKitDOMHTMLInputElement *element)
 {
   gboolean ret;
@@ -709,7 +703,6 @@ goa_google_provider_class_init (GoaGoogleProviderClass *klass)
   oauth2_class->get_identity_sync         = get_identity_sync;
   oauth2_class->get_redirect_uri          = get_redirect_uri;
   oauth2_class->get_scope                 = get_scope;
-  oauth2_class->is_deny_node              = is_deny_node;
   oauth2_class->is_identity_node          = is_identity_node;
   oauth2_class->get_token_uri             = get_token_uri;
   oauth2_class->get_use_mobile_browser    = get_use_mobile_browser;
diff --git a/src/goabackend/goaoauth2provider.c b/src/goabackend/goaoauth2provider.c
index 8be7020..594c173 100644
--- a/src/goabackend/goaoauth2provider.c
+++ b/src/goabackend/goaoauth2provider.c
@@ -1,6 +1,6 @@
 /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
 /*
- * Copyright (C) 2011, 2012, 2013, 2014 Red Hat, Inc.
+ * Copyright (C) 2011, 2012, 2013, 2014, 2015 Red Hat, Inc.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -133,6 +133,38 @@ goa_oauth2_provider_get_use_mobile_browser (GoaOAuth2Provider *provider)
 /* ---------------------------------------------------------------------------------------------------- */
 
 static gboolean
+goa_oauth2_provider_is_deny_node_default (GoaOAuth2Provider *provider, WebKitDOMNode *node)
+{
+  return FALSE;
+}
+
+/**
+ * goa_oauth2_provider_is_deny_node:
+ * @provider: A #GoaOAuth2Provider.
+ * @node: A WebKitDOMNode.
+ *
+ * Checks whether @node is the HTML UI element that the user can use
+ * to deny permission to access his account. Usually they are either a
+ * WebKitDOMHTMLButtonElement or a WebKitDOMHTMLInputElement.
+ *
+ * Please note that providers may have multiple such elements in their
+ * UI and this method should catch all of them.
+ *
+ * This is a virtual method where the default implementation returns
+ * %FALSE.
+ *
+ * Returns: %TRUE if the @node can be used to deny permission.
+ */
+gboolean
+goa_oauth2_provider_is_deny_node (GoaOAuth2Provider *provider, WebKitDOMNode *node)
+{
+  g_return_val_if_fail (GOA_IS_OAUTH2_PROVIDER (provider), FALSE);
+  return GOA_OAUTH2_PROVIDER_GET_CLASS (provider)->is_deny_node (provider, node);
+}
+
+/* ---------------------------------------------------------------------------------------------------- */
+
+static gboolean
 goa_oauth2_provider_is_password_node_default (GoaOAuth2Provider *provider, WebKitDOMHTMLInputElement 
*element)
 {
   return FALSE;
@@ -496,30 +528,6 @@ goa_oauth2_provider_get_identity_sync (GoaOAuth2Provider    *provider,
 }
 
 /**
- * goa_oauth2_provider_is_deny_node:
- * @provider: A #GoaOAuth2Provider.
- * @node: A WebKitDOMNode.
- *
- * Checks whether @node is the HTML UI element that the user can use
- * to deny permission to access his account. Usually they are either a
- * WebKitDOMHTMLButtonElement or a WebKitDOMHTMLInputElement.
- *
- * Please note that providers may have multiple such elements in their
- * UI and this method should catch all of them.
- *
- * This is a pure virtual method - a subclass must provide an
- * implementation.
- *
- * Returns: %TRUE if the @node can be used to deny permission.
- */
-gboolean
-goa_oauth2_provider_is_deny_node (GoaOAuth2Provider *provider, WebKitDOMNode *node)
-{
-  g_return_val_if_fail (GOA_IS_OAUTH2_PROVIDER (provider), FALSE);
-  return GOA_OAUTH2_PROVIDER_GET_CLASS (provider)->is_deny_node (provider, node);
-}
-
-/**
  * goa_oauth2_provider_is_identity_node:
  * @provider: A #GoaOAuth2Provider.
  * @element: A WebKitDOMHTMLInputElement.
@@ -1750,6 +1758,7 @@ goa_oauth2_provider_class_init (GoaOAuth2ProviderClass *klass)
   klass->get_token_uri            = goa_oauth2_provider_get_token_uri_default;
   klass->get_scope                = goa_oauth2_provider_get_scope_default;
   klass->get_use_mobile_browser   = goa_oauth2_provider_get_use_mobile_browser_default;
+  klass->is_deny_node             = goa_oauth2_provider_is_deny_node_default;
   klass->is_password_node         = goa_oauth2_provider_is_password_node_default;
   klass->add_account_key_values   = goa_oauth2_provider_add_account_key_values_default;
 
diff --git a/src/goabackend/goaoauth2provider.h b/src/goabackend/goaoauth2provider.h
index 6c6a895..65c46cf 100644
--- a/src/goabackend/goaoauth2provider.h
+++ b/src/goabackend/goaoauth2provider.h
@@ -1,6 +1,6 @@
 /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
 /*
- * Copyright (C) 2011, 2012, 2014 Red Hat, Inc.
+ * Copyright (C) 2011, 2012, 2014, 2015 Red Hat, Inc.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -104,12 +104,12 @@ struct _GoaOAuth2ProviderClass
                                                 GVariantBuilder              *builder);
 
   /* pure virtual */
-  gboolean     (*is_deny_node)                 (GoaOAuth2Provider            *provider,
-                                                WebKitDOMNode                *node);
   gboolean     (*is_identity_node)             (GoaOAuth2Provider            *provider,
                                                 WebKitDOMHTMLInputElement    *element);
 
   /* virtual but with default implementation */
+  gboolean     (*is_deny_node)                 (GoaOAuth2Provider            *provider,
+                                                WebKitDOMNode                *node);
   gboolean     (*is_password_node)             (GoaOAuth2Provider            *provider,
                                                 WebKitDOMHTMLInputElement    *element);
 
diff --git a/src/goabackend/goaoauthprovider.c b/src/goabackend/goaoauthprovider.c
index 6225aff..9c95bae 100644
--- a/src/goabackend/goaoauthprovider.c
+++ b/src/goabackend/goaoauthprovider.c
@@ -115,6 +115,38 @@ goa_oauth_provider_get_use_mobile_browser (GoaOAuthProvider *provider)
 /* ---------------------------------------------------------------------------------------------------- */
 
 static gboolean
+goa_oauth_provider_is_deny_node_default (GoaOAuthProvider *provider, WebKitDOMNode *node)
+{
+  return FALSE;
+}
+
+/**
+ * goa_oauth_provider_is_deny_node:
+ * @provider: A #GoaOAuthProvider.
+ * @node: A WebKitDOMNode.
+ *
+ * Checks whether @node is the HTML UI element that the user can use
+ * to deny permission to access his account. Usually they are either a
+ * WebKitDOMHTMLButtonElement or a WebKitDOMHTMLInputElement.
+ *
+ * Please note that providers may have multiple such elements in their
+ * UI and this method should catch all of them.
+ *
+ * This is a virtual method where the default implementation returns
+ * %FALSE.
+ *
+ * Returns: %TRUE if the @node can be used to deny permission.
+ */
+gboolean
+goa_oauth_provider_is_deny_node (GoaOAuthProvider *provider, WebKitDOMNode *node)
+{
+  g_return_val_if_fail (GOA_IS_OAUTH_PROVIDER (provider), FALSE);
+  return GOA_OAUTH_PROVIDER_GET_CLASS (provider)->is_deny_node (provider, node);
+}
+
+/* ---------------------------------------------------------------------------------------------------- */
+
+static gboolean
 goa_oauth_provider_is_password_node_default (GoaOAuthProvider *provider, WebKitDOMHTMLInputElement *element)
 {
   return FALSE;
@@ -424,30 +456,6 @@ goa_oauth_provider_get_identity_sync (GoaOAuthProvider *provider,
 }
 
 /**
- * goa_oauth_provider_is_deny_node:
- * @provider: A #GoaOAuthProvider.
- * @node: A WebKitDOMNode.
- *
- * Checks whether @node is the HTML UI element that the user can use
- * to deny permission to access his account. Usually they are either a
- * WebKitDOMHTMLButtonElement or a WebKitDOMHTMLInputElement.
- *
- * Please note that providers may have multiple such elements in their
- * UI and this method should catch all of them.
- *
- * This is a pure virtual method - a subclass must provide an
- * implementation.
- *
- * Returns: %TRUE if the @node can be used to deny permission.
- */
-gboolean
-goa_oauth_provider_is_deny_node (GoaOAuthProvider *provider, WebKitDOMNode *node)
-{
-  g_return_val_if_fail (GOA_IS_OAUTH_PROVIDER (provider), FALSE);
-  return GOA_OAUTH_PROVIDER_GET_CLASS (provider)->is_deny_node (provider, node);
-}
-
-/**
  * goa_oauth_provider_is_identity_node:
  * @provider: A #GoaOAuthProvider.
  * @element: A WebKitDOMHTMLInputElement.
@@ -1686,6 +1694,7 @@ goa_oauth_provider_class_init (GoaOAuthProviderClass *klass)
 
   klass->build_authorization_uri  = goa_oauth_provider_build_authorization_uri_default;
   klass->get_use_mobile_browser   = goa_oauth_provider_get_use_mobile_browser_default;
+  klass->is_deny_node             = goa_oauth_provider_is_deny_node_default;
   klass->is_password_node         = goa_oauth_provider_is_password_node_default;
   klass->get_request_uri_params   = goa_oauth_provider_get_request_uri_params_default;
   klass->add_account_key_values   = goa_oauth_provider_add_account_key_values_default;
diff --git a/src/goabackend/goaoauthprovider.h b/src/goabackend/goaoauthprovider.h
index 82ca20a..f39d2b1 100644
--- a/src/goabackend/goaoauthprovider.h
+++ b/src/goabackend/goaoauthprovider.h
@@ -1,6 +1,6 @@
 /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
 /*
- * Copyright (C) 2011, 2012, 2014 Red Hat, Inc.
+ * Copyright (C) 2011, 2012, 2014, 2015 Red Hat, Inc.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -110,12 +110,12 @@ struct _GoaOAuthProviderClass
                                                 GVariantBuilder              *builder);
 
   /* pure virtual */
-  gboolean     (*is_deny_node)                 (GoaOAuthProvider             *provider,
-                                                WebKitDOMNode                *node);
   gboolean     (*is_identity_node)             (GoaOAuthProvider             *provider,
                                                 WebKitDOMHTMLInputElement    *element);
 
   /* virtual but with default implementation */
+  gboolean     (*is_deny_node)                 (GoaOAuthProvider             *provider,
+                                                WebKitDOMNode                *node);
   gboolean     (*is_password_node)             (GoaOAuthProvider             *provider,
                                                 WebKitDOMHTMLInputElement    *element);
 
diff --git a/src/goabackend/goawindowsliveprovider.c b/src/goabackend/goawindowsliveprovider.c
index 9be1f4f..e1ac1ab 100644
--- a/src/goabackend/goawindowsliveprovider.c
+++ b/src/goabackend/goawindowsliveprovider.c
@@ -253,12 +253,6 @@ get_identity_sync (GoaOAuth2Provider  *provider,
 /* ---------------------------------------------------------------------------------------------------- */
 
 static gboolean
-is_deny_node (GoaOAuth2Provider *provider, WebKitDOMNode *node)
-{
-  return FALSE;
-}
-
-static gboolean
 is_identity_node (GoaOAuth2Provider *provider, WebKitDOMHTMLInputElement *element)
 {
   gboolean ret;
@@ -469,7 +463,6 @@ goa_windows_live_provider_class_init (GoaWindowsLiveProviderClass *klass)
   oauth2_class->get_client_secret        = get_client_secret;
   oauth2_class->get_authentication_cookie = get_authentication_cookie;
   oauth2_class->get_identity_sync        = get_identity_sync;
-  oauth2_class->is_deny_node             = is_deny_node;
   oauth2_class->is_identity_node         = is_identity_node;
   oauth2_class->add_account_key_values   = add_account_key_values;
 }
diff --git a/src/goabackend/goayahooprovider.c b/src/goabackend/goayahooprovider.c
index 586ede3..33f2c08 100644
--- a/src/goabackend/goayahooprovider.c
+++ b/src/goabackend/goayahooprovider.c
@@ -314,12 +314,6 @@ get_identity_sync (GoaOAuthProvider  *provider,
 /* ---------------------------------------------------------------------------------------------------- */
 
 static gboolean
-is_deny_node (GoaOAuthProvider *provider, WebKitDOMNode *node)
-{
-  return FALSE;
-}
-
-static gboolean
 is_identity_node (GoaOAuthProvider *provider, WebKitDOMHTMLInputElement *element)
 {
   return FALSE;
@@ -418,7 +412,6 @@ goa_yahoo_provider_class_init (GoaYahooProviderClass *klass)
 
   oauth_class = GOA_OAUTH_PROVIDER_CLASS (klass);
   oauth_class->get_identity_sync        = get_identity_sync;
-  oauth_class->is_deny_node             = is_deny_node;
   oauth_class->is_identity_node         = is_identity_node;
   oauth_class->get_consumer_key         = get_consumer_key;
   oauth_class->get_consumer_secret      = get_consumer_secret;


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