diff --git a/offlineimap.conf b/offlineimap.conf index 4be3ce5..5970bdf 100644 --- a/offlineimap.conf +++ b/offlineimap.conf @@ -769,7 +769,8 @@ remoteuser = username # with type = IMAP for compatible servers). # # Mandatory parameters are "oauth2_client_id", "oauth2_client_secret" and -# "oauth2_refresh_token". See below to learn how to get those. +# either "oauth2_refresh_token" or "oauth2_access_token". +# See below to learn how to get those. # # Specify the OAuth2 client id and secret to use for the connection.. # Here's how to register an OAuth2 client for Gmail, as of 10-2-2016: @@ -791,8 +792,12 @@ remoteuser = username # - Type the following command-line in a terminal and follow the instructions # python python/oauth2.py --generate_oauth2_token \ # --client_id=YOUR_CLIENT_ID --client_secret=YOUR_CLIENT_SECRET +# - Access token can be obtained using refresh token with command +# python python/oauth2.py --user=YOUR_EMAIL --client_id=YOUR_CLIENT_ID +# --client_secret=YOUR_CLIENT_SECRET --refresh_token=REFRESH_TOKEN # #oauth2_refresh_token = REFRESH_TOKEN +#oauth2_access_token = ACCESS_TOKEN ########## Passwords diff --git a/offlineimap/imapserver.py b/offlineimap/imapserver.py index 5cb1be4..018ba7b 100644 --- a/offlineimap/imapserver.py +++ b/offlineimap/imapserver.py @@ -95,10 +95,10 @@ class IMAPServer: self.tlslevel = repos.gettlslevel() self.oauth2_refresh_token = repos.getoauth2_refresh_token() + self.oauth2_access_token = repos.getoauth2_access_token() self.oauth2_client_id = repos.getoauth2_client_id() self.oauth2_client_secret = repos.getoauth2_client_secret() self.oauth2_request_url = repos.getoauth2_request_url() - self.oauth2_access_token = None self.delim = None self.root = None @@ -212,7 +212,7 @@ class IMAPServer: def __xoauth2handler(self, response): - if self.oauth2_refresh_token is None: + if self.oauth2_refresh_token is None and self.oauth2_access_token is None: return None if self.oauth2_access_token is None: diff --git a/offlineimap/repository/IMAP.py b/offlineimap/repository/IMAP.py index 4ecfb38..7a2a98c 100644 --- a/offlineimap/repository/IMAP.py +++ b/offlineimap/repository/IMAP.py @@ -276,6 +276,9 @@ class IMAPRepository(BaseRepository): def getoauth2_refresh_token(self): return self.getconf('oauth2_refresh_token', None) + def getoauth2_access_token(self): + return self.getconf('oauth2_access_token', None) + def getoauth2_client_id(self): return self.getconf('oauth2_client_id', None)