In a Python web application, I am able to connect to Gmail using OAuth and IMAP. OAuth uses whichever Google account you're currently signed into simply and asks you to grant access to the web app. However, it doesn't provide an API to actually retrieve that account's email address.
The problem is, even though the user grants access with OAuth, to interface with Gmail, you still need to explicitly provide the email address in your IMAP connection URL:
https://mail.google.com/mail/b/[your-email]/imap/
Because of this, the web application has to ask the user for their email address and ask them to grant access from Gmail with OAuth. What's worse is the email address they enter may not match the email of the account they grant access with, causing the app to fail.
Is there a way to get your email address using OAuth so you can put it in that URL without asking the user for it? I tried looking at this answer but Google returns a Bad Request
whenever I use both https://mail.google.com/
and https://www.googleapis.com/auth/userinfo#email
as my scope.