示例#1
0
    def authenticate(self, url, consumer, token):
        if consumer is not None and not isinstance(consumer, oauth2.Consumer):
            raise ValueError("Invalid consumer.")

        if token is not None and not isinstance(token, oauth2.Token):
            raise ValueError("Invalid token.")

        imaplib.IMAP4_SSL.authenticate(self, 'XOAUTH',
            lambda x: oauth2.build_xoauth_string(url, consumer, token))
示例#2
0
    def authenticate(self, url, consumer, token):
        if consumer is not None and not isinstance(consumer, oauth2.Consumer):
            raise ValueError("Invalid consumer.")

        if token is not None and not isinstance(token, oauth2.Token):
            raise ValueError("Invalid token.")

        self.docmd('AUTH', 'XOAUTH %s' % \
            base64.b64encode(oauth2.build_xoauth_string(url, consumer, token)))
示例#3
0
    def authenticate(self, url, consumer, token):
        if consumer is not None and not isinstance(consumer, oauth2.Consumer):
            raise ValueError("Invalid consumer.")

        if token is not None and not isinstance(token, oauth2.Token):
            raise ValueError("Invalid token.")

        self.docmd('AUTH', 'XOAUTH %s' % \
            base64.b64encode(oauth2.build_xoauth_string(url, consumer, token)))
示例#4
0
    def authenticate(self, url, consumer, token):
        if consumer is not None and not isinstance(consumer, oauth2.Consumer):
            raise ValueError("Invalid consumer.")

        if token is not None and not isinstance(token, oauth2.Token):
            raise ValueError("Invalid token.")

        imaplib.IMAP4_SSL.authenticate(self, 'XOAUTH',
            lambda x: oauth2.build_xoauth_string(url, consumer, token))
示例#5
0
    def oauth_login(self, url, oauth_token, oauth_token_secret, consumer_key="anonymous", consumer_secret="anonymous"):
        """Authenticate using the OAUTH method.

        This only works with IMAP servers that support OAUTH (eg. Gmail).
        """
        if oauth2:
            token = oauth2.Token(oauth_token, oauth_token_secret)
            consumer = oauth2.Consumer(consumer_key, consumer_secret)
            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")
示例#6
0
文件: google_.py 项目: teknikqa/f1
    def authenticate(self, url, consumer, token):
        if consumer is not None and not isinstance(consumer, oauth.Consumer):
            raise ValueError("Invalid consumer.")

        if token is not None and not isinstance(token, oauth.Token):
            raise ValueError("Invalid token.")

        xoauth_string = oauth.build_xoauth_string(url, consumer, token)
        code, resp = self.docmd("AUTH", "XOAUTH %s" % base64.b64encode(xoauth_string))
        if code >= 500:
            raise smtplib.SMTPResponseException(code, resp)
        return code, resp
示例#7
0
    def authenticate(self, url, consumer, token):
        if consumer is not None and not isinstance(consumer, oauth.Consumer):
            raise ValueError("Invalid consumer.")

        if token is not None and not isinstance(token, oauth.Token):
            raise ValueError("Invalid token.")

        xoauth_string = oauth.build_xoauth_string(url, consumer, token)
        code, resp = self.docmd('AUTH', 'XOAUTH %s' % base64.b64encode(xoauth_string))
        if code >= 500:
            raise smtplib.SMTPResponseException(code, resp)
        return code, resp
示例#8
0
    def oauth_login(self, url, oauth_token, oauth_token_secret,
                    consumer_key='anonymous', consumer_secret='anonymous'):
        """Authenticate using the OAUTH method.

        This only works with IMAP servers that support OAUTH (e.g. Gmail).
        """
        if oauth_module:
            token = oauth_module.Token(oauth_token, oauth_token_secret)
            consumer = oauth_module.Consumer(consumer_key, consumer_secret)
            xoauth_callable = lambda x: oauth_module.build_xoauth_string(url, consumer, token)
            return self._command_and_check('authenticate', 'XOAUTH', xoauth_callable, unpack=True)
        else:
            raise self.Error('The optional oauth2 package is needed for OAUTH authentication')
示例#9
0
    def test_build_xoauth_string(self):
        consumer = oauth.Consumer('consumer_token', 'consumer_secret')
        token = oauth.Token('user_token', 'user_secret')
        url = "https://mail.google.com/mail/b/[email protected]/imap/"
        xoauth_string = oauth.build_xoauth_string(url, consumer, token)

        method, oauth_url, oauth_string = xoauth_string.split(' ')

        self.assertEqual("GET", method)
        self.assertEqual(url, oauth_url)

        returned = {}
        parts = oauth_string.split(',')
        for part in parts:
            var, val = part.split('=')
            returned[var] = val.strip('"') 

        self.assertEquals('HMAC-SHA1', returned['oauth_signature_method'])
        self.assertEquals('user_token', returned['oauth_token'])
        self.assertEquals('consumer_token', returned['oauth_consumer_key'])
        self.assertTrue('oauth_signature' in returned, 'oauth_signature')
示例#10
0
    def test_build_xoauth_string(self):
        consumer = oauth.Consumer('consumer_token', 'consumer_secret')
        token = oauth.Token('user_token', 'user_secret')
        url = "https://mail.google.com/mail/b/[email protected]/imap/"
        xoauth_string = oauth.build_xoauth_string(url, consumer, token)

        method, oauth_url, oauth_string = xoauth_string.split(' ')

        self.assertEqual("GET", method)
        self.assertEqual(url, oauth_url)

        returned = {}
        parts = oauth_string.split(',')
        for part in parts:
            var, val = part.split('=')
            returned[var] = val.strip('"')

        self.assertEquals('HMAC-SHA1', returned['oauth_signature_method'])
        self.assertEquals('user_token', returned['oauth_token'])
        self.assertEquals('consumer_token', returned['oauth_consumer_key'])
        self.assertTrue('oauth_signature' in returned, 'oauth_signature')
示例#11
0
    def test_build_xoauth_string(self):
        consumer = oauth.Consumer("consumer_token", "consumer_secret")
        token = oauth.Token("user_token", "user_secret")
        url = "https://mail.google.com/mail/b/[email protected]/imap/"
        xoauth_string = oauth.build_xoauth_string(url, consumer, token)

        method, oauth_url, oauth_string = xoauth_string.split(" ")

        self.assertEqual("GET", method)
        self.assertEqual(url, oauth_url)

        returned = {}
        parts = oauth_string.split(",")
        for part in parts:
            var, val = part.split("=")
            returned[var] = val.strip('"')

        self.assertEquals("HMAC-SHA1", returned["oauth_signature_method"])
        self.assertEquals("user_token", returned["oauth_token"])
        self.assertEquals("consumer_token", returned["oauth_consumer_key"])
        self.assertTrue("oauth_signature" in returned, "oauth_signature")
示例#12
0
    def oauth_login(self,
                    url,
                    oauth_token,
                    oauth_token_secret,
                    consumer_key='anonymous',
                    consumer_secret='anonymous'):
        """Authenticate using the OAUTH method.

        This only works with IMAP servers that support OAUTH (e.g. Gmail).
        """
        if oauth_module:
            token = oauth_module.Token(oauth_token, oauth_token_secret)
            consumer = oauth_module.Consumer(consumer_key, consumer_secret)
            xoauth_callable = lambda x: oauth_module.build_xoauth_string(
                url, consumer, token)
            return self._command_and_check('authenticate',
                                           'XOAUTH',
                                           xoauth_callable,
                                           unpack=True)
        else:
            raise self.Error(
                'The optional oauth2 package is needed for OAUTH authentication'
            )