From 57b4525653972dc23c8c5ca5ffaa7e44fad64ee9 Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Fri, 22 Jul 2011 19:29:25 +0100 Subject: Nothing useful yet, this just generates an auth URL. Things to do: Ability to process the answer. This is hard because the GTalk server will time out very quickly which means we lose our state/scope/etc. (And the ability to even receive the answer, at least if I'd do this the same way the Twitter module does it.) And then, get the access token and use it, of course. :-) --- lib/oauth2.h | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 lib/oauth2.h (limited to 'lib/oauth2.h') diff --git a/lib/oauth2.h b/lib/oauth2.h new file mode 100644 index 00000000..c2985ef6 --- /dev/null +++ b/lib/oauth2.h @@ -0,0 +1,69 @@ +/***************************************************************************\ +* * +* BitlBee - An IRC to IM gateway * +* Simple OAuth client (consumer) implementation. * +* * +* Copyright 2010-2011 Wilmer van der Gaast * +* * +* 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 02110-1301 USA. * +* * +\***************************************************************************/ + +struct oauth2_info; + +/* Callback function called twice during the access token request process. + Return FALSE if something broke and the process must be aborted. */ +typedef gboolean (*oauth_cb)( struct oauth2_info * ); + +struct oauth2_info +{ + const struct oauth_service *sp; + + oauth_cb func; + void *data; + + struct http_request *http; + +// char *auth_url; +// char *request_token; + +// char *token; +// char *token_secret; +// GSList *params; +}; + +struct oauth2_service +{ + char *base_url; + char *consumer_key; + char *consumer_secret; +}; + +extern struct oauth2_service oauth2_service_google; + +/* http://oauth.net/core/1.0a/#auth_step1 (section 6.1) + Request an initial anonymous token which can be used to construct an + authorization URL for the user. This is passed to the callback function + in a struct oauth2_info. */ +char *oauth2_url( const struct oauth2_service *sp, const char *scope ); + +/* http://oauth.net/core/1.0a/#auth_step3 (section 6.3) + The user gets a PIN or so which we now exchange for the final access + token. This is passed to the callback function in the same + struct oauth2_info. */ +gboolean oauth2_access_token( const char *pin, struct oauth2_info *st ); + +/* Shouldn't normally be required unless the process is aborted by the user. */ +void oauth2_info_free( struct oauth2_info *info ); -- cgit v1.2.3 From 4a5d88504235e1df5d01a3a5701b83dd82d6695d Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Tue, 26 Jul 2011 12:58:38 +0100 Subject: Working OAuth2 support. Needs some more debugging (error handling is not great and imc_logout() gets (rightfully) confused when jabber_data is empty). --- lib/oauth2.h | 50 ++++++++++++++++---------------------------------- 1 file changed, 16 insertions(+), 34 deletions(-) (limited to 'lib/oauth2.h') diff --git a/lib/oauth2.h b/lib/oauth2.h index c2985ef6..657a0ab3 100644 --- a/lib/oauth2.h +++ b/lib/oauth2.h @@ -1,7 +1,7 @@ /***************************************************************************\ * * * BitlBee - An IRC to IM gateway * -* Simple OAuth client (consumer) implementation. * +* Simple OAuth2 client (consumer) implementation. * * * * Copyright 2010-2011 Wilmer van der Gaast * * * @@ -21,28 +21,10 @@ * * \***************************************************************************/ -struct oauth2_info; +/* Implementation mostly based on my experience with writing the previous OAuth + module, and from http://code.google.com/apis/accounts/docs/OAuth2.html . */ -/* Callback function called twice during the access token request process. - Return FALSE if something broke and the process must be aborted. */ -typedef gboolean (*oauth_cb)( struct oauth2_info * ); - -struct oauth2_info -{ - const struct oauth_service *sp; - - oauth_cb func; - void *data; - - struct http_request *http; - -// char *auth_url; -// char *request_token; - -// char *token; -// char *token_secret; -// GSList *params; -}; +typedef void (*oauth2_token_callback)( gpointer data, const char *atoken, const char *rtoken ); struct oauth2_service { @@ -51,19 +33,19 @@ struct oauth2_service char *consumer_secret; }; +/* Currently suitable for authenticating to Google Talk only, and only for + accounts that have 2-factor authorization enabled. */ extern struct oauth2_service oauth2_service_google; -/* http://oauth.net/core/1.0a/#auth_step1 (section 6.1) - Request an initial anonymous token which can be used to construct an - authorization URL for the user. This is passed to the callback function - in a struct oauth2_info. */ -char *oauth2_url( const struct oauth2_service *sp, const char *scope ); +#define OAUTH2_AUTH_CODE "authorization_code" +#define OAUTH2_AUTH_REFRESH "refresh_token" -/* http://oauth.net/core/1.0a/#auth_step3 (section 6.3) - The user gets a PIN or so which we now exchange for the final access - token. This is passed to the callback function in the same - struct oauth2_info. */ -gboolean oauth2_access_token( const char *pin, struct oauth2_info *st ); +/* Generate a URL the user should open in his/her browser to get an + authorization code. */ +char *oauth2_url( const struct oauth2_service *sp, const char *scope ); -/* Shouldn't normally be required unless the process is aborted by the user. */ -void oauth2_info_free( struct oauth2_info *info ); +/* Exchanges an auth code or refresh token for an access token. + auth_type is one of the two OAUTH2_AUTH_.. constants above. */ +int oauth2_access_token( const struct oauth2_service *sp, + const char *auth_type, const char *auth, + oauth2_token_callback func, gpointer data ); -- cgit v1.2.3 From 39a939ce4ef6717d65c36c97e6a7adf05b125cad Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Sun, 31 Jul 2011 15:55:00 +0100 Subject: oauth2 changes to address http://twitter.com/Wilmer/status/96715400124968960 --- lib/oauth2.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'lib/oauth2.h') diff --git a/lib/oauth2.h b/lib/oauth2.h index 657a0ab3..6f56b426 100644 --- a/lib/oauth2.h +++ b/lib/oauth2.h @@ -28,7 +28,9 @@ typedef void (*oauth2_token_callback)( gpointer data, const char *atoken, const struct oauth2_service { - char *base_url; + char *auth_url; + char *token_url; + char *redirect_url; char *consumer_key; char *consumer_secret; }; @@ -37,6 +39,8 @@ struct oauth2_service accounts that have 2-factor authorization enabled. */ extern struct oauth2_service oauth2_service_google; +extern struct oauth2_service oauth2_service_facebook; + #define OAUTH2_AUTH_CODE "authorization_code" #define OAUTH2_AUTH_REFRESH "refresh_token" -- cgit v1.2.3 From 18c6d369d777a1d38ef450f868c22de1d0ebba2d Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Sun, 18 Dec 2011 20:25:44 +0100 Subject: More generic OAuth support now. Should work well for all GTalk accounts now and somewhat for MS Messenger. The fb part needs different parsing of the authorize request, and possibly some other work. --- lib/oauth2.h | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) (limited to 'lib/oauth2.h') diff --git a/lib/oauth2.h b/lib/oauth2.h index 6f56b426..c8d18963 100644 --- a/lib/oauth2.h +++ b/lib/oauth2.h @@ -31,22 +31,17 @@ struct oauth2_service char *auth_url; char *token_url; char *redirect_url; + char *scope; char *consumer_key; char *consumer_secret; }; -/* Currently suitable for authenticating to Google Talk only, and only for - accounts that have 2-factor authorization enabled. */ -extern struct oauth2_service oauth2_service_google; - -extern struct oauth2_service oauth2_service_facebook; - #define OAUTH2_AUTH_CODE "authorization_code" #define OAUTH2_AUTH_REFRESH "refresh_token" /* Generate a URL the user should open in his/her browser to get an authorization code. */ -char *oauth2_url( const struct oauth2_service *sp, const char *scope ); +char *oauth2_url( const struct oauth2_service *sp ); /* Exchanges an auth code or refresh token for an access token. auth_type is one of the two OAUTH2_AUTH_.. constants above. */ -- cgit v1.2.3