]> khamidou — GitHub mirrors - imapclient.git/commitdiff
Add an optional 'vendor' param to the XOAUTH2 payload, as Yahoo now requires
authorPhil Peterson <php@contextengines.com>
Fri, 9 Jan 2015 01:51:37 +0000 (17:51 -0800)
committerPhil Peterson <php@contextengines.com>
Fri, 9 Jan 2015 01:51:37 +0000 (17:51 -0800)
imapclient/imapclient.py

index 7c85bbdb4837637d6dd37a372c16a0a4a32347b4..787ceb190f5577bd9ca075922f0cedcdb6d5af36 100644 (file)
@@ -151,12 +151,16 @@ class IMAPClient(object):
         else:
             raise self.Error('The optional oauth2 package is needed for OAUTH authentication')
 
-    def oauth2_login(self, user, access_token, mech='XOAUTH2'):
+    def oauth2_login(self, user, access_token, mech='XOAUTH2', vendor=None):
         """Authenticate using the OAUTH2 method.
 
-        Gmail supports the 'XOAUTH2' SASL mechanism, but Yahoo! supports 'OAUTH2'
+        Gmail and Yahoo both support the 'XOAUTH2' mechanism, but Yahoo requires 
+        the 'vendor' portion in the payload. 
         """
-        auth_string = lambda x: 'user=%s\1auth=Bearer %s\1\1' % (user, access_token)
+        if vendor:
+            auth_string = lambda x: 'user=%s\1auth=Bearer %s\1vendor=%s\1\1' % (user, access_token, vendor)
+        else:
+            auth_string = lambda x: 'user=%s\1auth=Bearer %s\1\1' % (user, access_token)
         return self._command_and_check('authenticate', mech, auth_string)
 
     def logout(self):