Changeset 4a5d885 for lib/oauth2.h


Ignore:
Timestamp:
2011-07-26T11:58:38Z (9 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Branches:
master
Children:
1174899
Parents:
59c9adb
Message:

Working OAuth2 support. Needs some more debugging (error handling is not
great and imc_logout() gets (rightfully) confused when jabber_data is empty).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • lib/oauth2.h

    r59c9adb r4a5d885  
    22*                                                                           *
    33*  BitlBee - An IRC to IM gateway                                           *
    4 *  Simple OAuth client (consumer) implementation.                           *
     4*  Simple OAuth2 client (consumer) implementation.                          *
    55*                                                                           *
    66*  Copyright 2010-2011 Wilmer van der Gaast <wilmer@gaast.net>              *
     
    2222\***************************************************************************/
    2323
    24 struct oauth2_info;
     24/* Implementation mostly based on my experience with writing the previous OAuth
     25   module, and from http://code.google.com/apis/accounts/docs/OAuth2.html . */
    2526
    26 /* Callback function called twice during the access token request process.
    27    Return FALSE if something broke and the process must be aborted. */
    28 typedef gboolean (*oauth_cb)( struct oauth2_info * );
    29 
    30 struct oauth2_info
    31 {
    32         const struct oauth_service *sp;
    33        
    34         oauth_cb func;
    35         void *data;
    36        
    37         struct http_request *http;
    38        
    39 //      char *auth_url;
    40 //      char *request_token;
    41        
    42 //      char *token;
    43 //      char *token_secret;
    44 //      GSList *params;
    45 };
     27typedef void (*oauth2_token_callback)( gpointer data, const char *atoken, const char *rtoken );
    4628
    4729struct oauth2_service
     
    5234};
    5335
     36/* Currently suitable for authenticating to Google Talk only, and only for
     37   accounts that have 2-factor authorization enabled. */
    5438extern struct oauth2_service oauth2_service_google;
    5539
    56 /* http://oauth.net/core/1.0a/#auth_step1 (section 6.1)
    57    Request an initial anonymous token which can be used to construct an
    58    authorization URL for the user. This is passed to the callback function
    59    in a struct oauth2_info. */
     40#define OAUTH2_AUTH_CODE "authorization_code"
     41#define OAUTH2_AUTH_REFRESH "refresh_token"
     42
     43/* Generate a URL the user should open in his/her browser to get an
     44   authorization code. */
    6045char *oauth2_url( const struct oauth2_service *sp, const char *scope );
    6146
    62 /* http://oauth.net/core/1.0a/#auth_step3 (section 6.3)
    63    The user gets a PIN or so which we now exchange for the final access
    64    token. This is passed to the callback function in the same
    65    struct oauth2_info. */
    66 gboolean oauth2_access_token( const char *pin, struct oauth2_info *st );
    67 
    68 /* Shouldn't normally be required unless the process is aborted by the user. */
    69 void oauth2_info_free( struct oauth2_info *info );
     47/* Exchanges an auth code or refresh token for an access token.
     48   auth_type is one of the two OAUTH2_AUTH_.. constants above. */
     49int oauth2_access_token( const struct oauth2_service *sp,
     50                         const char *auth_type, const char *auth,
     51                         oauth2_token_callback func, gpointer data );
Note: See TracChangeset for help on using the changeset viewer.