[gnome-software/wip/ubuntu-3-22: 10/28] ubuntu-review: Re-prompt for authentication if request fails due to 401
- From: Robert Ancell <rancell src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software/wip/ubuntu-3-22: 10/28] ubuntu-review: Re-prompt for authentication if request fails due to 401
- Date: Wed, 13 Dec 2017 21:36:55 +0000 (UTC)
commit 21a612e18dff2cd3d26f0e298a0a63db014aee52
Author: Robert Ancell <robert ancell canonical com>
Date: Tue Nov 8 10:51:39 2016 +1300
ubuntu-review: Re-prompt for authentication if request fails due to 401
src/plugins/gs-plugin-ubuntu-reviews.c | 50 ++++++++++++-------------------
1 files changed, 19 insertions(+), 31 deletions(-)
---
diff --git a/src/plugins/gs-plugin-ubuntu-reviews.c b/src/plugins/gs-plugin-ubuntu-reviews.c
index f4be0be..663f3ef 100644
--- a/src/plugins/gs-plugin-ubuntu-reviews.c
+++ b/src/plugins/gs-plugin-ubuntu-reviews.c
@@ -301,27 +301,6 @@ parse_review_entries (GsPlugin *plugin, JsonParser *parser, GError **error)
return TRUE;
}
-static gboolean
-get_ubuntuone_token (GsPlugin *plugin,
- gchar **consumer_key, gchar **consumer_secret,
- gchar **token_key, gchar **token_secret,
- GCancellable *cancellable, GError **error)
-{
- GsAuth *auth = gs_plugin_get_auth_by_id (plugin, "ubuntuone");
- if (auth == NULL) {
- g_set_error_literal (error,
- GS_PLUGIN_ERROR,
- GS_PLUGIN_ERROR_FAILED,
- "No UbuntuOne authentication provider");
- return FALSE;
- }
- *consumer_key = g_strdup (gs_auth_get_metadata_item (auth, "consumer-key"));
- *consumer_secret = g_strdup (gs_auth_get_metadata_item (auth, "consumer-secret"));
- *token_key = g_strdup (gs_auth_get_metadata_item (auth, "token-key"));
- *token_secret = g_strdup (gs_auth_get_metadata_item (auth, "token-secret"));
- return *consumer_key != NULL && *consumer_secret != NULL && *token_key != NULL && *token_secret !=
NULL;
-}
-
static void
sign_message (SoupMessage *message, OAuthMethod method,
const gchar *consumer_key, const gchar *consumer_secret,
@@ -363,15 +342,16 @@ send_review_request (GsPlugin *plugin,
g_autofree gchar *uri = NULL;
g_autoptr(SoupMessage) msg = NULL;
- if (do_sign && !get_ubuntuone_token (plugin,
- &consumer_key, &consumer_secret,
- &token_key, &token_secret,
- cancellable, NULL)) {
- g_set_error_literal (error,
- GS_PLUGIN_ERROR,
- GS_PLUGIN_ERROR_AUTH_REQUIRED,
- "Requires authentication with @ubuntuone");
- return FALSE;
+ if (do_sign) {
+ GsAuth *auth = gs_plugin_get_auth_by_id (plugin, "ubuntuone");
+ if (auth != NULL) {
+ consumer_key = g_strdup (gs_auth_get_metadata_item (auth, "consumer-key"));
+ consumer_secret = g_strdup (gs_auth_get_metadata_item (auth, "consumer-secret"));
+ token_key = g_strdup (gs_auth_get_metadata_item (auth, "token-key"));
+ token_secret = g_strdup (gs_auth_get_metadata_item (auth, "token-secret"));
+ }
+ else
+ g_warning ("No UbuntuOne authentication provider");
}
uri = g_strdup_printf ("%s%s",
@@ -389,7 +369,7 @@ send_review_request (GsPlugin *plugin,
soup_message_set_request (msg, "application/json", SOUP_MEMORY_TAKE, data, length);
}
- if (do_sign)
+ if (consumer_key != NULL && consumer_secret != NULL && token_key != NULL && token_secret != NULL)
sign_message (msg,
OA_PLAINTEXT,
consumer_key, consumer_secret,
@@ -397,6 +377,14 @@ send_review_request (GsPlugin *plugin,
*status_code = soup_session_send_message (gs_plugin_get_soup_session (plugin), msg);
+ if (*status_code == SOUP_STATUS_UNAUTHORIZED) {
+ g_set_error_literal (error,
+ GS_PLUGIN_ERROR,
+ GS_PLUGIN_ERROR_AUTH_REQUIRED,
+ "Requires authentication with @ubuntuone");
+ return FALSE;
+ }
+
if (result != NULL) {
g_autoptr(JsonParser) parser = NULL;
const gchar *content_type;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]