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

a51ff7
diff -up evolution-data-server-3.28.5/src/libedataserver/e-oauth2-service-google.c.google-oauth2 evolution-data-server-3.28.5/src/libedataserver/e-oauth2-service-google.c
a51ff7
--- evolution-data-server-3.28.5/src/libedataserver/e-oauth2-service-google.c.google-oauth2	2018-07-30 15:17:06.000000000 +0200
a51ff7
+++ evolution-data-server-3.28.5/src/libedataserver/e-oauth2-service-google.c	2022-05-04 18:57:08.059385307 +0200
a51ff7
@@ -24,6 +24,7 @@
a51ff7
 #include "e-oauth2-service-google.h"
a51ff7
 
a51ff7
 /* https://developers.google.com/identity/protocols/OAuth2InstalledApp */
a51ff7
+/* https://developers.google.com/identity/protocols/oauth2/native-app */
a51ff7
 
a51ff7
 /* Forward Declarations */
a51ff7
 static void e_oauth2_service_google_oauth2_service_init (EOAuth2ServiceInterface *iface);
a51ff7
@@ -74,14 +75,60 @@ static const gchar *
a51ff7
 eos_google_get_authentication_uri (EOAuth2Service *service,
a51ff7
 				   ESource *source)
a51ff7
 {
a51ff7
-	return "https://accounts.google.com/o/oauth2/auth";
a51ff7
+	return "https://accounts.google.com/o/oauth2/v2/auth";
a51ff7
 }
a51ff7
 
a51ff7
 static const gchar *
a51ff7
 eos_google_get_refresh_uri (EOAuth2Service *service,
a51ff7
 			    ESource *source)
a51ff7
 {
a51ff7
-	return "https://www.googleapis.com/oauth2/v3/token";
a51ff7
+	return "https://oauth2.googleapis.com/token";
a51ff7
+}
a51ff7
+
a51ff7
+static const gchar *
a51ff7
+eos_google_get_redirect_uri (EOAuth2Service *service,
a51ff7
+			     ESource *source)
a51ff7
+{
a51ff7
+	G_LOCK_DEFINE_STATIC (redirect_uri);
a51ff7
+	const gchar *key_name = "oauth2-google-redirect-uri";
a51ff7
+	gchar *value;
a51ff7
+
a51ff7
+	G_LOCK (redirect_uri);
a51ff7
+
a51ff7
+	value = g_object_get_data (G_OBJECT (service), key_name);
a51ff7
+	if (!value) {
a51ff7
+		const gchar *client_id = eos_google_get_client_id (service, source);
a51ff7
+
a51ff7
+		if (client_id) {
a51ff7
+			GPtrArray *array;
a51ff7
+			gchar **strv;
a51ff7
+			gchar *joinstr;
a51ff7
+			guint ii;
a51ff7
+
a51ff7
+			strv = g_strsplit (client_id, ".", -1);
a51ff7
+			array = g_ptr_array_new ();
a51ff7
+
a51ff7
+			for (ii = 0; strv[ii]; ii++) {
a51ff7
+				g_ptr_array_insert (array, 0, strv[ii]);
a51ff7
+			}
a51ff7
+
a51ff7
+			g_ptr_array_add (array, NULL);
a51ff7
+
a51ff7
+			joinstr = g_strjoinv (".", (gchar **) array->pdata);
a51ff7
+			/* Use reverse-DNS of the client ID with the below path */
a51ff7
+			value = g_strconcat (joinstr, ":/oauth2redirect", NULL);
a51ff7
+
a51ff7
+			g_ptr_array_free (array, TRUE);
a51ff7
+			g_strfreev (strv);
a51ff7
+			g_free (joinstr);
a51ff7
+
a51ff7
+			g_object_set_data_full (G_OBJECT (service), key_name, value, g_free);
a51ff7
+		}
a51ff7
+	}
a51ff7
+
a51ff7
+	G_UNLOCK (redirect_uri);
a51ff7
+
a51ff7
+	return value;
a51ff7
 }
a51ff7
 
a51ff7
 static void
a51ff7
@@ -143,13 +190,13 @@ eos_google_extract_authorization_code (E
a51ff7
 
a51ff7
 				params = soup_form_decode (query);
a51ff7
 				if (params) {
a51ff7
-					const gchar *response;
a51ff7
+					const gchar *code;
a51ff7
 
a51ff7
-					response = g_hash_table_lookup (params, "response");
a51ff7
-					if (response && g_ascii_strncasecmp (response, "code=", 5) == 0) {
a51ff7
-						*out_authorization_code = g_strdup (response + 5);
a51ff7
+					code = g_hash_table_lookup (params, "code");
a51ff7
+					if (code && *code) {
a51ff7
+						*out_authorization_code = g_strdup (code);
a51ff7
 						known = TRUE;
a51ff7
-					} else if (response && g_ascii_strncasecmp (response, "error", 5) == 0) {
a51ff7
+					} else if (g_hash_table_lookup (params, "error")) {
a51ff7
 						known = TRUE;
a51ff7
 					}
a51ff7
 
a51ff7
@@ -177,6 +224,7 @@ e_oauth2_service_google_oauth2_service_i
a51ff7
 	iface->get_client_secret = eos_google_get_client_secret;
a51ff7
 	iface->get_authentication_uri = eos_google_get_authentication_uri;
a51ff7
 	iface->get_refresh_uri = eos_google_get_refresh_uri;
a51ff7
+	iface->get_redirect_uri = eos_google_get_redirect_uri;
a51ff7
 	iface->prepare_authentication_uri_query = eos_google_prepare_authentication_uri_query;
a51ff7
 	iface->extract_authorization_code = eos_google_extract_authorization_code;
a51ff7
 }