offlineimap icon indicating copy to clipboard operation
offlineimap copied to clipboard

XOAUTH2 authentication failed

Open DamienRobert opened this issue 6 years ago • 6 comments

Using offlineimap 7.1.5, I fetch gmail emails via oauth2 token:

oauth2_client_id_eval = get_id_token_fromdict("gmail") oauth2_client_secret_eval = get_secret_token_fromdict("gmail") oauth2_refresh_token_eval = get_refresh_token_fromdict("gmail")

This work well at first, but after a while I get the following error messages: XOAUTH2 authentication failed: [AUTHENTICATIONFAILED] Invalid credentials

Restarting offlineimap the authentification works again.

Just before it starts failing, I see Attempting NOOP on dropped connection imap.gmail.com (typically because I am resuming from suspend to ram).

So it would seems like somehow xoauth2 token are not correctly refreshed when restarting a dropped connection?

DamienRobert avatar Mar 16 '18 20:03 DamienRobert

Yep, the connection is no longer authenticated on gmail server side, due to the fact your computer suspended to RAM which caused it to drop the TCP network connection from your side to the Gmail imap server. The software needs a contributor to add code to detect this dropped network connection, and re-authenticate login.

chris001 avatar Mar 16 '18 23:03 chris001

Linked to #56 .

nicolas33 avatar Mar 17 '18 00:03 nicolas33

@DamienRobert Try adding this setting socktimeout into your .offlineimaprc config file [general] section:

[general]
socktimeout = 10

chris001 avatar Mar 17 '18 03:03 chris001

offlineimap fails for me after 1 hour of successful syncing with autorefresh=5, which I guess is related to:

$ offlineimap -d ALL -c gmail.rc
...
[imap]: xoauth2handler: response "{u'access_token': u'xxxxxxxxxxxx', u'token_type': u'Bearer', u'expires_in': 3600}"
...

kucharskim avatar Mar 21 '18 21:03 kucharskim

Yep, the Gmail XOAUTH2 login expires after one hour @kucharskim .
We should probably upgrade the code so that it will detect the error that the login token has expired, get a new token, and continue.

chris001 avatar Mar 21 '18 22:03 chris001

@chris001: I already had 'socktimeout=90'. I'll try with socktimeout=10, but this is not a real fix, this just means we hope that the timeout will occur before the connection is resumed after a suspend so that offlineimap will reset the connection properly. (I understand this is hard to fix).

Thanks you all for your help.

DamienRobert avatar Mar 22 '18 08:03 DamienRobert