From 38d63cb7f78835e4f99573f09bea6d5441a15af3 Mon Sep 17 00:00:00 2001 From: Dean Date: Wed, 11 Jan 2023 09:37:48 +1100 Subject: imap,smtp: cache and cycle XOAUTH2 refresh token Normally for emails with xoauth2, the help page says to pass the refresh token as the password. When the refresh token expires, aerc can't fetch the access token, and you must get a new refresh token from the external script. This patch implements a cycle of refresh tokens so you only need to use an external script to fetch the refresh token once. Once you have fetched the initial refresh token (with an external script like mutt_xoauth2.py or https://github.com/gaoDean/oauthRefreshToken), that refresh token is inputted as the password to aerc (as normal) to fetch the access token. Before this patch aerc used to only fetch the access token, but now it fetches that and a new refresh token, which it caches in $XDG_CONFIG_HOME/aerc/-xoauth2.token. In the next opening of aerc, aerc will pull the refresh token from the cache, and use it instead of the inputted refresh token from the password. If it is not present in the cache, the refresh token is taken from the password as usual. Signed-off-by: Dean Acked-by: Robin Jarry --- worker/imap/connect.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'worker') diff --git a/worker/imap/connect.go b/worker/imap/connect.go index 5be916e7..6f341753 100644 --- a/worker/imap/connect.go +++ b/worker/imap/connect.go @@ -82,7 +82,7 @@ func (w *IMAPWorker) connect() (*client.Client, error) { } } else if w.config.xoauth2.Enabled { if err := w.config.xoauth2.Authenticate( - username, password, c); err != nil { + username, password, w.worker.Name, c); err != nil { return nil, err } } else if err := c.Login(username, password); err != nil { -- cgit