/soc/2015/nakulgulati/main: 9d9c73d641bc: hangouts: API Template...

Nakul at rock.pidgin.im Nakul at rock.pidgin.im
Mon Jun 29 01:54:34 EDT 2015


Changeset: 9d9c73d641bc91d904ea832b8de8d2ba2bf7700b
Author:	 Nakul Gulati
Date:	 2015-06-26 16:25 +0800
Branch:	 hangouts
URL: https://hg.pidgin.im/soc/2015/nakulgulati/main/rev/9d9c73d641bc

Description:

hangouts: API Template, auth-cookies

diffstat:

 libpurple/protocols/hangouts/api.c      |  22 +++++++++
 libpurple/protocols/hangouts/api.h      |  38 ++++++++++++++++
 libpurple/protocols/hangouts/auth.c     |  76 ++++++++++++++++++++++++++++++--
 libpurple/protocols/hangouts/auth.h     |   8 +++-
 libpurple/protocols/hangouts/hangouts.c |  25 ++++++++++
 5 files changed, 162 insertions(+), 7 deletions(-)

diffs (250 lines):

diff --git a/libpurple/protocols/hangouts/api.c b/libpurple/protocols/hangouts/api.c
new file mode 100644
--- /dev/null
+++ b/libpurple/protocols/hangouts/api.c
@@ -0,0 +1,22 @@
+/* purple
+ *
+ * Purple is the legal property of its developers, whose names are too numerous
+ * to list here.  Please refer to the COPYRIGHT file distributed with this
+ * source distribution.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111-1301  USA
+ */
+
+#include "api.h"
diff --git a/libpurple/protocols/hangouts/api.h b/libpurple/protocols/hangouts/api.h
new file mode 100644
--- /dev/null
+++ b/libpurple/protocols/hangouts/api.h
@@ -0,0 +1,38 @@
+/* purple
+ *
+ * Purple is the legal property of its developers, whose names are too numerous
+ * to list here.  Please refer to the COPYRIGHT file distributed with this
+ * source distribution.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111-1301  USA
+ */
+
+#ifndef _API_H
+#define _API_H
+
+#define ORIGIN_URL "https://talkgadget.google.com"
+#define IMAGE_UPLOAD_URL "http://docs.google.com/upload/photos/resumable"
+#define PVT_TOKEN_URL "https://talkgadget.google.com/talkgadget/_/extension-start"
+#define CHAT_INIT_URL "https://talkgadget.google.com/u/0/talkgadget/_/chat"
+
+#define PROP "aChromeExtension"
+#define FID "gtn-roster-iframe-id"
+#define EC "[\"ci:ec\",true,true,false]"
+
+#define CHAT_INIT_PARAMS(pvt) g_strdup_printf("prop=%s&fid=%s&ec=%s&pvt=%s",PROP,FID,EC,pvt)
+
+
+
+#endif /* _API_H */
diff --git a/libpurple/protocols/hangouts/auth.c b/libpurple/protocols/hangouts/auth.c
--- a/libpurple/protocols/hangouts/auth.c
+++ b/libpurple/protocols/hangouts/auth.c
@@ -20,6 +20,7 @@
  */
 
 #include "http.h"
+#include "http.c"
 #include "auth.h"
 
 #include <json-glib/json-glib.h>
@@ -44,8 +45,8 @@ typedef struct
 	gchar *redirect_uri;
 } _hangouts_oauth_token_request_data;
 
-static void
-hangouts_auth_with_authentication_code_cb(PurpleHttpConnection *http_conn,
+void
+hangouts_auth_with_authentication_code_cb(PurpleHttpConnection *gc,
 	PurpleHttpResponse *response, gpointer user_data){
 	purple_debug_misc("hangouts-prpl", "http req call back");
 
@@ -73,7 +74,7 @@ hangouts_auth_with_authentication_code_c
 
 
 	purple_debug_misc("hangouts-prpl", "response data: %s \n error: %s, token: %s",raw_res, error, access_token);
-
+	hangouts_auth_get_session_cookies(gc,access_token);
 
 }
 
@@ -111,8 +112,8 @@ hangouts_auth_with_authentication_code(P
 
 }
 
-static void
-hangouts_auth_with_refresh_token_cb(PurpleHttpConnection *http_conn,
+void
+hangouts_auth_with_refresh_token_cb(PurpleHttpConnection *gc,
 	PurpleHttpResponse *response, gpointer user_data){
 	purple_debug_misc("hangouts-prpl", "hangouts_auth_with_refresh_token");
 
@@ -136,6 +137,7 @@ hangouts_auth_with_refresh_token_cb(Purp
 
 	purple_debug_misc("hangouts-prpl", "response data: %s \n error: %s, token: %s",raw_res, error, access_token);
 
+	hangouts_auth_get_session_cookies(gc, access_token);
 
 }
 
@@ -146,7 +148,6 @@ hangouts_auth_with_refresh_token(PurpleC
 
 	gchar *request_data;
 	gchar *refresh_token;
-	PurpleAccount *account = purple_connection_get_account(gc);
 
 	request_data = g_strdup_printf(
 			"client_id=%s&"
@@ -170,4 +171,67 @@ hangouts_auth_with_refresh_token(PurpleC
 
 }
 
+void
+hangouts_auth_get_session_cookies_got_cb(PurpleHttpConnection *gc,
+		PurpleHttpResponse *response, gpointer user_data)
+{
+	purple_debug_misc("hangouts-prpl", "cookies_got");
+	gchar *raw = purple_http_response_get_data(response, NULL);
+	purple_debug_misc("hangouts-prpl", "cookies_got response: %s", raw);
 
+	PurpleHttpCookieJar *cookie_jar;
+
+	cookie_jar = purple_http_conn_get_cookie_jar(gc);
+
+	gchar *cookies = purple_http_cookie_jar_dump(cookie_jar);
+
+	purple_debug_misc("hangouts-prpl", "cookies: %s", cookies);
+}
+
+void
+hangouts_auth_get_session_cookies_uberauth_cb(PurpleHttpConnection *gc,
+		PurpleHttpResponse *response, gpointer user_data)
+{
+	purple_debug_misc("hangouts-prpl", "uberauth");
+	PurpleHttpRequest *request;
+	gchar *auth_data, *url, *uberauth;
+	//PurpleHttpCookieJar *cookie_jar;
+
+	uberauth = purple_http_response_get_data(response, NULL);
+	purple_debug_misc("hangouts-prpl", "uberauth: %s", uberauth);
+
+	auth_data = g_strdup_printf("Bearer %s",user_data);
+	url = g_strdup_printf("https://accounts.google.com/MergeSession?"
+			"service=mail&continue=http://www.google.com&uberauth=%s",uberauth);
+
+	request = purple_http_request_new(url);
+	purple_http_request_set_method(request,"GET");
+	purple_http_request_header_set(request,"Authorization",auth_data);
+	purple_http_request(gc,request,hangouts_auth_get_session_cookies_got_cb,NULL);
+
+}
+
+void
+hangouts_auth_get_session_cookies(PurpleConnection *gc, gchar* access_token)
+{
+	purple_debug_misc("hangouts-prpl", "cookies");
+	PurpleHttpRequest *request;
+	PurpleHttpKeepalivePool *keep_alive_pool;
+	gchar *auth_data;
+
+	//keep_alive_pool = purple_http_keepalive_pool_new();
+
+	auth_data = g_strdup_printf("Bearer %s",access_token);
+
+	request = purple_http_request_new("https://accounts.google.com/accounts/OAuthLogin"
+			"?source=hangups&issueuberauth=1");
+	purple_http_request_set_method(request,"GET");
+	purple_http_request_header_set(request,"Authorization",auth_data);
+	//purple_http_request_set_keepalive_pool(request, keep_alive_pool);
+
+	purple_http_request(gc,request,hangouts_auth_get_session_cookies_uberauth_cb,access_token);
+
+}
+
+
+
diff --git a/libpurple/protocols/hangouts/auth.h b/libpurple/protocols/hangouts/auth.h
--- a/libpurple/protocols/hangouts/auth.h
+++ b/libpurple/protocols/hangouts/auth.h
@@ -44,8 +44,14 @@ typedef struct _hangouts_oauth_token_req
 
 void hangouts_oauth_data_free(hangouts_oauth_data *data);
 void hangouts_auth_with_authentication_code(PurpleConnection *gc);
-static void hangouts_auth_with_authentication_code_cb(PurpleHttpConnection *http_conn,
+void hangouts_auth_with_authentication_code_cb(PurpleHttpConnection *gc,
 		PurpleHttpResponse *response, gpointer user_data);
 void hangouts_auth_with_refresh_token(PurpleConnection *gc);
+void hangouts_auth_get_session_cookies(PurpleConnection *gc, gchar *access_token);
+void hangouts_auth_get_session_cookies_uberauth_cb(PurpleHttpConnection *gc,
+		PurpleHttpResponse *response, gpointer user_data);
+
+void hangouts_auth_get_session_cookies_got_cb(PurpleHttpConnection *gc,
+		PurpleHttpResponse *response, gpointer user_data);
 
 #endif /* _AUTH_H_ */
diff --git a/libpurple/protocols/hangouts/hangouts.c b/libpurple/protocols/hangouts/hangouts.c
--- a/libpurple/protocols/hangouts/hangouts.c
+++ b/libpurple/protocols/hangouts/hangouts.c
@@ -49,6 +49,31 @@ hangouts_login(PurpleAccount *acct)
 	purple_debug_misc("hangouts-prpl", "login; account username: %s;",username);
 
 	hangouts_auth_with_authentication_code(gc);
+	//hangouts_auth_get_session_cookies(gc,"ya29.nQH0kem4ti_DiNx_10QYIi7i_-_sSX6wTB5psDX2HCrTMumch1sA9MH4W9vX1wjPKQ0DWI7YpPeyYg");
+
+	/*gchar *auth_data, *url, *uberauth;
+	PurpleHttpRequest *request;
+
+	uberauth = "APh-3FyMsmiJ992AFz_MyLg61JSKHEH_gNMB3j1QQjXqP-"
+			"t6yRNf0CcnTuv3V2MxXlEEUDtlqnKootkJV-a-hdiZvP7vE2ee"
+			"Ticearq7L_hNHM_Pspko2kXmCf6t6ACen-XU5jTsbY0ijXejX7g"
+			"3_W9r2sBBeNiMvoX-aqGYQ8tU7-oDFjy5r0ryA9oeyEwXuxMX9h"
+			"9vtkw04kHDkzrXvu-2VZDw-GshEK6FyFnNI8jf93TQuJAlDOsfug"
+			"9O0XgE0MUlpxrQK2MnovmekE4j46z8nGTJkLwg2faQn3SeX51CpW"
+			"tt6wT6Q9RP-HgkTjJ-Xh_JDZ7rvZKGDzJ9M2lqzzwWaPK5i1j-4ut"
+			"m8m8pl4TUd4pa-S4raVN_yBUdh7Saft9ctUNXHAJwIFynJxnSZ0G5o"
+			"yVBzslBYb4GG8olQStMStT5rynlmnH34gMzu5IW7Y9NpHHZbDYA2Kt-O"
+			"80GuKdl_xujLh3xS4dttx2K7Tbefy8LVqA5KiJL3kKW9rEFnMJzv7heF"
+			"zVBV0cnwiJg_JXstIt7rzSwyA";
+
+	auth_data = g_strdup_printf("Bearer %s","ya29.nQH0kem4ti_DiNx_10QYIi7i_-_sSX6wTB5psDX2HCrTMumch1sA9MH4W9vX1wjPKQ0DWI7YpPeyYg");
+	url = g_strdup_printf("https://accounts.google.com/MergeSession?"
+			"service=mail&continue=http://www.google.com&uberauth=%s",uberauth);
+
+	request = purple_http_request_new(url);
+	purple_http_request_set_method(request,"GET");
+	purple_http_request_header_set(request,"Authorization",auth_data);
+	purple_http_request(gc,request,hangouts_auth_get_session_cookies_got_cb,NULL);*/
 
 }
 



More information about the Commits mailing list