From: Menno Smits Date: Sun, 4 Nov 2012 23:08:56 +0000 (+0000) Subject: Committed Zac Witte's patch for OAUTH2 support X-Git-Tag: 0.9.1~5 X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=632f3f9aa743ba7bdc3eec746c73323ea161222f;p=imapclient.git Committed Zac Witte's patch for OAUTH2 support ... and some related clean-ups. --- diff --git a/NEWS b/NEWS index 804b4b1..91166af 100644 --- a/NEWS +++ b/NEWS @@ -13,6 +13,11 @@ run. 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 diff --git a/THANKS b/THANKS index d92d524..b1ef28a 100644 --- a/THANKS +++ b/THANKS @@ -35,6 +35,9 @@ Brian Neal Dave Eckhardt Stream connection support. +Zac Witte + OAUTH2 support. + Bug Reports ------------ Brian Jackson diff --git a/imapclient/imapclient.py b/imapclient/imapclient.py index 1b64054..e135dfd 100644 --- a/imapclient/imapclient.py +++ b/imapclient/imapclient.py @@ -12,7 +12,7 @@ from operator import itemgetter import imaplib import response_lexer - +# Confusingly, this module is for OAUTH v1, not v2 try: import oauth2 except ImportError: @@ -132,7 +132,7 @@ class IMAPClient(object): 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) @@ -140,7 +140,15 @@ class IMAPClient(object): 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.