summaryrefslogtreecommitdiff
path: root/src/libedataserver/e-source-credentials-provider.c
diff options
context:
space:
mode:
authorMilan Crha <mcrha@redhat.com>2018-01-22 13:32:29 +0100
committerMilan Crha <mcrha@redhat.com>2018-01-22 13:32:29 +0100
commit9a4c9d6a58e6dd5d4bbf3f8dc5d79040219dfbca (patch)
treedf078253f22bcd8c33802c8156b3892b32ba78cf /src/libedataserver/e-source-credentials-provider.c
parent01857f50c25d411f5ed83bff2d4554c65e3947bd (diff)
downloadevolution-data-server-9a4c9d6a58e6dd5d4bbf3f8dc5d79040219dfbca.tar.gz
Change how built-in OAuth2 authentication works
This change allows easier extending of built-in OAuth2 authentications with minimal code "duplication". A CMake option ENABLE_GOOGLE_AUTH had been renamed to ENABLE_OAUTH2 to reflect this extensibility as well.
Diffstat (limited to 'src/libedataserver/e-source-credentials-provider.c')
-rw-r--r--src/libedataserver/e-source-credentials-provider.c72
1 files changed, 4 insertions, 68 deletions
diff --git a/src/libedataserver/e-source-credentials-provider.c b/src/libedataserver/e-source-credentials-provider.c
index 7eea89814..36764ba80 100644
--- a/src/libedataserver/e-source-credentials-provider.c
+++ b/src/libedataserver/e-source-credentials-provider.c
@@ -33,7 +33,7 @@
/* built-in source credentials provider implementations */
#include "e-source-credentials-provider-impl-password.h"
-#include "e-source-credentials-provider-impl-google.h"
+#include "e-source-credentials-provider-impl-oauth2.h"
struct _ESourceCredentialsProviderPrivate {
GWeakRef registry; /* The property can hold both client and server-side registry */
@@ -200,7 +200,7 @@ e_source_credentials_provider_class_init (ESourceCredentialsProviderClass *class
/* Ensure built-in credential providers implementation types */
g_type_ensure (E_TYPE_SOURCE_CREDENTIALS_PROVIDER_IMPL_PASSWORD);
- g_type_ensure (E_TYPE_SOURCE_CREDENTIALS_PROVIDER_IMPL_GOOGLE);
+ g_type_ensure (E_TYPE_SOURCE_CREDENTIALS_PROVIDER_IMPL_OAUTH2);
}
static void
@@ -437,72 +437,8 @@ e_source_credentials_provider_ref_credentials_source (ESourceCredentialsProvider
collection = parent;
}
- if (collection && e_source_has_extension (collection, E_SOURCE_EXTENSION_COLLECTION)) {
- gboolean can_use_collection = FALSE;
-
- /* Use the found parent collection source for credentials store only if
- the child source doesn't have any authentication information, or this
- information is not filled, or if either the host name or the user name
- are the same with the collection source.
-
- This allows to create a collection of sources which has one source
- (like message send) on a different server, thus this source uses
- its own credentials.
- */
- if (!e_source_has_extension (source, E_SOURCE_EXTENSION_AUTHENTICATION)) {
- can_use_collection = TRUE;
- } else if (e_source_has_extension (collection, E_SOURCE_EXTENSION_AUTHENTICATION)) {
- ESourceAuthentication *auth_source, *auth_collection;
- gchar *host_source, *host_collection;
-
- auth_source = e_source_get_extension (source, E_SOURCE_EXTENSION_AUTHENTICATION);
- auth_collection = e_source_get_extension (collection, E_SOURCE_EXTENSION_AUTHENTICATION);
-
- host_source = e_source_authentication_dup_host (auth_source);
- host_collection = e_source_authentication_dup_host (auth_collection);
-
- if (host_source && host_collection && g_ascii_strcasecmp (host_source, host_collection) == 0) {
- gchar *username_source, *username_collection;
-
- username_source = e_source_authentication_dup_user (auth_source);
- username_collection = e_source_authentication_dup_user (auth_collection);
-
- if (username_source && username_collection && g_ascii_strcasecmp (username_source, username_collection) == 0) {
- can_use_collection = TRUE;
- } else {
- can_use_collection = !username_source || !*username_source;
- }
-
- g_free (username_source);
- g_free (username_collection);
- } else {
- /* Only one of them is filled, then use the collection; otherwise
- both are filled and they do not match, thus do not use collection. */
- can_use_collection = (host_collection && *host_collection && (!host_source || !*host_source)) ||
- (host_source && *host_source && (!host_collection || !*host_collection));
-
- if (can_use_collection) {
- gchar *method_source, *method_collection;
-
- /* Also check the method; if different, then rather not use the collection */
- method_source = e_source_authentication_dup_method (auth_source);
- method_collection = e_source_authentication_dup_method (auth_collection);
-
- can_use_collection = !method_source || !method_collection ||
- g_ascii_strcasecmp (method_source, method_collection) == 0;
-
- g_free (method_source);
- g_free (method_collection);
- }
- }
-
- g_free (host_source);
- g_free (host_collection);
- }
-
- if (can_use_collection)
- cred_source = g_object_ref (collection);
- }
+ if (e_util_can_use_collection_as_credential_source (collection, source))
+ cred_source = g_object_ref (collection);
g_clear_object (&collection);