0

I have been trying to create a connection with the gmail api. It worked when I followed this example: https://developers.google.com/gmail/api/quickstart/nodejs

The problem is, this requires the user to browse to a URL and then enter an authentication code in the CLI. This is possible on my local dev machine, but I don't see how this should be done when deployed on a production server, in a docker container. Additionally this method requires you to store a file in your project folder containing your credentials (sensitive data that I don't want to have in my Dockerfile obviously).

My second attempt was using JWT. I followed these steps Send mail via Google Apps Gmail using service account domain wide delegation in nodejs. This works until I actually try to retreive the email from the inbox. I get an error saying GaxiosError: unauthorized_client: Client is unauthorized to retrieve access tokens using this method, or client not authorized for any of the scopes requested.. I have created a service account with domain wide delegation so the account should be authorized to do anything.

Then I read this: "Service accounts only work with GSuite because you have to be able to preauthorize the service account and grant it access to the users account. There is no way to preauthorize a normal user Gmail account. So no you cant use a service account with a normal users gmail account." source: Client is unauthorized to retrieve access tokens using this method Gmail API C#

I have also looked at using just an api key, but this option is not available for gmail.

How the hell am I supposed to authenticate from my container?

boydenhartog
  • 752
  • 2
  • 9
  • 22
  • It depends of what you are trying to do. Accessing a user's inbox does need Domain Wide Delegation which requires G Suite. What is your final objective? – Jescanellas May 08 '20 at 07:42

1 Answers1

0

So it turns out the account I was using didn't have the correct rights. We did have a gsuite. Everything is working as expected now! :)

boydenhartog
  • 752
  • 2
  • 9
  • 22