summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJonathon Jongsma <jonathon@quotidian.org>2010-05-07 17:15:20 -0500
committerRoss Burton <ross@linux.intel.com>2010-05-26 15:15:38 +0100
commit44c991200bd5e8bc8be11e9fb8af9937abc1ae7c (patch)
treee856f4cd9a93962a1b5550d5251b15bbc7cc844f /tests
parenta85b16a89d97199beabe283d5f0bdd9d1956490e (diff)
downloadlibrest-44c991200bd5e8bc8be11e9fb8af9937abc1ae7c.tar.gz
Add a oauth2 proxy
This new class provides a proxy class for oauth2-based web services, such as the new facebook graph API. The basic idea is as follows: - Construct a OAuth2Proxy object - Build a login url with _build_login_url(_full)() - Display said url in a browser widget (e.g. webkit) and listen for redirects to the specified 'redirect_uri' - Extract the access token from the uri that you are redirected to - Set the access token for the proxy with _set_access_token() http://bugs.meego.com/show_bug.cgi?id=2265
Diffstat (limited to 'tests')
-rw-r--r--tests/Makefile.am3
-rw-r--r--tests/oauth2.c56
2 files changed, 58 insertions, 1 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am
index bf23f5a..8a02588 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -1,4 +1,4 @@
-TESTS = proxy threaded oauth oauth-async flickr lastfm
+TESTS = proxy threaded oauth oauth-async oauth2 flickr lastfm
AM_CPPFLAGS = $(SOUP_CFLAGS) -I$(top_srcdir)
AM_LDFLAGS = $(SOUP_LIBS) ../rest/librest-@API_VERSION@.la ../rest-extras/librest-extras-@API_VERSION@.la
@@ -9,5 +9,6 @@ proxy_SOURCES = proxy.c
threaded_SOURCES = threaded.c
oauth_SOURCES = oauth.c
oauth_async_SOURCES = oauth-async.c
+oauth2_SOURCES = oauth2.c
flickr_SOURCES = flickr.c
lastfm_SOURCES = lastfm.c
diff --git a/tests/oauth2.c b/tests/oauth2.c
new file mode 100644
index 0000000..e992b6a
--- /dev/null
+++ b/tests/oauth2.c
@@ -0,0 +1,56 @@
+/*
+ * librest - RESTful web services access
+ * Copyright (c) 2010 Intel Corporation.
+ *
+ * Authors: Jonathon Jongsma <jonathon.jongsma@collabora.co.uk>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU Lesser General Public License,
+ * version 2.1, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope 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 program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ */
+
+#include <rest/oauth2-proxy.h>
+#include <string.h>
+
+void
+test_extract_token ()
+{
+ char *token;
+
+ /* test a url without a fragment */
+ token = oauth2_proxy_extract_access_token ("http://example.com/");
+ g_assert (token == NULL);
+
+ /* test a url with a fragment but without an access_token parameter */
+ token = oauth2_proxy_extract_access_token ("http://example.com/foo?foo=1#bar");
+ g_assert (token == NULL);
+
+ /* test simple access_token */
+ token = oauth2_proxy_extract_access_token ("http://example.com/foo?foo=1#access_token=1234567890_12.34561abcdefg&bar");
+ g_assert (strcmp(token, "1234567890_12.34561abcdefg") == 0);
+
+ /* test access_token with url encoding */
+ token = oauth2_proxy_extract_access_token ("http://example.com/foo?foo=1#access_token=1234567890%5F12%2E34561abcdefg&bar");
+ g_assert (strcmp(token, "1234567890_12.34561abcdefg") == 0);
+}
+
+int
+main (int argc, char **argv)
+{
+ g_thread_init (NULL);
+ g_type_init ();
+
+ test_extract_token ();
+
+ return 0;
+}