[evolution-data-server] [CalDAV] Add Bearer auth to the SoupSession only when using OAuth2



commit 8e52dec114bdfadaefcfa60d3bd4ad0cd54ae5d0
Author: Milan Crha <mcrha redhat com>
Date:   Thu Mar 10 14:57:48 2016 +0100

    [CalDAV] Add Bearer auth to the SoupSession only when using OAuth2
    
    It can be that the server advertises both Basic and Bearer authentication
    methods, while the calendar is setup to use the Basic. When the SoupSession
    checks for authentications it can pick the Bearer instead, even when
    the calendar doesn't have any credentials (OAuth2 token) for it.
    Not passing the Bearer authenticator to the SoupSession helps it
    to pick the right authenticator.

 calendar/backends/caldav/e-cal-backend-caldav.c |   11 ++++-------
 libedataserver/e-webdav-discover.c              |    2 +-
 2 files changed, 5 insertions(+), 8 deletions(-)
---
diff --git a/calendar/backends/caldav/e-cal-backend-caldav.c b/calendar/backends/caldav/e-cal-backend-caldav.c
index 3284f94..dcb11e2 100644
--- a/calendar/backends/caldav/e-cal-backend-caldav.c
+++ b/calendar/backends/caldav/e-cal-backend-caldav.c
@@ -387,6 +387,9 @@ caldav_maybe_prepare_bearer_auth (ECalBackendCalDAV *cbdav,
 
        feature = soup_session_get_feature (cbdav->priv->session, SOUP_TYPE_AUTH_MANAGER);
 
+       /* Add the "Bearer" auth type to support OAuth 2.0. */
+       soup_session_feature_add_feature (feature, E_TYPE_SOUP_AUTH_BEARER);
+
        extension = e_source_get_extension (source, E_SOURCE_EXTENSION_WEBDAV_BACKEND);
        soup_uri = e_source_webdav_dup_soup_uri (extension);
 
@@ -5637,18 +5640,12 @@ caldav_backend_initable_init (GInitable *initable,
                               GError **error)
 {
        ECalBackendCalDAVPrivate *priv;
-       SoupSessionFeature *feature;
-       gboolean success = TRUE;
 
        priv = E_CAL_BACKEND_CALDAV_GET_PRIVATE (initable);
 
-       feature = soup_session_get_feature (priv->session, SOUP_TYPE_AUTH_MANAGER);
-
-       /* Add the "Bearer" auth type to support OAuth 2.0. */
-       soup_session_feature_add_feature (feature, E_TYPE_SOUP_AUTH_BEARER);
        g_mutex_init (&priv->bearer_auth_error_lock);
 
-       return success;
+       return TRUE;
 }
 
 static void
diff --git a/libedataserver/e-webdav-discover.c b/libedataserver/e-webdav-discover.c
index 7c0f22b..b64d24d 100644
--- a/libedataserver/e-webdav-discover.c
+++ b/libedataserver/e-webdav-discover.c
@@ -1809,7 +1809,6 @@ e_webdav_discover_sources_sync (ESource *source,
                gchar *auth_method;
 
                feature = soup_session_get_feature (session, SOUP_TYPE_AUTH_MANAGER);
-               soup_session_feature_add_feature (feature, E_TYPE_SOUP_AUTH_BEARER);
 
                success = TRUE;
 
@@ -1825,6 +1824,7 @@ e_webdav_discover_sources_sync (ESource *source,
                                E_SOUP_AUTH_BEARER (soup_auth), cancellable, error);
 
                        if (success) {
+                               soup_session_feature_add_feature (feature, E_TYPE_SOUP_AUTH_BEARER);
                                soup_auth_manager_use_auth (
                                        SOUP_AUTH_MANAGER (feature),
                                        soup_uri, soup_auth);


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