]> khamidou — GitHub mirrors - imapclient.git/commitdiff
Cleaned up OAUTH2 auth string generation
authorMenno Smits <menno@freshfoo.com>
Mon, 12 Jan 2015 10:34:55 +0000 (23:34 +1300)
committerMenno Smits <menno@freshfoo.com>
Mon, 12 Jan 2015 10:34:55 +0000 (23:34 +1300)
imapclient/imapclient.py

index 5dabe2ac4bfacb61ae1d41d5ece64e6ddcc1bfd7..ee2bc7fd968a8e35bb3fa88eb5062cc14e53ac4f 100644 (file)
@@ -168,14 +168,14 @@ class IMAPClient(object):
     def oauth2_login(self, user, access_token, mech='XOAUTH2', vendor=None):
         """Authenticate using the OAUTH2 method.
 
-        Gmail and Yahoo both support the 'XOAUTH2' mechanism, but Yahoo requires 
+        Gmail and Yahoo both support the 'XOAUTH2' mechanism, but Yahoo requires
         the 'vendor' portion in the payload. 
         """
+        auth_string = 'user=%s\1auth=Bearer %s\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)
+            auth_string += 'vendor=%s\1' % vendor
+        auth_string += '\1'
+        return self._command_and_check('authenticate', mech, lambda x: auth_string)
 
     def logout(self):
         """Logout, returning the server response.