Blame SOURCES/evolution-data-server-3.40.4-google-oauth2.patch

63acf8
From 08ec37272bb945625daed7e6ae7ed2bd663cdabd Mon Sep 17 00:00:00 2001
63acf8
From: Milan Crha <mcrha@redhat.com>
63acf8
Date: Wed, 4 May 2022 15:30:49 +0200
63acf8
Subject: [PATCH] I#388 - Google OAuth out-of-band (oob) flow will be
63acf8
 deprecated
63acf8
63acf8
Closes https://gitlab.gnome.org/GNOME/evolution-data-server/-/issues/388
63acf8
---
63acf8
 src/libedataserver/e-oauth2-service-google.c | 62 +++++++++++++++++---
63acf8
 1 file changed, 55 insertions(+), 7 deletions(-)
63acf8
63acf8
diff --git a/src/libedataserver/e-oauth2-service-google.c b/src/libedataserver/e-oauth2-service-google.c
63acf8
index 4d262d32f..93af1cb0b 100644
63acf8
--- a/src/libedataserver/e-oauth2-service-google.c
63acf8
+++ b/src/libedataserver/e-oauth2-service-google.c
63acf8
@@ -24,6 +24,7 @@
63acf8
 #include "e-oauth2-service-google.h"
63acf8
 
63acf8
 /* https://developers.google.com/identity/protocols/OAuth2InstalledApp */
63acf8
+/* https://developers.google.com/identity/protocols/oauth2/native-app */
63acf8
 
63acf8
 /* Forward Declarations */
63acf8
 static void e_oauth2_service_google_oauth2_service_init (EOAuth2ServiceInterface *iface);
63acf8
@@ -122,14 +123,60 @@ static const gchar *
63acf8
 eos_google_get_authentication_uri (EOAuth2Service *service,
63acf8
 				   ESource *source)
63acf8
 {
63acf8
-	return "https://accounts.google.com/o/oauth2/auth";
63acf8
+	return "https://accounts.google.com/o/oauth2/v2/auth";
63acf8
 }
63acf8
 
63acf8
 static const gchar *
63acf8
 eos_google_get_refresh_uri (EOAuth2Service *service,
63acf8
 			    ESource *source)
63acf8
 {
63acf8
-	return "https://www.googleapis.com/oauth2/v3/token";
63acf8
+	return "https://oauth2.googleapis.com/token";
63acf8
+}
63acf8
+
63acf8
+static const gchar *
63acf8
+eos_google_get_redirect_uri (EOAuth2Service *service,
63acf8
+			     ESource *source)
63acf8
+{
63acf8
+	G_LOCK_DEFINE_STATIC (redirect_uri);
63acf8
+	const gchar *key_name = "oauth2-google-redirect-uri";
63acf8
+	gchar *value;
63acf8
+
63acf8
+	G_LOCK (redirect_uri);
63acf8
+
63acf8
+	value = g_object_get_data (G_OBJECT (service), key_name);
63acf8
+	if (!value) {
63acf8
+		const gchar *client_id = eos_google_get_client_id (service, source);
63acf8
+
63acf8
+		if (client_id) {
63acf8
+			GPtrArray *array;
63acf8
+			gchar **strv;
63acf8
+			gchar *joinstr;
63acf8
+			guint ii;
63acf8
+
63acf8
+			strv = g_strsplit (client_id, ".", -1);
63acf8
+			array = g_ptr_array_new ();
63acf8
+
63acf8
+			for (ii = 0; strv[ii]; ii++) {
63acf8
+				g_ptr_array_insert (array, 0, strv[ii]);
63acf8
+			}
63acf8
+
63acf8
+			g_ptr_array_add (array, NULL);
63acf8
+
63acf8
+			joinstr = g_strjoinv (".", (gchar **) array->pdata);
63acf8
+			/* Use reverse-DNS of the client ID with the below path */
63acf8
+			value = g_strconcat (joinstr, ":/oauth2redirect", NULL);
63acf8
+
63acf8
+			g_ptr_array_free (array, TRUE);
63acf8
+			g_strfreev (strv);
63acf8
+			g_free (joinstr);
63acf8
+
63acf8
+			g_object_set_data_full (G_OBJECT (service), key_name, value, g_free);
63acf8
+		}
63acf8
+	}
63acf8
+
63acf8
+	G_UNLOCK (redirect_uri);
63acf8
+
63acf8
+	return value;
63acf8
 }
63acf8
 
63acf8
 static void
63acf8
@@ -191,13 +238,13 @@ eos_google_extract_authorization_code (EOAuth2Service *service,
63acf8
 
63acf8
 				params = soup_form_decode (query);
63acf8
 				if (params) {
63acf8
-					const gchar *response;
63acf8
+					const gchar *code;
63acf8
 
63acf8
-					response = g_hash_table_lookup (params, "response");
63acf8
-					if (response && g_ascii_strncasecmp (response, "code=", 5) == 0) {
63acf8
-						*out_authorization_code = g_strdup (response + 5);
63acf8
+					code = g_hash_table_lookup (params, "code");
63acf8
+					if (code && *code) {
63acf8
+						*out_authorization_code = g_strdup (code);
63acf8
 						known = TRUE;
63acf8
-					} else if (response && g_ascii_strncasecmp (response, "error", 5) == 0) {
63acf8
+					} else if (g_hash_table_lookup (params, "error")) {
63acf8
 						known = TRUE;
63acf8
 					}
63acf8
 
63acf8
@@ -225,6 +272,7 @@ e_oauth2_service_google_oauth2_service_init (EOAuth2ServiceInterface *iface)
63acf8
 	iface->get_client_secret = eos_google_get_client_secret;
63acf8
 	iface->get_authentication_uri = eos_google_get_authentication_uri;
63acf8
 	iface->get_refresh_uri = eos_google_get_refresh_uri;
63acf8
+	iface->get_redirect_uri = eos_google_get_redirect_uri;
63acf8
 	iface->prepare_authentication_uri_query = eos_google_prepare_authentication_uri_query;
63acf8
 	iface->extract_authorization_code = eos_google_extract_authorization_code;
63acf8
 }
63acf8
-- 
63acf8
2.35.1
63acf8