summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorRoss Burton <ross@linux.intel.com>2008-09-18 21:18:23 +0100
committerRoss Burton <ross@linux.intel.com>2008-09-18 21:18:23 +0100
commit095846f59988a42b9937053001bebb3368fe22fc (patch)
treea9fa88cfcb00d7cc8fd31485e5425c2df31f4135 /examples
parent9f77edf5cd7b1dfdb9b2603db15db3be5ce67af0 (diff)
Add test-oauth
Diffstat (limited to 'examples')
-rw-r--r--examples/Makefile.am4
-rw-r--r--examples/test-oauth.c55
2 files changed, 57 insertions, 2 deletions
diff --git a/examples/Makefile.am b/examples/Makefile.am
index 83d48ea..9fd4152 100644
--- a/examples/Makefile.am
+++ b/examples/Makefile.am
@@ -1,8 +1,8 @@
-noinst_PROGRAMS = test-raw test-xml
+noinst_PROGRAMS = test-raw test-xml test-oauth
AM_CFLAGS = $(GLIB_CFLAGS) $(SOUP_CFLAGS) -I$(top_srcdir)
AM_LDFLAGS = $(GLIB_LIBS) $(SOUP_LIBS) ../rest/librest.la
test_raw_SOURCES = test-raw.c
test_xml_SOURCES = test-xml.c
-
+test_oauth_SOURCES = test-oauth.c
diff --git a/examples/test-oauth.c b/examples/test-oauth.c
new file mode 100644
index 0000000..b89c52b
--- /dev/null
+++ b/examples/test-oauth.c
@@ -0,0 +1,55 @@
+#include <rest/oauth-proxy.h>
+#include <stdio.h>
+
+static GMainLoop *loop;
+
+int
+main (int argc, char **argv)
+{
+ RestProxy *proxy;
+ RestProxyCall *call;
+ GError *error = NULL;
+
+ g_thread_init (NULL);
+ g_type_init ();
+
+ loop = g_main_loop_new (NULL, TRUE);
+
+ /* Create the proxy */
+ proxy = oauth_proxy_new (
+ /* Consumer Key */
+ "NmUm6hxQ9a4u",
+ /* Consumer Secret */
+ "t4FM7LiUeD4RBwKSPa6ichKPDh5Jx4kt",
+ /* FireEagle endpoint, which we bind as required */
+ "https://fireeagle.yahooapis.com/%s", TRUE);
+
+ /* First stage authentication, this gets a request token */
+ oauth_proxy_auth_step (OAUTH_PROXY (proxy), "oauth/request_token");
+
+ /* From the token construct a URL for the user to visit */
+ g_print ("Go to https://fireeagle.yahoo.net/oauth/authorize?oauth_token=%s then hit any key\n",
+ oauth_proxy_get_token (OAUTH_PROXY (proxy)));
+ getchar ();
+
+ /* Second stage authentication, this gets an access token */
+ oauth_proxy_auth_step (OAUTH_PROXY (proxy), "oauth/access_token");
+
+ /* We're now authenticated */
+ g_print ("Got access token\n");
+
+ /* Get the user's current location */
+ rest_proxy_bind (proxy, "api/0.1/user");
+ call = rest_proxy_new_call (proxy);
+
+ if (!rest_proxy_call_run (call, NULL, &error))
+ g_error ("Cannot make call: %s", error->message);
+
+ g_print ("%s\n", rest_proxy_call_get_payload (call));
+
+ g_object_unref (call);
+
+ g_object_unref (proxy);
+
+ return 0;
+}