[evolution-ews] Bug 775690 - Support OAuth2 for outlook.office365.com (more changes)
- From: Milan Crha <mcrha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution-ews] Bug 775690 - Support OAuth2 for outlook.office365.com (more changes)
- Date: Tue, 6 Feb 2018 18:50:37 +0000 (UTC)
commit d96735f41e2ccb203b0fdfe2749a1ade61f77938
Author: Milan Crha <mcrha redhat com>
Date: Tue Feb 6 19:51:13 2018 +0100
Bug 775690 - Support OAuth2 for outlook.office365.com (more changes)
CMakeLists.txt | 2 +-
src/addressbook/e-book-backend-ews.c | 6 ++--
src/calendar/e-cal-backend-ews.c | 2 +-
src/configuration/e-mail-config-ews-backend.c | 2 +-
src/server/CMakeLists.txt | 3 ++
src/server/e-ews-connection-utils.c | 4 ++-
src/server/e-ews-connection.c | 42 +++++++++++++++++++++++++
src/server/e-ews-connection.h | 5 +++
src/server/e-oauth2-service-office365.c | 37 ++++++++++++---------
9 files changed, 80 insertions(+), 23 deletions(-)
---
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 9e20ca1..7285183 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -192,7 +192,7 @@ endif(WITH_OFFICE365_CLIENT_ID STREQUAL "")
add_printable_variable(WITH_OFFICE365_REDIRECT_URI "Office365.com OAuth 2.0 redirect URI" "")
if(WITH_OFFICE365_REDIRECT_URI STREQUAL "")
- set(WITH_OFFICE365_REDIRECT_URI "https://login.microsoftonline.com/common/oauth2/v2.0/nativeclient")
+ set(WITH_OFFICE365_REDIRECT_URI "https://login.microsoftonline.com/common/oauth2/nativeclient")
endif(WITH_OFFICE365_REDIRECT_URI STREQUAL "")
# ******************************
diff --git a/src/addressbook/e-book-backend-ews.c b/src/addressbook/e-book-backend-ews.c
index 190b2b7..e521f36 100644
--- a/src/addressbook/e-book-backend-ews.c
+++ b/src/addressbook/e-book-backend-ews.c
@@ -1887,7 +1887,7 @@ ebb_ews_download_gal_file (EBookBackendEws *bbews,
cache_dir = e_book_backend_get_cache_dir (E_BOOK_BACKEND (bbews));
download_path = g_build_filename (cache_dir, full->filename, NULL);
- oab_cnc = e_ews_connection_new (e_backend_get_source (E_BACKEND (bbews)), full_url, ews_settings);
+ oab_cnc = e_ews_connection_new_for_backend (E_BACKEND (bbews), e_book_backend_get_registry
(E_BOOK_BACKEND (bbews)), full_url, ews_settings);
e_binding_bind_property (
bbews, "proxy-resolver",
@@ -2732,7 +2732,7 @@ ebb_ews_connect_sync (EBookMetaBackend *meta_backend,
ews_settings = ebb_ews_get_collection_settings (bbews);
hosturl = camel_ews_settings_dup_hosturl (ews_settings);
- bbews->priv->cnc = e_ews_connection_new (e_backend_get_source (E_BACKEND (bbews)), hosturl,
ews_settings);
+ bbews->priv->cnc = e_ews_connection_new_for_backend (E_BACKEND (bbews), e_book_backend_get_registry
(E_BOOK_BACKEND (bbews)), hosturl, ews_settings);
e_binding_bind_property (
bbews, "proxy-resolver",
@@ -2856,7 +2856,7 @@ ebb_ews_get_changes_sync (EBookMetaBackend *meta_backend,
if (sequence == -1)
sequence = 0;
- oab_cnc = e_ews_connection_new (e_backend_get_source (E_BACKEND (bbews)), oab_url,
ews_settings);
+ oab_cnc = e_ews_connection_new_for_backend (E_BACKEND (bbews),
e_book_backend_get_registry (E_BOOK_BACKEND (bbews)), oab_url, ews_settings);
e_binding_bind_property (
bbews, "proxy-resolver",
diff --git a/src/calendar/e-cal-backend-ews.c b/src/calendar/e-cal-backend-ews.c
index 5941ebb..9efd5f5 100644
--- a/src/calendar/e-cal-backend-ews.c
+++ b/src/calendar/e-cal-backend-ews.c
@@ -1364,7 +1364,7 @@ ecb_ews_connect_sync (ECalMetaBackend *meta_backend,
ews_settings = ecb_ews_get_collection_settings (cbews);
hosturl = camel_ews_settings_dup_hosturl (ews_settings);
- cbews->priv->cnc = e_ews_connection_new (e_backend_get_source (E_BACKEND (cbews)), hosturl,
ews_settings);
+ cbews->priv->cnc = e_ews_connection_new_for_backend (E_BACKEND (cbews), e_cal_backend_get_registry
(E_CAL_BACKEND (cbews)), hosturl, ews_settings);
e_binding_bind_property (
cbews, "proxy-resolver",
diff --git a/src/configuration/e-mail-config-ews-backend.c b/src/configuration/e-mail-config-ews-backend.c
index 1ec22a1..9b52561 100644
--- a/src/configuration/e-mail-config-ews-backend.c
+++ b/src/configuration/e-mail-config-ews-backend.c
@@ -397,7 +397,7 @@ mail_config_ews_backend_insert_widgets (EMailConfigServiceBackend *backend,
widget, "sensitive",
G_BINDING_SYNC_CREATE);
- markup = g_strdup_printf (_("Default redirect URI is “%s”"),
"https://login.microsoftonline.com/common/oauth2/v2.0/nativeclient");
+ markup = g_strdup_printf (_("Default redirect URI is “%s”"),
"https://login.microsoftonline.com/common/oauth2/nativeclient");
mail_config_ews_backend_set_oauth2_tooltip (widget, OFFICE365_REDIRECT_URI,
markup,
g_strdup_printf (_("Default redirect URI is “%s”"), OFFICE365_REDIRECT_URI));
diff --git a/src/server/CMakeLists.txt b/src/server/CMakeLists.txt
index a6ed430..5b2ab0c 100644
--- a/src/server/CMakeLists.txt
+++ b/src/server/CMakeLists.txt
@@ -54,6 +54,7 @@ target_compile_definitions(evolution-ews PRIVATE
target_compile_options(evolution-ews PUBLIC
${CAMEL_CFLAGS}
+ ${LIBEBACKEND_CFLAGS}
${LIBECAL_CFLAGS}
${LIBEDATACAL_CFLAGS}
${LIBEDATASERVER_CFLAGS}
@@ -68,6 +69,7 @@ target_include_directories(evolution-ews PUBLIC
${CMAKE_SOURCE_DIR}/src
${CMAKE_CURRENT_BINARY_DIR}
${CAMEL_INCLUDE_DIRS}
+ ${LIBEBACKEND_INCLUDE_DIRS}
${LIBECAL_INCLUDE_DIRS}
${LIBEDATACAL_INCLUDE_DIRS}
${LIBEDATASERVER_INCLUDE_DIRS}
@@ -77,6 +79,7 @@ target_include_directories(evolution-ews PUBLIC
target_link_libraries(evolution-ews
${CAMEL_LDFLAGS}
+ ${LIBEBACKEND_LDFLAGS}
${LIBECAL_LDFLAGS}
${LIBEDATACAL_LDFLAGS}
${LIBEDATASERVER_LDFLAGS}
diff --git a/src/server/e-ews-connection-utils.c b/src/server/e-ews-connection-utils.c
index 822e53b..9c126ab 100644
--- a/src/server/e-ews-connection-utils.c
+++ b/src/server/e-ews-connection-utils.c
@@ -365,7 +365,9 @@ ews_connection_utils_maybe_prepare_bearer_auth (EEwsConnection *cnc,
return TRUE;
}
- if (g_strcmp0 (auth_method, "OAuth2") != 0 && !e_oauth2_services_is_oauth2_alias_static
(auth_method)) {
+ if (g_strcmp0 (auth_method, "OAuth2") != 0 &&
+ g_strcmp0 (auth_method, "Office365") != 0 &&
+ !e_oauth2_services_is_oauth2_alias_static (auth_method)) {
g_free (auth_method);
return TRUE;
}
diff --git a/src/server/e-ews-connection.c b/src/server/e-ews-connection.c
index 47f8ec4..1b4107f 100644
--- a/src/server/e-ews-connection.c
+++ b/src/server/e-ews-connection.c
@@ -2459,6 +2459,48 @@ e_ews_connection_new (ESource *source,
return e_ews_connection_new_full (source, uri, settings, TRUE);
}
+EEwsConnection *
+e_ews_connection_new_for_backend (EBackend *backend,
+ ESourceRegistry *registry,
+ const gchar *uri,
+ CamelEwsSettings *settings)
+{
+ ESource *source;
+ EEwsConnection *cnc;
+
+ g_return_val_if_fail (E_IS_BACKEND (backend), NULL);
+ g_return_val_if_fail (E_IS_SOURCE_REGISTRY (registry), NULL);
+
+ source = e_backend_get_source (backend);
+ if (!source)
+ return e_ews_connection_new (source, uri, settings);
+
+ g_object_ref (source);
+
+ while (source && !e_source_has_extension (source, E_SOURCE_EXTENSION_COLLECTION) &&
+ e_source_get_parent (source)) {
+ ESource *parent;
+
+ parent = e_source_registry_ref_source (registry, e_source_get_parent (source));
+ if (!parent) {
+ g_clear_object (&source);
+ break;
+ }
+
+ g_object_unref (source);
+ source = parent;
+ }
+
+ if (source)
+ cnc = e_ews_connection_new (source, uri, settings);
+ else
+ cnc = e_ews_connection_new (e_backend_get_source (backend), uri, settings);
+
+ g_clear_object (&source);
+
+ return cnc;
+}
+
void
e_ews_connection_update_credentials (EEwsConnection *cnc,
const ENamedParameters *credentials)
diff --git a/src/server/e-ews-connection.h b/src/server/e-ews-connection.h
index ab3e298..fdff192 100644
--- a/src/server/e-ews-connection.h
+++ b/src/server/e-ews-connection.h
@@ -28,6 +28,7 @@
#include <gio/gio.h>
#include <libsoup/soup.h>
#include <libedataserver/libedataserver.h>
+#include <libebackend/libebackend.h>
#include "e-soap-message.h"
#include "ews-errors.h"
@@ -413,6 +414,10 @@ EEwsConnection *e_ews_connection_new_full (ESource *source,
const gchar *uri,
CamelEwsSettings *settings,
gboolean allow_connection_reuse);
+EEwsConnection *e_ews_connection_new_for_backend(EBackend *backend,
+ ESourceRegistry *registry,
+ const gchar *uri,
+ CamelEwsSettings *settings);
void e_ews_connection_update_credentials
(EEwsConnection *cnc,
const ENamedParameters *credentials);
diff --git a/src/server/e-oauth2-service-office365.c b/src/server/e-oauth2-service-office365.c
index e442984..bdb6cd4 100644
--- a/src/server/e-oauth2-service-office365.c
+++ b/src/server/e-oauth2-service-office365.c
@@ -28,18 +28,20 @@
https://tsmatz.wordpress.com/2016/10/07/application-permission-with-v2-endpoint-and-microsoft-graph/
*/
+#define OFFICE365_RESOURCE "https://outlook.office.com"
+
#define OFFICE365_SCOPE "offline_access " \
- "https://outlook.office.com/Mail.ReadWrite " \
- "https://outlook.office.com/Mail.Send " \
- "https://outlook.office.com/Calendars.ReadWrite " \
- "https://outlook.office.com/Contacts.ReadWrite " \
- "https://outlook.office.com/Tasks.ReadWrite"
-
- /*"https://outlook.office.com/Mail.ReadWrite.Shared " \
- "https://outlook.office.com/Mail.Send.Shared " \
- "https://outlook.office.com/Calendars.ReadWrite.Shared " \
- "https://outlook.office.com/Contacts.ReadWrite.Shared " \
- "https://outlook.office.com/Tasks.ReadWrite.Shared"*/
+ "Mail.ReadWrite " \
+ "Mail.Send " \
+ "Calendars.ReadWrite " \
+ "Contacts.ReadWrite " \
+ "Tasks.ReadWrite"
+
+ /*"Mail.ReadWrite.Shared " \
+ "Mail.Send.Shared " \
+ "Calendars.ReadWrite.Shared " \
+ "Contacts.ReadWrite.Shared " \
+ "Tasks.ReadWrite.Shared"*/
struct _EOAuth2ServiceOffice365Private
{
@@ -169,7 +171,7 @@ eos_office365_get_authentication_uri (EOAuth2Service *service,
}
res = eos_office365_cache_string (oauth2_office365,
- g_strdup_printf ("https://login.microsoftonline.com/%s/oauth2/v2.0/authorize",
+ g_strdup_printf ("https://login.microsoftonline.com/%s/oauth2/authorize",
tenant ? tenant : OFFICE365_TENANT));
g_free (tenant);
@@ -177,7 +179,7 @@ eos_office365_get_authentication_uri (EOAuth2Service *service,
return res;
}
- return "https://login.microsoftonline.com/" OFFICE365_TENANT "/oauth2/v2.0/authorize";
+ return "https://login.microsoftonline.com/" OFFICE365_TENANT "/oauth2/authorize";
}
static const gchar *
@@ -199,7 +201,7 @@ eos_office365_get_refresh_uri (EOAuth2Service *service,
}
res = eos_office365_cache_string (oauth2_office365,
- g_strdup_printf ("https://login.microsoftonline.com/%s/oauth2/v2.0/token",
+ g_strdup_printf ("https://login.microsoftonline.com/%s/oauth2/token",
tenant ? tenant : OFFICE365_TENANT));
g_free (tenant);
@@ -207,7 +209,7 @@ eos_office365_get_refresh_uri (EOAuth2Service *service,
return res;
}
- return "https://login.microsoftonline.com/" OFFICE365_TENANT "/oauth2/v2.0/token";
+ return "https://login.microsoftonline.com/" OFFICE365_TENANT "/oauth2/token";
}
static const gchar *
@@ -237,7 +239,7 @@ eos_office365_get_redirect_uri (EOAuth2Service *service,
if (res && *res)
return res;
- return "https://login.microsoftonline.com/common/oauth2/v2.0/nativeclient";
+ return "https://login.microsoftonline.com/common/oauth2/nativeclient";
}
static void
@@ -248,7 +250,9 @@ eos_office365_prepare_authentication_uri_query (EOAuth2Service *service,
g_return_if_fail (uri_query != NULL);
e_oauth2_service_util_set_to_form (uri_query, "response_mode", "query");
+ e_oauth2_service_util_set_to_form (uri_query, "prompt", "admin_consent");
e_oauth2_service_util_set_to_form (uri_query, "scope", OFFICE365_SCOPE);
+ e_oauth2_service_util_set_to_form (uri_query, "resource", OFFICE365_RESOURCE);
}
static gboolean
@@ -316,6 +320,7 @@ eos_office365_prepare_refresh_token_form (EOAuth2Service *service,
g_return_if_fail (form != NULL);
e_oauth2_service_util_set_to_form (form, "scope", OFFICE365_SCOPE);
+ e_oauth2_service_util_set_to_form (form, "resource", OFFICE365_RESOURCE);
e_oauth2_service_util_set_to_form (form, "redirect_uri", e_oauth2_service_get_redirect_uri (service,
source));
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]