summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoss Burton <ross@linux.intel.com>2009-08-05 08:47:19 +0100
committerRoss Burton <ross@linux.intel.com>2009-08-05 08:47:19 +0100
commit349845409a79c13fea9355225612d3e65ed610f6 (patch)
tree8fba146bd5e39ec1103c1080e29f7d1b2cf3a34e
parentf8993177c3e1a9bce2cfcd9552ef4eb537b82c1f (diff)
downloadlibrest-349845409a79c13fea9355225612d3e65ed610f6.tar.gz
Add oauth_proxy_is_oauth10a()
-rw-r--r--docs/reference/rest/rest-sections.txt1
-rw-r--r--rest/oauth-proxy-private.h1
-rw-r--r--rest/oauth-proxy.c106
-rw-r--r--rest/oauth-proxy.h2
4 files changed, 95 insertions, 15 deletions
diff --git a/docs/reference/rest/rest-sections.txt b/docs/reference/rest/rest-sections.txt
index d78234f..b7b2a59 100644
--- a/docs/reference/rest/rest-sections.txt
+++ b/docs/reference/rest/rest-sections.txt
@@ -169,6 +169,7 @@ oauth_proxy_auth_step
oauth_proxy_auth_step_async
oauth_proxy_request_token
oauth_proxy_request_token_async
+oauth_proxy_is_oauth10a
oauth_proxy_access_token
oauth_proxy_access_token_async
oauth_proxy_get_token
diff --git a/rest/oauth-proxy-private.h b/rest/oauth-proxy-private.h
index 3d1fa02..6e44619 100644
--- a/rest/oauth-proxy-private.h
+++ b/rest/oauth-proxy-private.h
@@ -31,5 +31,6 @@ typedef struct {
char *token;
char *token_secret;
OAuthSignatureMethod method;
+ gboolean oauth_10a;
char *verifier;
} OAuthProxyPrivate;
diff --git a/rest/oauth-proxy.c b/rest/oauth-proxy.c
index 6c4d2ab..ae8db62 100644
--- a/rest/oauth-proxy.c
+++ b/rest/oauth-proxy.c
@@ -358,6 +358,19 @@ oauth_proxy_auth_step (OAuthProxy *proxy, const char *function, GError **error)
return TRUE;
}
+static void
+request_token_done (OAuthProxy *proxy, RestProxyCall *call)
+{
+ OAuthProxyPrivate *priv = PROXY_GET_PRIVATE (proxy);
+ GHashTable *form;
+
+ form = soup_form_decode (rest_proxy_call_get_payload (call));
+ priv->token = g_strdup (g_hash_table_lookup (form, "oauth_token"));
+ priv->token_secret = g_strdup (g_hash_table_lookup (form, "oauth_token_secret"));
+ priv->oauth_10a = g_hash_table_lookup (form, "oauth_callback_confirmed") != NULL;
+ g_hash_table_destroy (form);
+}
+
/**
* oauth_proxy_request_token:
* @proxy: an #OAuthProxy
@@ -381,9 +394,7 @@ oauth_proxy_request_token (OAuthProxy *proxy,
const char *callback_uri,
GError **error)
{
- OAuthProxyPrivate *priv = PROXY_GET_PRIVATE (proxy);
RestProxyCall *call;
- GHashTable *form;
call = rest_proxy_new_call (REST_PROXY (proxy));
rest_proxy_call_set_function (call, function ? function : "request_token");
@@ -397,17 +408,36 @@ oauth_proxy_request_token (OAuthProxy *proxy,
}
/* TODO: sanity check response */
- form = soup_form_decode (rest_proxy_call_get_payload (call));
- priv->token = g_strdup (g_hash_table_lookup (form, "oauth_token"));
- priv->token_secret = g_strdup (g_hash_table_lookup (form, "oauth_token_secret"));
- /* TODO: check for oauth_callback_confirmed=true and set is-1.0a flag? */
- g_hash_table_destroy (form);
+ request_token_done (proxy, call);
g_object_unref (call);
return TRUE;
}
+static void
+request_token_cb (RestProxyCall *call,
+ GError *error,
+ GObject *weak_object,
+ gpointer user_data)
+{
+ AuthData *data = user_data;
+ OAuthProxy *proxy = NULL;
+
+ g_object_get (call, "proxy", &proxy, NULL);
+ g_assert (proxy);
+
+ if (!error) {
+ request_token_done (proxy, call);
+ }
+
+ data->callback (proxy, error, weak_object, data->user_data);
+
+ g_slice_free (AuthData, data);
+ g_object_unref (call);
+ g_object_unref (proxy);
+}
+
/**
* oauth_proxy_request_token_async:
* @proxy: an #OAuthProxy
@@ -453,7 +483,19 @@ oauth_proxy_request_token_async (OAuthProxy *proxy,
data->callback = callback;
data->user_data = user_data;
- return rest_proxy_call_async (call, auth_callback, weak_object, data, error);
+ return rest_proxy_call_async (call, request_token_cb, weak_object, data, error);
+}
+
+static void
+access_token_done (OAuthProxy *proxy, RestProxyCall *call)
+{
+ OAuthProxyPrivate *priv = PROXY_GET_PRIVATE (proxy);
+ GHashTable *form;
+
+ form = soup_form_decode (rest_proxy_call_get_payload (call));
+ priv->token = g_strdup (g_hash_table_lookup (form, "oauth_token"));
+ priv->token_secret = g_strdup (g_hash_table_lookup (form, "oauth_token_secret"));
+ g_hash_table_destroy (form);
}
/**
@@ -479,9 +521,7 @@ oauth_proxy_access_token (OAuthProxy *proxy,
const char *verifier,
GError **error)
{
- OAuthProxyPrivate *priv = PROXY_GET_PRIVATE (proxy);
RestProxyCall *call;
- GHashTable *form;
call = rest_proxy_new_call (REST_PROXY (proxy));
rest_proxy_call_set_function (call, function ? function : "access_token");
@@ -495,16 +535,36 @@ oauth_proxy_access_token (OAuthProxy *proxy,
}
/* TODO: sanity check response */
- form = soup_form_decode (rest_proxy_call_get_payload (call));
- priv->token = g_strdup (g_hash_table_lookup (form, "oauth_token"));
- priv->token_secret = g_strdup (g_hash_table_lookup (form, "oauth_token_secret"));
- g_hash_table_destroy (form);
+ access_token_done (proxy, call);
g_object_unref (call);
return TRUE;
}
+static void
+access_token_cb (RestProxyCall *call,
+ GError *error,
+ GObject *weak_object,
+ gpointer user_data)
+{
+ AuthData *data = user_data;
+ OAuthProxy *proxy = NULL;
+
+ g_object_get (call, "proxy", &proxy, NULL);
+ g_assert (proxy);
+
+ if (!error) {
+ access_token_done (proxy, call);
+ }
+
+ data->callback (proxy, error, weak_object, data->user_data);
+
+ g_slice_free (AuthData, data);
+ g_object_unref (call);
+ g_object_unref (proxy);
+}
+
/**
* oauth_proxy_access_token_async:
* @proxy: an #OAuthProxy
@@ -551,7 +611,7 @@ oauth_proxy_access_token_async (OAuthProxy *proxy,
data->callback = callback;
data->user_data = user_data;
- return rest_proxy_call_async (call, auth_callback, weak_object, data, error);
+ return rest_proxy_call_async (call, access_token_cb, weak_object, data, error);
}
/**
@@ -627,3 +687,19 @@ oauth_proxy_set_token_secret (OAuthProxy *proxy, const char *token_secret)
priv->token_secret = g_strdup (token_secret);
}
+
+/**
+ * oauth_proxy_is_oauth10a:
+ * @proxy: an #OAuthProxy
+ *
+ * Returns %TRUE if the server supports OAuth 1.0a with this proxy, %FALSE
+ * otherwise. This is only valid after oauth_proxy_request_token() or
+ * oauth_proxy_request_token_async() has been called.
+ */
+gboolean
+oauth_proxy_is_oauth10a (OAuthProxy *proxy)
+{
+ g_return_val_if_fail (OAUTH_IS_PROXY (proxy), FALSE);
+
+ return PROXY_GET_PRIVATE (proxy)->oauth_10a;
+}
diff --git a/rest/oauth-proxy.h b/rest/oauth-proxy.h
index d19fcb5..7ba2309 100644
--- a/rest/oauth-proxy.h
+++ b/rest/oauth-proxy.h
@@ -123,6 +123,8 @@ gboolean oauth_proxy_request_token_async (OAuthProxy *proxy,
gpointer user_data,
GError **error);
+gboolean oauth_proxy_is_oauth10a (OAuthProxy *proxy);
+
gboolean oauth_proxy_access_token (OAuthProxy *proxy,
const char *function,
const char *verifier,