I want to use Oauth to connect to Gmail in Python. Right now I've got the xoauth.py script from Google (link), and generating a token works all fine, but how can I then use that in another script? It's going to be in Django.
Right now my script logs in like this:
m = imaplib.IMAP4_SSL("imap.gmail.com")
m.login("example@gmail.com", "password")
But I want something more secure.
Google has a good example code to do OAuth2 and IMAP. Also make sure that your scope is correct.
Below is from the code sample in google example
Here's an example using the
oauth2
module to authenticate using oauth, taken from the readme:Quite a bit cleaner than using
xoauth
.Here is an example of connecting to IMAP using routines present in Google's
xoauth.py
. It'll output some debug information, so you'll probably want to switch to using the oauth package for a real application. At least this should get you started: