From a36606b6633e4244740793ab3a17d392b1cf6035 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=BCnther=20Wagner?= Date: Sun, 19 Jun 2022 11:10:14 +0200 Subject: Remove oauth1 proxy OAuth1 is discouraged to be used nowadays. Only flickr is the only service we used in the past which needed oauth1. They probably won't update their API to OAuth2 and therefore it was dropped in GOA. Following this example, dropping OAuth1 support too for librest. --- examples/continuous-twitter.c | 90 ---------------------- examples/demo/demo-rest-page.c | 165 +--------------------------------------- examples/demo/demo-rest-page.ui | 73 ------------------ examples/meson.build | 3 - examples/post-twitter-media.c | 101 ------------------------ examples/post-twitter.c | 77 ------------------- 6 files changed, 1 insertion(+), 508 deletions(-) delete mode 100644 examples/continuous-twitter.c delete mode 100644 examples/post-twitter-media.c delete mode 100644 examples/post-twitter.c (limited to 'examples') diff --git a/examples/continuous-twitter.c b/examples/continuous-twitter.c deleted file mode 100644 index 7a915e0..0000000 --- a/examples/continuous-twitter.c +++ /dev/null @@ -1,90 +0,0 @@ -/* - * librest - RESTful web services access - * Copyright (c) 2008, 2009, Intel Corporation. - * - * Authors: Rob Bradford - * Ross Burton - * - * 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 -#include - -static void -_call_continous_cb (RestProxyCall *call, - const gchar *buf, - gsize len, - const GError *error, - GObject *weak_object, - gpointer userdata) -{ - g_message ("%s", buf); -} - -int -main (int argc, char **argv) -{ - RestProxy *proxy; - RestProxyCall *call; - GError *error = NULL; - char pin[256]; - GMainLoop *loop; - - loop = g_main_loop_new (NULL, FALSE); - - /* Create the proxy */ - proxy = oauth_proxy_new ("UfXFxDbUjk41scg0kmkFwA", - "pYQlfI2ZQ1zVK0f01dnfhFTWzizBGDnhNJIw6xwto", - "https://api.twitter.com/", FALSE); - - /* First stage authentication, this gets a request token */ - if (!oauth_proxy_request_token (OAUTH_PROXY (proxy), "oauth/request_token", "oob", &error)) - g_error ("Cannot get request token: %s", error->message); - - /* From the token construct a URL for the user to visit */ - g_print ("Go to http://twitter.com/oauth/authorize?oauth_token=%s then enter the PIN\n", - oauth_proxy_get_token (OAUTH_PROXY (proxy))); - - fgets (pin, sizeof (pin), stdin); - g_strchomp (pin); - - /* Second stage authentication, this gets an access token */ - if (!oauth_proxy_access_token (OAUTH_PROXY (proxy), "oauth/access_token", pin, &error)) - g_error ("Cannot get access token: %s", error->message); - - /* We're now authenticated */ - - /* Post the status message */ - call = rest_proxy_new_call (proxy); - g_object_set (proxy, "url-format", "http://stream.twitter.com/", NULL); - rest_proxy_call_set_function (call, "1/statuses/filter.json"); - rest_proxy_call_set_method (call, "GET"); - rest_proxy_call_add_param (call, "track", "Cameron"); - rest_proxy_call_add_param (call, "delimited", "length"); - - rest_proxy_call_continuous (call, - _call_continous_cb, - NULL, - NULL, - NULL); - - g_main_loop_run (loop); - - g_object_unref (call); - g_object_unref (proxy); - - return 0; -} diff --git a/examples/demo/demo-rest-page.c b/examples/demo/demo-rest-page.c index e36fee7..d33d7b6 100644 --- a/examples/demo/demo-rest-page.c +++ b/examples/demo/demo-rest-page.c @@ -52,12 +52,6 @@ struct _DemoRestPage GtkWidget *digest_username; GtkWidget *digest_password; - /* oauth 1 auth */ - GtkWidget *oauth1_client_identifier; - GtkWidget *oauth1_client_secret; - GtkWidget *oauth1_get_access_token; - RestProxy *oauth1_proxy; - /* oauth 2 auth */ GtkWidget *oauth2_client_identifier; GtkWidget *oauth2_client_secret; @@ -73,7 +67,6 @@ typedef enum { AUTHMODE_NO, AUTHMODE_BASIC, AUTHMODE_DIGEST, - AUTHMODE_OAUTH1, AUTHMODE_OAUTH2 } AuthMode; @@ -90,7 +83,6 @@ demo_rest_page_finalize (GObject *object) { DemoRestPage *self = (DemoRestPage *)object; - g_clear_object (&self->oauth1_proxy); g_clear_object (&self->oauth2_proxy); g_clear_pointer (&self->pkce, rest_pkce_code_challenge_free); @@ -111,8 +103,6 @@ get_current_auth_mode (DemoRestPage *self) return AUTHMODE_BASIC; else if (g_strcmp0 (stack_name, "digest") == 0) return AUTHMODE_DIGEST; - else if (g_strcmp0 (stack_name, "oauth1") == 0) - return AUTHMODE_OAUTH1; else if (g_strcmp0 (stack_name, "oauth2") == 0) return AUTHMODE_OAUTH2; @@ -135,9 +125,7 @@ set_oauth_btn_active (DemoRestPage *self, { gtk_button_set_label (btn, "Get access token..."); gtk_widget_set_css_classes (GTK_WIDGET (btn), (const char*[]){ "suggested-action", NULL }); - if (proxy == self->oauth1_proxy) - g_clear_object (&self->oauth1_proxy); - else if (proxy == self->oauth2_proxy) + if (proxy == self->oauth2_proxy) g_clear_object (&self->oauth2_proxy); } } @@ -195,23 +183,6 @@ set_text_response (DemoRestPage *self, gtk_notebook_set_current_page (GTK_NOTEBOOK (self->notebook), 0); } -static void -demo_rest_page_fetched_oauth1_access_token (GObject *object, - GAsyncResult *result, - gpointer user_data) -{ - DemoRestPage *self = (DemoRestPage *)user_data; - RestProxy *proxy = (RestProxy *)object; - g_autoptr(GError) error = NULL; - - g_assert (G_IS_OBJECT (object)); - g_assert (G_IS_ASYNC_RESULT (result)); - - oauth_proxy_access_token_finish (OAUTH_PROXY (proxy), result, &error); - if (error) - set_oauth_btn_active (self, GTK_BUTTON (self->oauth1_get_access_token), proxy, FALSE); -} - static void demo_rest_page_fetched_oauth2_access_token (GObject *object, GAsyncResult *result, @@ -231,35 +202,6 @@ demo_rest_page_fetched_oauth2_access_token (GObject *object, } } -static void -oauth1_dialog_response (GtkDialog *dialog, - gint response_id, - DemoRestPage *self) -{ - switch (response_id) - { - case GTK_RESPONSE_OK: - { - const gchar *verifier = NULL; - GtkWidget *content_area = gtk_dialog_get_content_area (dialog); - GtkWidget *box = gtk_widget_get_first_child (content_area); - GtkWidget *entry = gtk_widget_get_last_child (box); - - verifier = gtk_editable_get_text (GTK_EDITABLE (entry)); - oauth_proxy_access_token_async (OAUTH_PROXY (self->oauth1_proxy), - "access_token", - verifier, - NULL, - demo_rest_page_fetched_oauth1_access_token, - self); - break; - } - case GTK_RESPONSE_CANCEL: - set_oauth_btn_active (self, GTK_BUTTON (self->oauth1_get_access_token), self->oauth1_proxy, FALSE); - break; - } -} - static void oauth2_dialog_response (GtkDialog *dialog, gint response_id, @@ -289,48 +231,6 @@ oauth2_dialog_response (GtkDialog *dialog, } } -static GtkWidget * -demo_rest_page_create_oauth1_dialog (DemoRestPage *self, - RestProxy *proxy) -{ - GtkWidget *dialog = NULL; - GtkWidget *content_area; - GtkWidget *box, *lbl, *token_lbl, *verifier_entry; - g_autofree char *token_str = NULL; - - dialog = gtk_dialog_new_with_buttons ("Get Verifier...", - GTK_WINDOW (gtk_widget_get_root (GTK_WIDGET (self))), - GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_USE_HEADER_BAR, - "Ok", - GTK_RESPONSE_OK, - "Cancel", - GTK_RESPONSE_CANCEL, - NULL); - - content_area = gtk_dialog_get_content_area (GTK_DIALOG (dialog)); - gtk_widget_set_margin_top (content_area, 6); - gtk_widget_set_margin_start (content_area, 6); - gtk_widget_set_margin_bottom (content_area, 6); - gtk_widget_set_margin_end (content_area, 6); - - box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6); - lbl = gtk_label_new ("Open a browser and authorize this application..."); - gtk_box_append (GTK_BOX (box), lbl); - token_str = g_strdup_printf ("Use this token: %s", oauth_proxy_get_token (OAUTH_PROXY (proxy))); - token_lbl = gtk_label_new (token_str); - gtk_label_set_selectable (GTK_LABEL (token_lbl), TRUE); - gtk_box_append (GTK_BOX (box), token_lbl); - verifier_entry = gtk_entry_new (); - gtk_box_append (GTK_BOX (box), verifier_entry); - - gtk_box_append (GTK_BOX (content_area), box); - - g_signal_connect (dialog, "response", G_CALLBACK (oauth1_dialog_response), self); - g_signal_connect_swapped (dialog, "response", G_CALLBACK (gtk_window_destroy), dialog); - - return dialog; -} - static GtkWidget * demo_rest_page_create_oauth2_dialog (DemoRestPage *self, RestProxy *proxy) @@ -377,57 +277,6 @@ demo_rest_page_create_oauth2_dialog (DemoRestPage *self, return dialog; } -static void -demo_rest_page_fetched_oauth1_request_token (GObject *object, - GAsyncResult *result, - gpointer user_data) -{ - DemoRestPage *self = (DemoRestPage *)user_data; - RestProxy *proxy = (RestProxy *)object; - GtkWidget *dialog = NULL; - g_autoptr(GError) error = NULL; - - g_assert (G_IS_OBJECT (object)); - g_assert (G_IS_ASYNC_RESULT (result)); - - oauth_proxy_request_token_finish (OAUTH_PROXY (proxy), result, &error); - if (error) - { - set_oauth_btn_active (self, GTK_BUTTON (self->oauth1_get_access_token), proxy, FALSE); - return; - } - - /* here we show a dialog requesting the user to a browser for authentication */ - dialog = demo_rest_page_create_oauth1_dialog (self, proxy); - - gtk_widget_show (dialog); -} - -static void -on_oauth1_get_access_token_clicked (GtkButton *btn, - gpointer user_data) -{ - DemoRestPage *self = (DemoRestPage *)user_data; - const char *url = NULL; - const char *consumer_key = NULL, *consumer_secret = NULL; - const char *function = NULL; - - if (self->oauth1_proxy != NULL) - { - set_oauth_btn_active (self, btn, self->oauth1_proxy, FALSE); - return; - } - - url = gtk_editable_get_text (GTK_EDITABLE (self->host)); - consumer_key = gtk_editable_get_text (GTK_EDITABLE (self->oauth1_client_identifier)); - consumer_secret = gtk_editable_get_text (GTK_EDITABLE (self->oauth1_client_secret)); - function = gtk_editable_get_text (GTK_EDITABLE (self->function)); - - self->oauth1_proxy = oauth_proxy_new (consumer_key, consumer_secret, url, FALSE); - oauth_proxy_request_token_async (OAUTH_PROXY (self->oauth1_proxy), function, "https://www.gnome.org", NULL, demo_rest_page_fetched_oauth1_request_token, self); - set_oauth_btn_active (self, btn, self->oauth1_proxy, TRUE); -} - static void on_oauth2_get_access_token_clicked (GtkButton *btn, gpointer user_data) @@ -531,13 +380,6 @@ on_send_clicked (GtkButton *btn, password = gtk_editable_get_text (GTK_EDITABLE (self->basic_password)); proxy = rest_proxy_new_with_authentication (url, FALSE, username, password); - break; - } - case AUTHMODE_OAUTH1: - { - g_object_set (self->oauth1_proxy, "url-format", url, NULL); - proxy = self->oauth1_proxy; - break; } case AUTHMODE_OAUTH2: @@ -620,10 +462,6 @@ demo_rest_page_class_init (DemoRestPageClass *klass) /* digest auth */ gtk_widget_class_bind_template_child (widget_class, DemoRestPage, digest_username); gtk_widget_class_bind_template_child (widget_class, DemoRestPage, digest_password); - /* oauth 1 auth */ - gtk_widget_class_bind_template_child (widget_class, DemoRestPage, oauth1_client_identifier); - gtk_widget_class_bind_template_child (widget_class, DemoRestPage, oauth1_client_secret); - gtk_widget_class_bind_template_child (widget_class, DemoRestPage, oauth1_get_access_token); /* oauth 2 auth */ gtk_widget_class_bind_template_child (widget_class, DemoRestPage, oauth2_client_identifier); gtk_widget_class_bind_template_child (widget_class, DemoRestPage, oauth2_client_secret); @@ -635,7 +473,6 @@ demo_rest_page_class_init (DemoRestPageClass *klass) /* callbacks */ gtk_widget_class_bind_template_callback (widget_class, on_send_clicked); gtk_widget_class_bind_template_callback (widget_class, on_auth_method_activated); - gtk_widget_class_bind_template_callback (widget_class, on_oauth1_get_access_token_clicked); gtk_widget_class_bind_template_callback (widget_class, on_oauth2_get_access_token_clicked); } diff --git a/examples/demo/demo-rest-page.ui b/examples/demo/demo-rest-page.ui index a5771c8..3bfc004 100644 --- a/examples/demo/demo-rest-page.ui +++ b/examples/demo/demo-rest-page.ui @@ -81,7 +81,6 @@ No Auth Basic Digest - OAuth1 OAuth2 @@ -197,78 +196,6 @@ - - - oauth1 - - - 8 - 6 - - - true - Client Identifier: - 1.0 - - 0 - 0 - - - - - - true - - 1 - 0 - - - - - - dialog-question-symbolic - Typically the consumer key and secret can be obtained from the oauth provider. - - 2 - 0 - - - - - - Client Secret: - 1.0 - - 0 - 1 - - - - - - - 1 - 1 - - - - - - Get access token... - - 1 - 2 - - - - - - - - - oauth2 diff --git a/examples/meson.build b/examples/meson.build index 37ea0ca..34c8f33 100644 --- a/examples/meson.build +++ b/examples/meson.build @@ -2,11 +2,8 @@ example_names = [ 'test-raw', 'test-xml', 'dump-xml', - 'post-twitter', - 'post-twitter-media', 'get-flickr-favorites', 'lastfm-shout', - 'continuous-twitter', 'gitlab-oauth2-example', ] diff --git a/examples/post-twitter-media.c b/examples/post-twitter-media.c deleted file mode 100644 index afae309..0000000 --- a/examples/post-twitter-media.c +++ /dev/null @@ -1,101 +0,0 @@ -/* - * librest - RESTful web services access - * Copyright (c) 2008, 2009, Intel Corporation. - * - * Authors: Rob Bradford - * Ross Burton - * - * 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 -#include - - -int -main (int argc, char **argv) -{ - RestProxy *proxy; - RestProxyCall *call; - RestParam *img_param; - GError *error = NULL; - char pin[256]; - gsize length; - gchar *contents; - - if (argc != 2) { - g_printerr ("$ post-twitter-media \"message\"\n"); - return -1; - } - - /* Create the proxy */ - proxy = oauth_proxy_new ("UfXFxDbUjk41scg0kmkFwA", - "pYQlfI2ZQ1zVK0f01dnfhFTWzizBGDnhNJIw6xwto", - "https://api.twitter.com/", FALSE); - - /* First stage authentication, this gets a request token */ - if (!oauth_proxy_request_token (OAUTH_PROXY (proxy), "oauth/request_token", "oob", &error)) - g_error ("Cannot get request token: %s", error->message); - - /* From the token construct a URL for the user to visit */ - g_print ("Go to http://twitter.com/oauth/authorize?oauth_token=%s then enter the PIN\n", - oauth_proxy_get_token (OAUTH_PROXY (proxy))); - - - fgets (pin, sizeof(pin), stdin); - g_strchomp (pin); - - - /* Second stage authentication, this gets an access token */ - if (!oauth_proxy_access_token (OAUTH_PROXY (proxy), "oauth/access_token", pin, &error)) - g_error ("Cannot get access token: %s", error->message); - - /* We're now authenticated */ - - - /* In order to send an image to twitter, we first need to load it ourselves. */ - if (!g_file_get_contents("test-media.png", &contents, &length, NULL)){ - g_error("reading file failed."); - return -1; - } - - - /* Create the multipart/form-data parameter */ - img_param = rest_param_new_full("media[]", REST_MEMORY_COPY, contents, - length, "multipart/form-data", "test-media.png"); - - - /* Post the status message */ - call = rest_proxy_new_call (REST_PROXY(proxy)); - rest_proxy_call_set_function (call, "1.1/statuses/update_with_media.json"); - rest_proxy_call_set_method (call, "POST"); - rest_proxy_call_add_param (call, "status", argv[1]); - rest_proxy_call_add_param_full(call, img_param); - - if (!rest_proxy_call_sync (call, &error)) { - g_message("Return Code: %u", rest_proxy_call_get_status_code(call)); - g_message("Payload: %s", rest_proxy_call_get_payload(call)); - g_error ("Cannot make call: %s", error->message); - } - - /* TODO: parse the XML and print something useful */ - g_print ("%s\n", rest_proxy_call_get_payload (call)); - - g_object_unref (call); - g_object_unref (proxy); - g_free (contents); - - return 0; -} diff --git a/examples/post-twitter.c b/examples/post-twitter.c deleted file mode 100644 index d87eb24..0000000 --- a/examples/post-twitter.c +++ /dev/null @@ -1,77 +0,0 @@ -/* - * librest - RESTful web services access - * Copyright (c) 2008, 2009, Intel Corporation. - * - * Authors: Rob Bradford - * Ross Burton - * - * 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 -#include - -int -main (int argc, char **argv) -{ - RestProxy *proxy; - RestProxyCall *call; - GError *error = NULL; - char pin[256]; - - if (argc != 2) { - g_printerr ("$ post-twitter \"message\"\n"); - return 1; - } - - /* Create the proxy */ - proxy = oauth_proxy_new ("UfXFxDbUjk41scg0kmkFwA", - "pYQlfI2ZQ1zVK0f01dnfhFTWzizBGDnhNJIw6xwto", - "https://api.twitter.com/", FALSE); - - /* First stage authentication, this gets a request token */ - if (!oauth_proxy_request_token (OAUTH_PROXY (proxy), "oauth/request_token", "oob", &error)) - g_error ("Cannot get request token: %s", error->message); - - /* From the token construct a URL for the user to visit */ - g_print ("Go to http://twitter.com/oauth/authorize?oauth_token=%s then enter the PIN\n", - oauth_proxy_get_token (OAUTH_PROXY (proxy))); - - fgets (pin, sizeof (pin), stdin); - g_strchomp (pin); - - /* Second stage authentication, this gets an access token */ - if (!oauth_proxy_access_token (OAUTH_PROXY (proxy), "oauth/access_token", pin, &error)) - g_error ("Cannot get access token: %s", error->message); - - /* We're now authenticated */ - - /* Post the status message */ - call = rest_proxy_new_call (proxy); - rest_proxy_call_set_function (call, "1/statuses/update.xml"); - rest_proxy_call_set_method (call, "POST"); - rest_proxy_call_add_param (call, "status", argv[1]); - - if (!rest_proxy_call_sync (call, &error)) - g_error ("Cannot make call: %s", error->message); - - /* TODO: parse the XML and print something useful */ - g_print ("%s\n", rest_proxy_call_get_payload (call)); - - g_object_unref (call); - g_object_unref (proxy); - - return 0; -} -- cgit v1.2.1