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

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