I'm using a simple script that reads my gmail using imaplib, using my username and password and "less secure app" Gmail option. Gmail will disable the "less secure app" option on May 20, so I need to fix the login credentials before that happends.
I've followed this tutorial about using Oauth2, but the problem is that the script is not running locally (running on AWS ubuntu 20.04), so I can't open the web authentication on the machine that has running the script and the login fails.
More precisely, when I run the tutorial code, I get the following:
Please visit this URL to authorize this application: https://accounts.google.com/o/oauth2/...
I can't open that URL on the AWS command line, and logging in at my local machine doesn't work (it redirects to localhost with the credentials).
I believe the following code obtains the google response with the credentials:
flow = InstalledAppFlow.from_client_secrets_file('credentials.json', SCOPES)
creds = flow.run_local_server(port=0)
I think that one option is to get the credentials running the script locally or catching them with a local server and then send them to AWS, but if they expire I'll need to do that again and probably this wont work anyways.
My intuition says thats not the path to take. Any ideas?