getmail-gmail-xoauth-tokens patch 1

Tyrel McQueen <[email protected]> Wed, 4 May 2022 20:49:25 -0400
Newsgroups gmane.mail.getmail.user
Message-ID <CAG5L9vKxCgrQrRpeH-xd3OARmkD0F76EiUD60ANC_mh=_1msmQ@mail.gmail.com>
Folks,

This is the first of two potential patches for the oauth2 support script of
getmail. If one creates an OAuth2 client_id that is of type webapp, then
two additional parameters need to be passed in order to receive not just an
access_token, but also a refresh_token. The patch below accomplishes that.

Another patch for this script is necessary to make it work as of the end of
February as well. As outlined in:

https://developers.googleblog.com/2022/02/making-oauth-flows-safer.html

The out-of-band access mechanism is no longer allowed. This means this
script needs to be updated so that instead of having the verification code
pasted manually, that it starts a mini http server on localhost, and then
sets redirect_uri appropriately to receive the code by a redirect to
localhost:

https://developers.google.com/identity/protocols/oauth2/native-app#redirect-uri_loopback

I am not up for making such a change, but wanted to make people aware that
such a change is needed.

--- getmail-gmail-xoauth-tokens.orig 2022-05-04 20:38:01.760289654 -0400
+++ getmail-gmail-xoauth-tokens 2022-05-04 20:40:00.755317005 -0400
@@ -61,6 +61,10 @@
     def code_url(self):
         params = self.copy('scope', 'client_id', 'redirect_uri')
         params['response_type'] = 'code'
+        # These two needed to get a refresh token
+        # for "web app" type client IDs from google
+        params['access_type'] = 'offline'
+        params['prompt'] = 'consent'
         return '%s?%s' % (self.data['auth_uri'], self.query(params))

     def get_response(self, url, params):