[gnome-online-accounts/wip/pocket: 1/4] oauth2: Let backends extract the code or token themselves
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-online-accounts/wip/pocket: 1/4] oauth2: Let backends extract the code or token themselves
- Date: Fri, 20 Dec 2013 18:41:47 +0000 (UTC)
commit 7d3c4ba90131e7c2b19ea376be5cb05fb1188b13
Author: Bastien Nocera <hadess hadess net>
Date: Thu Oct 3 14:46:37 2013 +0200
oauth2: Let backends extract the code or token themselves
Certain OAuth2-like, but not exactly OAuth2, services do not follow
the standard mechanisms for extracting the access token or auth code
from the redirect URI. They use some non-standard technique to do so.
Let us try to accommodate them by allowing a provider specific hook
which we will invoke only if it is implemented.
https://bugzilla.gnome.org/show_bug.cgi?id=704564
src/goabackend/goaoauth2provider.c | 38 +++++++++++++++++++++++++++++++++--
src/goabackend/goaoauth2provider.h | 13 +++++++++++-
2 files changed, 47 insertions(+), 4 deletions(-)
---
diff --git a/src/goabackend/goaoauth2provider.c b/src/goabackend/goaoauth2provider.c
index 53f0d8b..fdb0bf9 100644
--- a/src/goabackend/goaoauth2provider.c
+++ b/src/goabackend/goaoauth2provider.c
@@ -291,6 +291,23 @@ goa_oauth2_provider_build_authorization_uri (GoaOAuth2Provider *provider,
escaped_scope);
}
+gboolean
+goa_oauth2_provider_process_redirect_url (GoaOAuth2Provider *provider,
+ const gchar *redirect_url,
+ gchar **authorization_code,
+ GError **error)
+{
+ g_return_val_if_fail (GOA_IS_OAUTH2_PROVIDER (provider), NULL);
+ g_return_val_if_fail (redirect_url != NULL, NULL);
+ g_return_val_if_fail (authorization_code != NULL, NULL);
+ g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
+
+ return GOA_OAUTH2_PROVIDER_GET_CLASS (provider)->process_redirect_url (provider,
+ redirect_url,
+ authorization_code,
+ error);
+}
+
/**
* goa_oauth2_provider_get_authorization_uri:
* @provider: A #GoaOAuth2Provider.
@@ -910,12 +927,27 @@ on_web_view_navigation_policy_decision_requested (WebKitWebView *web
fragment = soup_uri_get_fragment (uri);
query = soup_uri_get_query (uri);
- /* Two cases:
- * 1) we can either have the access_token and other information
+ /* Three cases:
+ * 1) we can either have the backend handle the URI for us, or
+ * 2) we can either have the access_token and other information
* directly in the fragment part of the URI, or
- * 2) the auth code can be in the query part of the URI, with which
+ * 3) the auth code can be in the query part of the URI, with which
* we'll obtain the token later.
*/
+ if (GOA_OAUTH2_PROVIDER_GET_CLASS (provider)->process_redirect_url)
+ {
+ gchar *url;
+
+ url = soup_uri_to_string (uri, FALSE);
+ if (!goa_oauth2_provider_process_redirect_url (provider, url, &priv->access_token, &priv->error))
+ response_id = GTK_RESPONSE_CLOSE;
+ else
+ response_id = GTK_RESPONSE_OK;
+
+ g_free (url);
+ goto ignore_request;
+ }
+
if (fragment != NULL)
{
/* fragment is encoded into a key/value pairs for the token and
diff --git a/src/goabackend/goaoauth2provider.h b/src/goabackend/goaoauth2provider.h
index 26bfaf6..4c91998 100644
--- a/src/goabackend/goaoauth2provider.h
+++ b/src/goabackend/goaoauth2provider.h
@@ -72,6 +72,7 @@ struct _GoaOAuth2Provider
* @get_use_external_browser: Virtual function for goa_oauth2_provider_get_use_external_browser().
* @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().
+ * @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().
* @is_password_node: Virtual function for goa_oauth2_provider_is_password_node().
@@ -117,9 +118,15 @@ struct _GoaOAuth2ProviderClass
gboolean (*is_password_node) (GoaOAuth2Provider *provider,
WebKitDOMHTMLInputElement *element);
+ gboolean (*process_redirect_url) (GoaOAuth2Provider *provider,
+ const gchar *redirect_url,
+ gchar **access_token,
+ GError **error);
+
+
/*< private >*/
/* Padding for future expansion */
- gpointer goa_reserved[29];
+ gpointer goa_reserved[28];
};
GType goa_oauth2_provider_get_type (void) G_GNUC_CONST;
@@ -156,6 +163,10 @@ gboolean goa_oauth2_provider_get_use_external_browser (GoaOAuth2Provider
gboolean goa_oauth2_provider_get_use_mobile_browser (GoaOAuth2Provider *provider);
void goa_oauth2_provider_add_account_key_values (GoaOAuth2Provider *provider,
GVariantBuilder *builder);
+gboolean goa_oauth2_provider_process_redirect_url (GoaOAuth2Provider *provider,
+ const gchar *redirect_url,
+ gchar
**authorization_code,
+ GError **error);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]