summaryrefslogtreecommitdiff
path: root/rest
diff options
context:
space:
mode:
Diffstat (limited to 'rest')
-rw-r--r--rest/oauth-proxy-call.c16
-rw-r--r--rest/oauth-proxy-private.h2
-rw-r--r--rest/oauth-proxy.c59
-rw-r--r--rest/oauth-proxy.h4
4 files changed, 78 insertions, 3 deletions
diff --git a/rest/oauth-proxy-call.c b/rest/oauth-proxy-call.c
index 42a0b6e..b667b20 100644
--- a/rest/oauth-proxy-call.c
+++ b/rest/oauth-proxy-call.c
@@ -129,10 +129,22 @@ sign_hmac (OAuthProxy *proxy, RestProxyCall *call, GHashTable *oauth_params)
text = g_string_new (NULL);
g_string_append (text, rest_proxy_call_get_method (REST_PROXY_CALL (call)));
g_string_append_c (text, '&');
- if (priv->oauth_echo)
+ if (priv->oauth_echo) {
g_string_append_uri_escaped (text, priv->service_url, NULL, FALSE);
- else
+ } else if (priv->signature_host != NULL) {
+ SoupURI *url = soup_uri_new (callpriv->url);
+ gchar *signing_url;
+
+ soup_uri_set_host (url, priv->signature_host);
+ signing_url = soup_uri_to_string (url, FALSE);
+
+ g_string_append_uri_escaped (text, signing_url, NULL, FALSE);
+
+ soup_uri_free (url);
+ g_free (signing_url);
+ } else {
g_string_append_uri_escaped (text, callpriv->url, NULL, FALSE);
+ }
g_string_append_c (text, '&');
/* Merge the OAuth parameters with the query parameters */
diff --git a/rest/oauth-proxy-private.h b/rest/oauth-proxy-private.h
index e3943a9..2d178a5 100644
--- a/rest/oauth-proxy-private.h
+++ b/rest/oauth-proxy-private.h
@@ -40,4 +40,6 @@ typedef struct {
/* OAuth Echo */
gboolean oauth_echo;
char *service_url;
+ /* URL to use for signatures */
+ char *signature_host;
} OAuthProxyPrivate;
diff --git a/rest/oauth-proxy.c b/rest/oauth-proxy.c
index 03549dc..38c9e4a 100644
--- a/rest/oauth-proxy.c
+++ b/rest/oauth-proxy.c
@@ -33,7 +33,8 @@ enum {
PROP_CONSUMER_KEY,
PROP_CONSUMER_SECRET,
PROP_TOKEN,
- PROP_TOKEN_SECRET
+ PROP_TOKEN_SECRET,
+ PROP_SIGNATURE_HOST,
};
static RestProxyCall *
@@ -67,6 +68,9 @@ oauth_proxy_get_property (GObject *object, guint property_id,
case PROP_TOKEN_SECRET:
g_value_set_string (value, priv->token_secret);
break;
+ case PROP_SIGNATURE_HOST:
+ g_value_set_string (value, priv->signature_host);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
}
@@ -99,6 +103,11 @@ oauth_proxy_set_property (GObject *object, guint property_id,
g_free (priv->token_secret);
priv->token_secret = g_value_dup_string (value);
break;
+ case PROP_SIGNATURE_HOST:
+ if (priv->signature_host)
+ g_free (priv->signature_host);
+ priv->signature_host = g_value_dup_string (value);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
}
@@ -166,6 +175,13 @@ oauth_proxy_class_init (OAuthProxyClass *klass)
PROP_TOKEN_SECRET,
pspec);
+ pspec = g_param_spec_string ("signature-host", "signature-host",
+ "The base URL used in the signature string",
+ NULL, G_PARAM_READWRITE|G_PARAM_STATIC_STRINGS);
+ g_object_class_install_property (object_class,
+ PROP_SIGNATURE_HOST,
+ pspec);
+
/* TODO: add enum property for signature method */
}
@@ -686,6 +702,47 @@ oauth_proxy_is_oauth10a (OAuthProxy *proxy)
return PROXY_GET_PRIVATE (proxy)->oauth_10a;
}
+/**
+ * oauth_proxy_get_signature_host:
+ * @proxy: an #OAuthProxy
+ *
+ * Get the signature hostname used when creating a signature base string.
+ *
+ * Returns: the signature hostname, or %NULL if there is none set.
+ * This string is owned by #OAuthProxy and should not be freed.
+ */
+const char *
+oauth_proxy_get_signature_host (OAuthProxy *proxy)
+{
+ OAuthProxyPrivate *priv;
+
+ g_return_val_if_fail (OAUTH_IS_PROXY (proxy), NULL);
+ priv = PROXY_GET_PRIVATE (proxy);
+
+ return priv->signature_host;
+}
+
+/**
+ * oauth_proxy_set_signature_host:
+ * @proxy: an #OAuthProxy
+ * @signature_host: the signature host
+ *
+ * Set the signature hostname used when creating a signature base string.
+ */
+void
+oauth_proxy_set_signature_host (OAuthProxy *proxy,
+ const char *signature_host)
+{
+ OAuthProxyPrivate *priv;
+
+ g_return_if_fail (OAUTH_IS_PROXY (proxy));
+ priv = PROXY_GET_PRIVATE (proxy);
+
+ g_free (priv->signature_host);
+
+ priv->signature_host = g_strdup (signature_host);
+}
+
RestProxy *
oauth_proxy_new_echo_proxy (OAuthProxy *proxy,
/* TODO: should this be a function on the base url? */
diff --git a/rest/oauth-proxy.h b/rest/oauth-proxy.h
index c84a1b0..24749a3 100644
--- a/rest/oauth-proxy.h
+++ b/rest/oauth-proxy.h
@@ -152,6 +152,10 @@ void oauth_proxy_set_token (OAuthProxy *proxy, const char *token);
const char * oauth_proxy_get_token_secret (OAuthProxy *proxy);
void oauth_proxy_set_token_secret (OAuthProxy *proxy, const char *token_secret);
+const char * oauth_proxy_get_signature_host (OAuthProxy *proxy);
+
+void oauth_proxy_set_signature_host (OAuthProxy *proxy,
+ const char *signature_host);
RestProxy *oauth_proxy_new_echo_proxy (OAuthProxy *proxy,
const char *service_url,