1 | /***************************************************************************\ |
---|
2 | * * |
---|
3 | * BitlBee - An IRC to IM gateway * |
---|
4 | * Simple OAuth2 client (consumer) implementation. * |
---|
5 | * * |
---|
6 | * Copyright 2010-2011 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 | /* Implementation mostly based on my experience with writing the previous OAuth |
---|
25 | module, and from http://code.google.com/apis/accounts/docs/OAuth2.html . */ |
---|
26 | |
---|
27 | typedef void (*oauth2_token_callback)( gpointer data, const char *atoken, const char *rtoken ); |
---|
28 | |
---|
29 | struct oauth2_service |
---|
30 | { |
---|
31 | char *base_url; |
---|
32 | char *consumer_key; |
---|
33 | char *consumer_secret; |
---|
34 | }; |
---|
35 | |
---|
36 | /* Currently suitable for authenticating to Google Talk only, and only for |
---|
37 | accounts that have 2-factor authorization enabled. */ |
---|
38 | extern struct oauth2_service oauth2_service_google; |
---|
39 | |
---|
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. */ |
---|
45 | char *oauth2_url( const struct oauth2_service *sp, const char *scope ); |
---|
46 | |
---|
47 | /* Exchanges an auth code or refresh token for an access token. |
---|
48 | auth_type is one of the two OAUTH2_AUTH_.. constants above. */ |
---|
49 | int oauth2_access_token( const struct oauth2_service *sp, |
---|
50 | const char *auth_type, const char *auth, |
---|
51 | oauth2_token_callback func, gpointer data ); |
---|