[gthumb] photobucket: fixed authorization process
- From: Paolo Bacchilega <paobac src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gthumb] photobucket: fixed authorization process
- Date: Sat, 22 Dec 2012 16:09:50 +0000 (UTC)
commit 44ae028a588c565776be6e3957300e0c130c0b8a
Author: Paolo Bacchilega <paobac src gnome org>
Date: Thu Dec 20 16:50:17 2012 +0100
photobucket: fixed authorization process
extensions/oauth/oauth-ask-authorization-dialog.c | 20 +++++++++++++++++++-
extensions/oauth/oauth-service.c | 20 ++++++++------------
extensions/photobucket/photobucket-consumer.c | 5 ++++-
extensions/photobucket/photobucket-service.c | 6 ++++--
4 files changed, 35 insertions(+), 16 deletions(-)
---
diff --git a/extensions/oauth/oauth-ask-authorization-dialog.c b/extensions/oauth/oauth-ask-authorization-dialog.c
index ea63d24..099fd05 100644
--- a/extensions/oauth/oauth-ask-authorization-dialog.c
+++ b/extensions/oauth/oauth-ask-authorization-dialog.c
@@ -110,7 +110,8 @@ webkit_view_load_changed_cb (WebKitWebView *web_view,
static void
oauth_ask_authorization_dialog_init (OAuthAskAuthorizationDialog *self)
{
- GtkWidget *box;
+ GtkWidget *box;
+ WebKitWebContext *context;
self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, OAUTH_TYPE_ASK_AUTHORIZATION_DIALOG, OAuthAskAuthorizationDialogPrivate);
@@ -125,6 +126,23 @@ oauth_ask_authorization_dialog_init (OAuthAskAuthorizationDialog *self)
gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (self))), box, TRUE, TRUE, 0);
self->priv->view = webkit_web_view_new ();
+ context = webkit_web_view_get_context (WEBKIT_WEB_VIEW (self->priv->view));
+ if (context != NULL) {
+ WebKitCookieManager *cookie_manager;
+ GFile *file;
+ char *cookie_filename;
+
+ file = gth_user_dir_get_file_for_write (GTH_DIR_CACHE, GTHUMB_DIR, "cookies", NULL);
+ cookie_filename = g_file_get_path (file);
+
+ cookie_manager = webkit_web_context_get_cookie_manager (context);
+ webkit_cookie_manager_set_accept_policy (cookie_manager, WEBKIT_COOKIE_POLICY_ACCEPT_ALWAYS);
+ webkit_cookie_manager_set_persistent_storage (cookie_manager, cookie_filename, WEBKIT_COOKIE_PERSISTENT_STORAGE_TEXT);
+ webkit_web_context_set_cache_model (context, WEBKIT_CACHE_MODEL_DOCUMENT_BROWSER);
+
+ g_free (cookie_filename);
+ g_object_unref (file);
+ }
gtk_widget_show (self->priv->view);
gtk_box_pack_start (GTK_BOX (box), self->priv->view, TRUE, TRUE, 0);
diff --git a/extensions/oauth/oauth-service.c b/extensions/oauth/oauth-service.c
index 39e10a8..2b0cb91 100644
--- a/extensions/oauth/oauth-service.c
+++ b/extensions/oauth/oauth-service.c
@@ -243,7 +243,8 @@ _oauth_service_get_access_token (OAuthService *self,
SoupMessage *msg;
data_set = g_hash_table_new (g_str_hash, g_str_equal);
- g_hash_table_insert (data_set, "oauth_verifier", (gpointer) verifier);
+ if (verifier != NULL)
+ g_hash_table_insert (data_set, "oauth_verifier", (gpointer) verifier);
oauth_service_add_signature (self, "POST", self->priv->consumer->access_token_url, data_set);
msg = soup_form_request_new_from_hash ("POST", self->priv->consumer->access_token_url, data_set);
_web_service_send_message (WEB_SERVICE (self),
@@ -321,17 +322,12 @@ ask_authorization_dialog_load_request_cb (OAuthAskAuthorizationDialog *dialog,
_g_strset (&self->priv->token, g_hash_table_lookup (data, "oauth_token"));
if (self->priv->token != NULL) {
- const char *oauth_verifier;
-
- oauth_verifier = g_hash_table_lookup (data, "oauth_verifier");
- if (oauth_verifier != NULL) {
- success = TRUE;
- _oauth_service_get_access_token (self,
- oauth_verifier,
- gth_task_get_cancellable (GTH_TASK (self)),
- get_access_token_ready_cb,
- self);
- }
+ success = TRUE;
+ _oauth_service_get_access_token (self,
+ g_hash_table_lookup (data, "oauth_verifier"),
+ gth_task_get_cancellable (GTH_TASK (self)),
+ get_access_token_ready_cb,
+ self);
}
if (! success)
diff --git a/extensions/photobucket/photobucket-consumer.c b/extensions/photobucket/photobucket-consumer.c
index 7ac2082..739e08e 100644
--- a/extensions/photobucket/photobucket-consumer.c
+++ b/extensions/photobucket/photobucket-consumer.c
@@ -74,8 +74,11 @@ photobucket_utils_parse_response (SoupMessage *msg,
*error = g_error_new_literal (WEB_SERVICE_ERROR, 999, _("Unknown error"));
}
else if (strcmp (status, "Exception") == 0) {
+ int error_code = (code != NULL) ? atoi (code) : 999;
+ if (error_code == 7)
+ error_code = WEB_SERVICE_ERROR_TOKEN_EXPIRED;
*error = g_error_new_literal (WEB_SERVICE_ERROR,
- (code != NULL) ? atoi (code) : 999,
+ error_code,
(message != NULL) ? message : _("Unknown error"));
}
diff --git a/extensions/photobucket/photobucket-service.c b/extensions/photobucket/photobucket-service.c
index 03e49a6..25120ab 100644
--- a/extensions/photobucket/photobucket-service.c
+++ b/extensions/photobucket/photobucket-service.c
@@ -155,8 +155,9 @@ photobucket_service_get_user_info (WebService *base,
SoupMessage *msg;
account = web_service_get_current_account (WEB_SERVICE (self));
- if (account != NULL)
- url = g_strconcat ("http://api.photobucket.com/user/", account->username, NULL);
+ g_return_if_fail (account != NULL);
+
+ url = g_strconcat ("http://api.photobucket.com/user/", account->username, NULL);
data_set = g_hash_table_new (g_str_hash, g_str_equal);
oauth_service_add_signature (OAUTH_SERVICE (self), "GET", url, data_set);
@@ -209,6 +210,7 @@ photobucket_service_new (GCancellable *cancellable,
"service-address", "www.photobucket.com",
"service-protocol", "http",
"account-type", PHOTOBUCKET_TYPE_ACCOUNT,
+ "consumer", &photobucket_consumer,
"cancellable", cancellable,
"browser", browser,
"dialog", dialog,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]