[evolution-data-server] Bug 790267 - Expired Google OAuth2 token not refreshed ][



commit 73861538bda28e1146f9ae11c9b1657c98181cb2
Author: Milan Crha <mcrha redhat com>
Date:   Thu Nov 23 11:52:42 2017 +0100

    Bug 790267 - Expired Google OAuth2 token not refreshed ][
    
    Book/calendar part didn't work properly. Its workflow was:
    a) try with empty credentials => fail with CREDENTIALS_REQUIRED response
    b) source registry noticed it and asked for credentials, but
       the Google provider returned no credentials when reading them
       from the store (due to expired access token)
    c) left the source wait for credentials until they are provided
       by some GUI application
    d) in case of Evolution it could show either "Unknown error" or
       "Credentials required" error in the UI, instead of refreshing
       the token.
    
    This changes the b) in a way that when the lookup fails, but it still
    can read credentials, only the token is expired, then it'll refresh it
    and save, which will connect the book/calendar without a need for a GUI
    application with running credentials prompter.

 .../e-source-credentials-provider-impl-google.c    |   24 +++++++++++++++++++-
 1 files changed, 23 insertions(+), 1 deletions(-)
---
diff --git a/src/libedataserver/e-source-credentials-provider-impl-google.c 
b/src/libedataserver/e-source-credentials-provider-impl-google.c
index 0b60cb3..9424620 100644
--- a/src/libedataserver/e-source-credentials-provider-impl-google.c
+++ b/src/libedataserver/e-source-credentials-provider-impl-google.c
@@ -180,6 +180,8 @@ e_source_credentials_provider_impl_google_lookup_sync (ESourceCredentialsProvide
                                                       ENamedParameters **out_credentials,
                                                       GError **error)
 {
+       gboolean success;
+
        g_return_val_if_fail (E_IS_SOURCE_CREDENTIALS_PROVIDER_IMPL_GOOGLE (provider_impl), FALSE);
        g_return_val_if_fail (E_IS_SOURCE (source), FALSE);
        g_return_val_if_fail (out_credentials != NULL, FALSE);
@@ -192,7 +194,27 @@ e_source_credentials_provider_impl_google_lookup_sync (ESourceCredentialsProvide
                return FALSE;
        }
 
-       return e_source_credentials_google_util_lookup_secret_for_source_sync (source, FALSE, cancellable, 
out_credentials, error);
+       success = e_source_credentials_google_util_lookup_secret_for_source_sync (source, FALSE, cancellable, 
out_credentials, error);
+
+       /* Try to refresh the access token, in case it's stored, but expired. */
+       if (!success && !g_cancellable_is_cancelled (cancellable)) {
+               ENamedParameters *empty_credentials;
+               gchar *access_token = NULL;
+
+               /* Use empty credentials, to read from store. */
+               empty_credentials = e_named_parameters_new ();
+
+               if (e_source_credentials_google_get_access_token_sync (source, empty_credentials, 
&access_token, NULL, cancellable, NULL)) {
+                       g_free (access_token);
+                       g_clear_error (error);
+
+                       success = e_source_credentials_google_util_lookup_secret_for_source_sync (source, 
FALSE, cancellable, out_credentials, error);
+               }
+
+               e_named_parameters_free (empty_credentials);
+       }
+
+       return success;
 }
 
 static gboolean


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]