| | 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') |