source: lib/oauth.h @ f7d12f7

Last change on this file since f7d12f7 was 3b878a1, checked in by Wilmer van der Gaast <wilmer@…>, at 2010-05-02T21:20:09Z

OAuth sanity fix: Twitter-specific stuff should *not* be in lib/oauth.c.
Somewhat intrusive, should've done this right immediately. :-/

  • Property mode set to 100644
File size: 3.7 KB
Line 
1/***************************************************************************\
2*                                                                           *
3*  BitlBee - An IRC to IM gateway                                           *
4*  Simple OAuth client (consumer) implementation.                           *
5*                                                                           *
6*  Copyright 2010 Wilmer van der Gaast <wilmer@gaast.net>                   *
7*                                                                           *
8*  This program is free software; you can redistribute it and/or modify     *
9*  it under the terms of the GNU General Public License as published by     *
10*  the Free Software Foundation; either version 2 of the License, or        *
11*  (at your option) any later version.                                      *
12*                                                                           *
13*  This program is distributed in the hope that it will be useful,          *
14*  but WITHOUT ANY WARRANTY; without even the implied warranty of           *
15*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            *
16*  GNU General Public License for more details.                             *
17*                                                                           *
18*  You should have received a copy of the GNU General Public License along  *
19*  with this program; if not, write to the Free Software Foundation, Inc.,  *
20*  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.              *
21*                                                                           *
22\***************************************************************************/
23
24/* http://oauth.net/core/1.0a/ */
25
26struct oauth_info;
27
28/* Callback function called twice during the access token request process.
29   Return FALSE if something broke and the process must be aborted. */
30typedef gboolean (*oauth_cb)( struct oauth_info * );
31
32typedef enum
33{
34        OAUTH_INIT,
35        OAUTH_REQUEST_TOKEN,
36        OAUTH_ACCESS_TOKEN,
37} oauth_stage_t;
38
39struct oauth_info
40{
41        oauth_stage_t stage;
42        const struct oauth_service *sp;
43       
44        oauth_cb func;
45        void *data;
46       
47        struct http_request *http;
48       
49        char *auth_url;
50        char *request_token;
51       
52        char *token;
53        char *token_secret;
54};
55
56struct oauth_service
57{
58        char *url_request_token;
59        char *url_access_token;
60        char *url_authorize;
61       
62        char *consumer_key;
63        char *consumer_secret;
64};
65
66/* http://oauth.net/core/1.0a/#auth_step1 (section 6.1)
67   Request an initial anonymous token which can be used to construct an
68   authorization URL for the user. This is passed to the callback function
69   in a struct oauth_info. */
70struct oauth_info *oauth_request_token( const struct oauth_service *sp, oauth_cb func, void *data );
71
72/* http://oauth.net/core/1.0a/#auth_step3 (section 6.3)
73   The user gets a PIN or so which we now exchange for the final access
74   token. This is passed to the callback function in the same
75   struct oauth_info. */
76gboolean oauth_access_token( const char *pin, struct oauth_info *st );
77
78/* http://oauth.net/core/1.0a/#anchor12 (section 7)
79   Generate an OAuth Authorization: HTTP header. access_token should be
80   saved/fetched using the functions above. args can be a string with
81   whatever's going to be in the POST body of the request. GET args will
82   automatically be grabbed from url. */
83char *oauth_http_header( struct oauth_info *oi, const char *method, const char *url, char *args );
84
85/* Shouldn't normally be required unless the process is aborted by the user. */
86void oauth_info_free( struct oauth_info *info );
87
88/* Convert to and back from strings, for easier saving. */
89char *oauth_to_string( struct oauth_info *oi );
90struct oauth_info *oauth_from_string( char *in, const struct oauth_service *sp );
Note: See TracBrowser for help on using the repository browser.