[gnome-online-accounts: 3/7] oauth2: Add a new vfunc to influence the navigation policy



commit e6dc39a2d1492876c1715904a856210c4903c1c6
Author: Debarshi Ray <debarshir gnome org>
Date:   Tue Jul 19 18:34:33 2016 +0200

    oauth2: Add a new vfunc to influence the navigation policy
    
    Certain authentication flows might not transparently handle all
    possible interactions. Let us try to accommodate them by allowing the
    provider to add the appropriate redirects.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=755386

 src/goabackend/Makefile.am                  |    1 +
 src/goabackend/goaoauth2provider-priv.h     |    5 +++
 src/goabackend/goaoauth2provider-web-view.h |   37 +++++++++++++++++++++++
 src/goabackend/goaoauth2provider.c          |   43 +++++++++++++++++++++++++++
 4 files changed, 86 insertions(+), 0 deletions(-)
---
diff --git a/src/goabackend/Makefile.am b/src/goabackend/Makefile.am
index f4fbe5d..6aaf2d8 100644
--- a/src/goabackend/Makefile.am
+++ b/src/goabackend/Makefile.am
@@ -83,6 +83,7 @@ libgoa_backend_1_0_la_SOURCES =                                               \
        goaoauthprovider.h              goaoauthprovider.c              \
        goaoauth2provider.h             goaoauth2provider-priv.h        \
        goaoauth2provider-web-extension.h                               \
+       goaoauth2provider-web-view.h                                    \
        goaoauth2provider.c                                             \
        goagoogleprovider.h             goagoogleprovider.c             \
        goafacebookprovider.h           goafacebookprovider.c           \
diff --git a/src/goabackend/goaoauth2provider-priv.h b/src/goabackend/goaoauth2provider-priv.h
index 898255b..3f11076 100644
--- a/src/goabackend/goaoauth2provider-priv.h
+++ b/src/goabackend/goaoauth2provider-priv.h
@@ -27,6 +27,7 @@
 #include <goabackend/goaoauth2provider.h>
 #include <goabackend/goaprovider-priv.h>
 #include <goabackend/goabackendtypes.h>
+#include <webkit2/webkit2.h>
 #include <webkitdom/webkitdom.h>
 
 G_BEGIN_DECLS
@@ -58,6 +59,7 @@ struct _GoaOAuth2Provider
  * @build_authorization_uri: Virtual function for goa_oauth2_provider_build_authorization_uri().
  * @get_use_mobile_browser: Virtual function for goa_oauth2_provider_get_use_mobile_browser().
  * @add_account_key_values: Virtual function for goa_oauth2_provider_add_account_key_values().
+ * @decide_navigation_policy: Virtual function for goa_oauth2_provider_decide_navigation_policy().
  * @process_redirect_url: Virtual function for goa_oauth2_provider_process_redirect_url().
  * @is_deny_node: Virtual function for goa_oauth2_provider_is_deny_node().
  * @is_identity_node: Virtual function for goa_oauth2_provider_is_identity_node().
@@ -102,6 +104,9 @@ struct _GoaOAuth2ProviderClass
                                                 WebKitDOMNode                *node);
   gboolean     (*is_password_node)             (GoaOAuth2Provider            *provider,
                                                 WebKitDOMHTMLInputElement    *element);
+  gboolean     (*decide_navigation_policy)     (GoaOAuth2Provider              *provider,
+                                                WebKitWebView                  *web_view,
+                                                WebKitNavigationPolicyDecision *decision);
   gboolean     (*process_redirect_url)         (GoaOAuth2Provider            *provider,
                                                 const gchar                  *redirect_url,
                                                 gchar                       **access_token,
diff --git a/src/goabackend/goaoauth2provider-web-view.h b/src/goabackend/goaoauth2provider-web-view.h
new file mode 100644
index 0000000..d85c873
--- /dev/null
+++ b/src/goabackend/goaoauth2provider-web-view.h
@@ -0,0 +1,37 @@
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
+/*
+ * Copyright (C) 2016 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
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#if !defined (__GOA_BACKEND_INSIDE_GOA_BACKEND_H__) && !defined (GOA_BACKEND_COMPILATION)
+#error "Only <goabackend/goabackend.h> can be included directly."
+#endif
+
+#ifndef __GOA_OAUTH2_PROVIDER_WEB_VIEW_H__
+#define __GOA_OAUTH2_PROVIDER_WEB_VIEW_H__
+
+#include <goabackend/goaoauth2provider.h>
+#include <webkit2/webkit2.h>
+
+G_BEGIN_DECLS
+
+gboolean     goa_oauth2_provider_decide_navigation_policy     (GoaOAuth2Provider              *provider,
+                                                               WebKitWebView                  *web_view,
+                                                               WebKitNavigationPolicyDecision *decision);
+
+G_END_DECLS
+
+#endif /* __GOA_OAUTH2_PROVIDER_WEB_VIEW_H__ */
diff --git a/src/goabackend/goaoauth2provider.c b/src/goabackend/goaoauth2provider.c
index 5d94a96..e0ac022 100644
--- a/src/goabackend/goaoauth2provider.c
+++ b/src/goabackend/goaoauth2provider.c
@@ -31,6 +31,7 @@
 #include "goaoauth2provider.h"
 #include "goaoauth2provider-priv.h"
 #include "goaoauth2provider-web-extension.h"
+#include "goaoauth2provider-web-view.h"
 
 /**
  * SECTION:goaoauth2provider
@@ -285,6 +286,47 @@ goa_oauth2_provider_build_authorization_uri (GoaOAuth2Provider  *provider,
                                                                                     escaped_scope);
 }
 
+/* ---------------------------------------------------------------------------------------------------- */
+
+static gboolean
+goa_oauth2_provider_decide_navigation_policy_default (GoaOAuth2Provider               *provider,
+                                                      WebKitWebView                   *web_view,
+                                                      WebKitNavigationPolicyDecision  *decision)
+{
+  return FALSE;
+}
+
+/*
+ * goa_oauth2_provider_decide_navigation_policy_default:
+ * @provider: A #GoaOAuth2Provider.
+ * @decision: A #WebKitNavigationPolicyDecision
+ *
+ * Certain OAuth2-like, but not exactly <ulink
+ * url="http://tools.ietf.org/html/draft-ietf-oauth-v2-15";>OAuth2</ulink>,
+ * providers may not send us to the redirect URI, as expected. They
+ * might need some special handling for that. This is a provider
+ * specific hook to accommodate them.
+ *
+ * This is a virtual method where the default implementation returns
+ * %FALSE.
+ *
+ * Returns: %TRUE if @provider decided what to do with @decision,
+ * %FALSE otherwise.
+ */
+gboolean
+goa_oauth2_provider_decide_navigation_policy (GoaOAuth2Provider               *provider,
+                                              WebKitWebView                   *web_view,
+                                              WebKitNavigationPolicyDecision  *decision)
+{
+  g_return_val_if_fail (GOA_IS_OAUTH2_PROVIDER (provider), FALSE);
+  g_return_val_if_fail (WEBKIT_IS_WEB_VIEW (web_view), FALSE);
+  g_return_val_if_fail (WEBKIT_IS_NAVIGATION_POLICY_DECISION (decision), FALSE);
+
+  return GOA_OAUTH2_PROVIDER_GET_CLASS (provider)->decide_navigation_policy (provider, web_view, decision);
+}
+
+/* ---------------------------------------------------------------------------------------------------- */
+
 /**
  * goa_oauth2_provider_process_redirect_url:
  * @provider: A #GoaOAuth2Provider.
@@ -1703,6 +1745,7 @@ goa_oauth2_provider_class_init (GoaOAuth2ProviderClass *klass)
   provider_class->ensure_credentials_sync    = goa_oauth2_provider_ensure_credentials_sync;
 
   klass->build_authorization_uri  = goa_oauth2_provider_build_authorization_uri_default;
+  klass->decide_navigation_policy = goa_oauth2_provider_decide_navigation_policy_default;
   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;


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