[evolution-data-server] [OAuth2] Add GSettings keys to override client ID and secret
- From: Milan Crha <mcrha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution-data-server] [OAuth2] Add GSettings keys to override client ID and secret
- Date: Mon, 11 Feb 2019 10:54:25 +0000 (UTC)
commit 3824aa3b88461f0d92f4bab2e674372d8eac629b
Author: Milan Crha <mcrha redhat com>
Date: Mon Feb 11 11:49:38 2019 +0100
[OAuth2] Add GSettings keys to override client ID and secret
The built-in OAuth2 service for Google and Outlook had only build-time
options to specify the client ID and secret, which is quite limiting
and unnecessarily complicated. The GSettings keys make it much simpler
to override the build-time values.
.../org.gnome.evolution-data-server.gschema.xml.in | 20 +++++++++
src/libedataserver/e-oauth2-service-google.c | 46 +++++++++++++++++++
src/libedataserver/e-oauth2-service-outlook.c | 52 ++++++++++++++++++++--
3 files changed, 115 insertions(+), 3 deletions(-)
---
diff --git a/data/org.gnome.evolution-data-server.gschema.xml.in
b/data/org.gnome.evolution-data-server.gschema.xml.in
index 27b2e0dd8..50857216d 100644
--- a/data/org.gnome.evolution-data-server.gschema.xml.in
+++ b/data/org.gnome.evolution-data-server.gschema.xml.in
@@ -46,5 +46,25 @@
Company:mail.company.com — enables “Company” OAuth2 authentication for “mail.company.com” host
Company-CalDAV:caldav.company.com — enables “Company” OAuth2 authentication for any “CalDAV” source,
which reads data from “caldav.company.com” host</_description>
</key>
+ <key name="oauth2-google-client-id" type="s">
+ <default>''</default>
+ <_summary>An OAuth2 client ID to use to connect to Google servers, instead of the one provided during
build time</_summary>
+ <_description>User-specified OAuth2 client ID for Google servers. Empty string means to use the one
provided during build time. Change of this requires restart.</_description>
+ </key>
+ <key name="oauth2-google-client-secret" type="s">
+ <default>''</default>
+ <_summary>An OAuth2 client secret to use to connect to Google servers, instead of the one provided
during build time</_summary>
+ <_description>User-specified OAuth2 client secret for Google servers. Empty string means to use the
one provided during build time. Change of this requires restart.</_description>
+ </key>
+ <key name="oauth2-outlook-client-id" type="s">
+ <default>''</default>
+ <_summary>An OAuth2 client ID to use to connect to Outlook servers, instead of the one provided during
build time</_summary>
+ <_description>User-specified OAuth2 client ID for Outlook servers. Empty string means to use the one
provided during build time. Change of this requires restart.</_description>
+ </key>
+ <key name="oauth2-outlook-client-secret" type="s">
+ <default>''</default>
+ <_summary>An OAuth2 client secret to use to connect to Outlook servers, instead of the one provided
during build time</_summary>
+ <_description>User-specified OAuth2 client secret for Outlook servers. Empty string means to use the
one provided during build time. Change of this requires restart.</_description>
+ </key>
</schema>
</schemalist>
diff --git a/src/libedataserver/e-oauth2-service-google.c b/src/libedataserver/e-oauth2-service-google.c
index c380c61ce..f0c6f2cbf 100644
--- a/src/libedataserver/e-oauth2-service-google.c
+++ b/src/libedataserver/e-oauth2-service-google.c
@@ -56,10 +56,49 @@ eos_google_get_display_name (EOAuth2Service *service)
return C_("OAuth2Service", "Google");
}
+static const gchar *
+eos_google_read_settings (EOAuth2Service *service,
+ const gchar *key_name)
+{
+ G_LOCK_DEFINE_STATIC (user_settings);
+ gchar *value;
+
+ G_LOCK (user_settings);
+
+ value = g_object_get_data (G_OBJECT (service), key_name);
+ if (!value) {
+ GSettings *settings;
+
+ settings = g_settings_new ("org.gnome.evolution-data-server");
+ value = g_settings_get_string (settings, key_name);
+ g_object_unref (settings);
+
+ if (value && *value) {
+ g_object_set_data_full (G_OBJECT (service), key_name, value, g_free);
+ } else {
+ g_free (value);
+ value = (gchar *) "";
+
+ g_object_set_data (G_OBJECT (service), key_name, value);
+ }
+ }
+
+ G_UNLOCK (user_settings);
+
+ return value;
+}
+
static const gchar *
eos_google_get_client_id (EOAuth2Service *service,
ESource *source)
{
+ const gchar *client_id;
+
+ client_id = eos_google_read_settings (service, "oauth2-google-client-id");
+
+ if (client_id && *client_id)
+ return client_id;
+
return GOOGLE_CLIENT_ID;
}
@@ -67,6 +106,13 @@ static const gchar *
eos_google_get_client_secret (EOAuth2Service *service,
ESource *source)
{
+ const gchar *client_secret;
+
+ client_secret = eos_google_read_settings (service, "oauth2-google-client-secret");
+
+ if (client_secret && *client_secret)
+ return client_secret;
+
return GOOGLE_CLIENT_SECRET;
}
diff --git a/src/libedataserver/e-oauth2-service-outlook.c b/src/libedataserver/e-oauth2-service-outlook.c
index cbc456b61..687c10d3b 100644
--- a/src/libedataserver/e-oauth2-service-outlook.c
+++ b/src/libedataserver/e-oauth2-service-outlook.c
@@ -57,10 +57,49 @@ eos_outlook_get_display_name (EOAuth2Service *service)
return C_("OAuth2Service", "Outlook");
}
+static const gchar *
+eos_outlook_read_settings (EOAuth2Service *service,
+ const gchar *key_name)
+{
+ G_LOCK_DEFINE_STATIC (user_settings);
+ gchar *value;
+
+ G_LOCK (user_settings);
+
+ value = g_object_get_data (G_OBJECT (service), key_name);
+ if (!value) {
+ GSettings *settings;
+
+ settings = g_settings_new ("org.gnome.evolution-data-server");
+ value = g_settings_get_string (settings, key_name);
+ g_object_unref (settings);
+
+ if (value && *value) {
+ g_object_set_data_full (G_OBJECT (service), key_name, value, g_free);
+ } else {
+ g_free (value);
+ value = (gchar *) "";
+
+ g_object_set_data (G_OBJECT (service), key_name, value);
+ }
+ }
+
+ G_UNLOCK (user_settings);
+
+ return value;
+}
+
static const gchar *
eos_outlook_get_client_id (EOAuth2Service *service,
ESource *source)
{
+ const gchar *client_id;
+
+ client_id = eos_outlook_read_settings (service, "oauth2-outlook-client-id");
+
+ if (client_id && *client_id)
+ return client_id;
+
return OUTLOOK_CLIENT_ID;
}
@@ -68,12 +107,19 @@ static const gchar *
eos_outlook_get_client_secret (EOAuth2Service *service,
ESource *source)
{
- const gchar *secret = OUTLOOK_CLIENT_SECRET;
+ const gchar *client_secret;
+
+ client_secret = eos_outlook_read_settings (service, "oauth2-outlook-client-secret");
+
+ if (client_secret && *client_secret)
+ return client_secret;
+
+ client_secret = OUTLOOK_CLIENT_SECRET;
- if (secret && !*secret)
+ if (client_secret && !*client_secret)
return NULL;
- return secret;
+ return client_secret;
}
static const gchar *
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]