]> khamidou — GitHub mirrors - imapclient.git/commitdiff
Committed Zac Witte's patch for OAUTH2 support
authorMenno Smits <menno@freshfoo.com>
Sun, 4 Nov 2012 23:08:56 +0000 (23:08 +0000)
committerMenno Smits <menno@freshfoo.com>
Sun, 4 Nov 2012 23:08:56 +0000 (23:08 +0000)
... and some related clean-ups.

NEWS
THANKS
imapclient/imapclient.py

diff --git a/NEWS b/NEWS
index 804b4b1eb0ab1d5344bf7f80117c87b53dc4c8ec..91166afe074e245726e9f570cfebf1d6e2554251 100644 (file)
--- 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 d92d52404f13baab57b809a5a707ee48de17247b..b1ef28a4ff2539732f2878b85d495537e70e8b09 100644 (file)
--- a/THANKS
+++ b/THANKS
@@ -35,6 +35,9 @@ Brian Neal
 Dave Eckhardt
     Stream connection support.
 
+Zac Witte
+    OAUTH2 support.
+    
 Bug Reports
 ------------
 Brian Jackson
index 1b640540603ab10a5c84eafc19fd3a7b8b6e6bec..e135dfd3e3f21932dc81ccdf98dc6948f3e9d5e6 100644 (file)
@@ -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.