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

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