learn XOAUTH2 authentication

Signed-off-by: François Lamboley <francois.lamboley@happn.com>
Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
This commit is contained in:
Christopher Corley
2014-01-09 14:30:41 -06:00
committed by Nicolas Sebrecht
parent ca1ce256ec
commit f7efaa2093
5 changed files with 118 additions and 4 deletions

View File

@ -29,6 +29,8 @@ class GmailRepository(IMAPRepository):
# Gmail IMAP server port
PORT = 993
OAUTH2_URL = 'https://accounts.google.com/o/oauth2/token'
def __init__(self, reposname, account):
"""Initialize a GmailRepository object."""
# Enforce SSL usage
@ -49,6 +51,18 @@ class GmailRepository(IMAPRepository):
self._host = GmailRepository.HOSTNAME
return self._host
def getoauth2_request_url(self):
"""Return the server name to connect to.
Gmail implementation first checks for the usual IMAP settings
and falls back to imap.gmail.com if not specified."""
try:
return super(GmailRepository, self).getoauth2_request_url()
except OfflineImapError:
# nothing was configured, cache and return hardcoded one
self._oauth2_request_url = GmailRepository.OAUTH2_URL
return self._oauth2_request_url
def getport(self):
return GmailRepository.PORT