Thanks to Dave Eckhardt for the original patch.
+OAUTH2 Support [NEW]
+--------------------
+OAUTH2 authentication (as supported by Gmail's IMAP) is now available
+via the new oauth2_login method. Thanks to Zac Witte for the original
+patch.
=====
0.9
import imaplib
import response_lexer
-
+# Confusingly, this module is for OAUTH v1, not v2
try:
import oauth2
except ImportError:
consumer_key='anonymous', consumer_secret='anonymous'):
"""Authenticate using the OAUTH method.
- This only works with IMAP servers that support OAUTH (eg. Gmail).
+ This only works with IMAP servers that support OAUTH (e.g. Gmail).
"""
if oauth2:
token = oauth2.Token(oauth_token, oauth_token_secret)
xoauth_callable = lambda x: oauth2.build_xoauth_string(url, consumer, token)
return self._command_and_check('authenticate', 'XOAUTH', xoauth_callable, unpack=True)
else:
- raise self.Error('The optional oauth2 dependency is needed for oauth authentication')
+ raise self.Error('The optional oauth2 dependency is needed for OAUTH authentication')
+
+ def oauth2_login(self, user, access_token):
+ """Authenticate using the OAUTH2 method.
+
+ This only works with IMAP servers that support OAUTH2 (e.g. Gmail).
+ """
+ auth_string = lambda x: 'user=%s\1auth=Bearer %s\1\1' % (user, access_token)
+ return self._command_and_check('authenticate', 'XOAUTH2', auth_string)
def logout(self):
"""Logout, returning the server response.