From: Phil Peterson Date: Mon, 15 Dec 2014 17:27:02 +0000 (-0800) Subject: Parameterize the SASL mechanism for OAuth2 login so it works for Yahoo (OAUTH2) as... X-Git-Tag: 0.12^2~7^2~1 X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=e1dda8292d562f84201f228241fcc723266b2f43;p=imapclient.git Parameterize the SASL mechanism for OAuth2 login so it works for Yahoo (OAUTH2) as well as Gmail (XOAUTH2) --- diff --git a/imapclient/imapclient.py b/imapclient/imapclient.py index 8928d14..7c85bbd 100644 --- a/imapclient/imapclient.py +++ b/imapclient/imapclient.py @@ -151,13 +151,13 @@ class IMAPClient(object): else: raise self.Error('The optional oauth2 package is needed for OAUTH authentication') - def oauth2_login(self, user, access_token): + def oauth2_login(self, user, access_token, mech='XOAUTH2'): """Authenticate using the OAUTH2 method. - This only works with IMAP servers that support OAUTH2 (e.g. Gmail). + Gmail supports the 'XOAUTH2' SASL mechanism, but Yahoo! supports 'OAUTH2' """ auth_string = lambda x: 'user=%s\1auth=Bearer %s\1\1' % (user, access_token) - return self._command_and_check('authenticate', 'XOAUTH2', auth_string) + return self._command_and_check('authenticate', mech, auth_string) def logout(self): """Logout, returning the server response.