title: How to authenticate with gmail api from node container
body: <p>I have been trying to create a connection with the gmail api. It worked when I followed this example: <a href="https://developers.google.com/gmail/api/quickstart/nodejs" rel="nofollow noreferrer">https://developers.google.com/gmail/api/quickstart/nodejs</a></p>
  
  <p>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). </p>
  
  <p>My second attempt was using JWT. I followed these steps <a href="https://stackoverflow.com/questions/37243862/send-mail-via-google-apps-gmail-using-service-account-domain-wide-delegation-in">Send mail via Google Apps Gmail using service account domain wide delegation in nodejs</a>. This works until I actually try to retreive the email from the inbox. I get an error saying <code>GaxiosError: unauthorized_client: Client is unauthorized to retrieve access tokens using this method, or client not authorized for any of the scopes requested.</code>. I have created a service account with domain wide delegation so the account should be authorized to do anything. </p>
  
  <p>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: <a href="https://stackoverflow.com/questions/42784640/client-is-unauthorized-to-retrieve-access-tokens-using-this-method-gmail-api-c-s/42785468">Client is unauthorized to retrieve access tokens using this method Gmail API C#</a></p>
  
  <p>I have also looked at using just an api key, but this option is not available for gmail.</p>
  
  <p>How the hell am I supposed to authenticate from my container?</p>