aboutsummaryrefslogtreecommitdiffstats
path: root/lib/oauth2.h
diff options
context:
space:
mode:
Diffstat (limited to 'lib/oauth2.h')
-rw-r--r--lib/oauth2.h50
1 files changed, 16 insertions, 34 deletions
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 <wilmer@gaast.net> *
* *
@@ -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 );