I am Google Apps administrator and using xoauth.py and IMAP to download users mails without users password. But this process gets stopped after 1 hour. I searched many blogs and I came to know this token expires after 1 hour. Can anyone tell me how to extend that expiration time to Never, or how to refresh this token?
Asked
Active
Viewed 414 times
2 Answers
1
I assume you're using a Service Account, OAuth 2.0 and impersonation here? See:
https://developers.google.com/accounts/docs/OAuth2ServiceAccount#expiration
there's no way to refresh the token or increase the expiration time. Your application should cache the given token to be used with all IMAP connections for one hour. After that it should generate another JWT, sign it, and request another access token.

Jay Lee
- 13,415
- 3
- 28
- 59
-
Thanks Jay, I tried with regenerating token again but it fails. Please guide me through it as my application is stucked because of this only. – Kiran Jadhav Jan 24 '13 at 10:47
-
Based on your code sample below, it looks like you're doing 2-legged OAuth 1.0, not OAuth 2.0. You should be using the exact same code you used to initially generate the xoauth string when reconnecting. Note that OAuth 1.0 xoauth strings expire after 10 minutes, not one hour: – Jay Lee Jan 24 '13 at 13:48
-
Exactly. I am using 2 legged oauth but not sure if its 1.0 or 2.0. It is expiring after 1 hour not in 10 mins. I am trying to download emails of 5 users simultaneously and it is working fine till 1 hour. Now when I try to regenerate xoauth string it gives following error: RuntimeError: maximum recursion depth exceeded while calling a Python object – Kiran Jadhav Jan 25 '13 at 04:43
0
try: .. catch:.. logic can be used to handle such exceptions.
As Google has retired OAuth1.0, its recommended to use OAuth2.0 instead of OAUth1.

Kiran Jadhav
- 43
- 5