Changeset 207:835686a87307
- Timestamp:
- 03/23/11 00:43:05 (14 months ago)
- Author:
- Johannes Heckel <stone.pixel@…>
- Branch:
- oauth
- Children:
- 209:80f530da50d7, 213:8e81638b42ec
- Message:
-
Implemented oauth authentication using oauth2.
Also added an example to demonstrate the new oauth_login function's use.
- Location:
- imapclient
- Files:
-
Legend:
- Unmodified
- Added
- Removed
-
|
r204
|
r207
|
|
| 9 | 9 | import warnings |
| 10 | 10 | #imaplib.Debug = 5 |
| | 11 | |
| | 12 | try: |
| | 13 | import oauth2 |
| | 14 | except ImportError: |
| | 15 | oauth2 = None |
| 11 | 16 | |
| 12 | 17 | import imap_utf7 |
| … |
… |
|
| 113 | 118 | return data[0] |
| 114 | 119 | |
| | 120 | def oauth_login(self, url, oauth_token, oauth_token_secret, |
| | 121 | consumer_key='anonymous', consumer_secret='anonymous'): |
| | 122 | """Authenticate using oauth. |
| | 123 | |
| | 124 | @param url: The OAuth request URL. |
| | 125 | @param oauth_token: An OAuth key. |
| | 126 | @param oauth_token_secret: An OAuth secret. |
| | 127 | @param consumer_key: An OAuth consumer key (defaults to 'anonymous'). |
| | 128 | @param consumer_secret: An OAuth consumer secret (defaults to 'anonymous'). |
| | 129 | """ |
| | 130 | if oauth2: |
| | 131 | token = oauth2.Token(oauth_token, oauth_token_secret) |
| | 132 | consumer = oauth2.Consumer(consumer_key, consumer_secret) |
| | 133 | xoauth_callable = lambda x: oauth2.build_xoauth_string(url, consumer, token) |
| | 134 | |
| | 135 | typ, data = self._imap.authenticate('XOAUTH', xoauth_callable) |
| | 136 | self._checkok('authenticate', typ, data) |
| | 137 | return data[0] |
| | 138 | else: |
| | 139 | raise self.Error('The optional oauth2 dependency is needed for oauth authentication') |
| 115 | 140 | |
| 116 | 141 | def logout(self): |