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

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