Search code examples
google-apigoogle-oauthgmail-apigoogle-api-client

How to Authorize my App and Auto Access my E-mail account without asking a user authentication?


I have E-mails in my g-mail account that I wish my App to access without my authorization as an user.

I managed to connect via OAuth 2.0, but that's not quite what I need. I would like my app to be linked with my E-mail automatically.

And thus, any user that access my App will have access to my E-mail (thought the App), is that possible?


Solution

  • Yes, this is possible. The key is to create a service account and then implement G Suite Domain-Wide Delegation. Link This method is the official supported method.

    Another method, that is less secure, is to authenticate with User Credentials. Store the Client ID, Client Secret and OAuth 2 Refresh Token. You application then creates a new Access Token and uses that for authorization. This link shows how to do this in Python.

    Think thru what you are trying to accomplish and more importantly the security risks associated with each method.