/soc/2015/nakulgulati/main: 45e2026c6118: Auth API

Nakul at rock.pidgin.im Nakul at rock.pidgin.im
Tue Jun 23 02:53:40 EDT 2015


Changeset: 45e2026c61180b0a5f604214e527a396af996672
Author:	 Nakul Gulati
Date:	 2015-06-18 18:42 +0800
Branch:	 hangouts
URL: https://hg.pidgin.im/soc/2015/nakulgulati/main/rev/45e2026c6118

Description:

Auth API

diffstat:

 libpurple/protocols/hangouts/Makefile.am    |    2 +
 libpurple/protocols/hangouts/Makefile.mingw |   80 +++++++++++++++++++
 libpurple/protocols/hangouts/auth.c         |   53 ++++++++++++
 libpurple/protocols/hangouts/auth.h         |   46 +++++++++++
 libpurple/protocols/hangouts/hangouts.c     |  115 +++++++++++++++++++--------
 5 files changed, 262 insertions(+), 34 deletions(-)

diffs (truncated from 391 to 300 lines):

diff --git a/libpurple/protocols/hangouts/Makefile.am b/libpurple/protocols/hangouts/Makefile.am
--- a/libpurple/protocols/hangouts/Makefile.am
+++ b/libpurple/protocols/hangouts/Makefile.am
@@ -4,6 +4,8 @@
 pkgdir = @PURPLE_PLUGINDIR@
 
 HANGOUTSSOURCES = \
+	auth.h \
+	auth.c \
 	hangouts.h \
 	hangouts.c
 
diff --git a/libpurple/protocols/hangouts/Makefile.mingw b/libpurple/protocols/hangouts/Makefile.mingw
new file mode 100644
--- /dev/null
+++ b/libpurple/protocols/hangouts/Makefile.mingw
@@ -0,0 +1,80 @@
+#
+# Makefile.mingw
+#
+# Description: Makefile for win32 (mingw) version of libhangouts
+#
+
+PIDGIN_TREE_TOP := ../../..
+include $(PIDGIN_TREE_TOP)/libpurple/win32/global.mak
+
+TARGET = libnovell
+TYPE = PLUGIN
+
+# Static or Plugin...
+ifeq ($(TYPE),STATIC)
+  DEFINES += -DSTATIC
+  DLL_INSTALL_DIR =	$(PURPLE_INSTALL_DIR)
+else
+ifeq ($(TYPE),PLUGIN)
+  DLL_INSTALL_DIR =	$(PURPLE_INSTALL_PLUGINS_DIR)
+endif
+endif
+
+##
+## INCLUDE PATHS
+##
+INCLUDE_PATHS +=	-I. \
+			-I$(GTK_TOP)/include \
+			-I$(GTK_TOP)/include/glib-2.0 \
+			-I$(GTK_TOP)/lib/glib-2.0/include \
+			-I$(PURPLE_TOP) \
+			-I$(PURPLE_TOP)/win32 \
+			-I$(PIDGIN_TREE_TOP)
+
+LIB_PATHS +=		-L$(GTK_TOP)/lib \
+			-L$(PURPLE_TOP)
+
+##
+##  SOURCES, OBJECTS
+##
+C_SRC =	\
+			auth.c
+			hangouts.c
+
+OBJECTS = $(C_SRC:%.c=%.o)
+
+##
+## LIBRARIES
+##
+LIBS =	\
+			-lglib-2.0 \
+			-lgobject-2.0 \
+			-lws2_32 \
+			-lintl \
+			-lpurple
+
+include $(PIDGIN_COMMON_RULES)
+
+##
+## TARGET DEFINITIONS
+##
+.PHONY: all install clean
+
+all: $(TARGET).dll
+
+install: all $(DLL_INSTALL_DIR)
+	cp $(TARGET).dll $(DLL_INSTALL_DIR)
+
+$(OBJECTS): $(PURPLE_CONFIG_H)
+
+$(TARGET).dll: $(PURPLE_DLL).a $(OBJECTS)
+	$(CC) -shared $(OBJECTS) $(LIB_PATHS) $(LIBS) $(DLL_LD_FLAGS) -o $(TARGET).dll
+
+##
+## CLEAN RULES
+##
+clean:
+	rm -f $(OBJECTS)
+	rm -f $(TARGET).dll
+
+include $(PIDGIN_COMMON_TARGETS)
diff --git a/libpurple/protocols/hangouts/auth.c b/libpurple/protocols/hangouts/auth.c
new file mode 100644
--- /dev/null
+++ b/libpurple/protocols/hangouts/auth.c
@@ -0,0 +1,53 @@
+/* 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 "http.h"
+#include "auth.h"
+
+typedef struct
+{
+	PurpleConnection *gc;
+	gpointer user_data;
+	gchar *token;
+	gchar *token_secret;
+
+	gchar *sign_method, *sign_url;
+} _hangouts_oauth_data;
+
+typedef struct
+{
+	PurpleConnection *gc;
+	gpointer user_data;
+	gchar *client_id;
+	gchar *client_secret;
+	gchar *authorization_code;
+	gchar *redirect_uri;
+} _hangouts_oauth_token_request_data;
+
+
+void
+hangouts_request_auth(PurpleConnection *gc)
+{
+
+}
+
+
+
diff --git a/libpurple/protocols/hangouts/auth.h b/libpurple/protocols/hangouts/auth.h
new file mode 100644
--- /dev/null
+++ b/libpurple/protocols/hangouts/auth.h
@@ -0,0 +1,46 @@
+/* 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 _AUTH_H_
+#define _AUTH_H_
+
+#define OAUTH2_SCOPE "https://www.google.com/accounts/OAuthLogin"
+#define OAUTH2_CLIENT_ID "936475272427.apps.googleusercontent.com"
+#define OAUTH2_CLIENT_SECRET "KWsJlkaMn1jGLxQpWxMnOox-"
+#define OAUTH2_REDIRECT_URI "urn:ietf:wg:oauth:2.0:oob"
+
+#define OAUTH2_LOGIN_URL "https://accounts.google.com/o/oauth2/auth?\
+response_type=code&\
+redirect_uri=" OAUTH2_REDIRECT_URI \
+"&client_id=" OAUTH2_CLIENT_ID "&scope=" OAUTH2_SCOPE
+
+#define OAUTH2_TOKEN_REQUEST_URL "https://accounts.google.com/o/oauth2/token"
+#define OAUTH2_GRANT_TYPE "authorization_code"
+
+
+typedef struct _hangouts_oauth_data hangouts_oauth_data;
+
+typedef struct _hangouts_oauth_token_request_data hangouts_oauth_token_request_data;
+
+
+void hangouts_oauth_data_free(hangouts_oauth_data *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
@@ -23,6 +23,7 @@
 
 #include "account.h"
 #include "connection.h"
+#include "http.h"
 #include "plugins.h"
 #include "protocol.h"
 #include "protocols.h"
@@ -30,16 +31,61 @@
 #include "version.h"
 
 #include "hangouts.h"
+#include "auth.h"
 
-static PurpleProtocol *my_protocol = NULL;
+static PurpleProtocol *_hangouts_protocol = NULL;
+
+static void hangouts_http_req_cb(PurpleHttpConnection *http_conn,
+	PurpleHttpResponse *response, gpointer user_data){
+	purple_debug_misc("hangouts-prpl", "http req call back");
+
+	gchar *raw_res = purple_http_response_get_data(response,NULL);
+	purple_debug_misc("hangouts-prpl", "response data: %s",raw_res);
+
+}
 
 static void
 hangouts_login(PurpleAccount *acct)
 {
-	PurpleConnection *gc = purple_account_get_connection(acct);
-	const char *username = purple_account_get_username(acct);
+	const gchar *username;
+	const gchar *pass;
 
-	printf("Account connected: \"%s\" (%s)\n", username, purple_account_get_protocol_id(acct));
+	PurpleConnection *gc;
+	gc = purple_account_get_connection(acct);
+
+	username = purple_account_get_username(acct);
+
+	purple_debug_misc("hangouts-prpl", "login; account username: %s;",username);
+	/*purple_signal_connect(purple_accounts_get_handle(), "account-connecting",
+							plugin, PURPLE_CALLBACK(account_connecting_cb), NULL);
+*/
+
+	//http login request
+
+	gchar *request_data;
+
+	request_data = g_strdup_printf(
+			"client_id=%s&"
+			"client_secret=%s&"
+			"code=%s&"
+			"grant_type=%s&"
+			"redirect_uri=%s",
+			OAUTH2_CLIENT_ID,
+			OAUTH2_CLIENT_SECRET,
+			"4/NfxMyTwRc0cVmSOZ0W-6hwOISSoQIvgGQgOHTzZBYdM",
+			OAUTH2_GRANT_TYPE,
+			OAUTH2_REDIRECT_URI);
+
+	/*PurpleHttpURL *login_url = purple_http_url_parse(OAUTH2_LOGIN_URL);*/
+	PurpleHttpRequest *request;
+	const char *method = "POST";
+
+	request = purple_http_request_new(OAUTH2_TOKEN_REQUEST_URL);
+	purple_http_request_set_method(request,method);
+	purple_http_request_header_set(request, "Content-Type", "application/x-www-form-urlencoded");
+	purple_http_request_set_contents(request, request_data, -1);
+
+	purple_http_request(gc,request,hangouts_http_req_cb,NULL);
 
 
 }
@@ -71,23 +117,24 @@ hangouts_status_types(PurpleAccount *acc
 static const char *
 hangouts_list_icon(PurpleAccount *account, PurpleBuddy *buddy)
 {
- return "hangouts";
+	return "hangouts";
 }
 
 static void
 hangouts_protocol_init(PurpleProtocol *protocol)
 {
- protocol->id   = "prpl-hangouts";
- protocol->name = "Hangouts";
+	protocol->id   = "prpl-hangouts";
+	protocol->name = "Hangouts";
+	purple_debug_misc("hangouts-prpl", "init");
 }



More information about the Commits mailing list