Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What keyFile key does google.auth.GoogleAuth() need?

Goal

Using googleapis with firebase functions. Get a JWT token so firebase functions can use a service account with domain-wide delegation to authorize G Suite APIs like directory and drive.

Question

What goes in path.join();

What is __dirname What is 'jwt.keys.json'?

From this example: https://github.com/googleapis/google-api-nodejs-client/blob/master/samples/jwt.js

  // Create a new JWT client using the key file downloaded from the Google Developer Console
  const auth = new google.auth.GoogleAuth({
    keyFile: path.join(__dirname, 'jwt.keys.json'), // <---- WHAT GOES IN path.join()
    scopes: 'https://www.googleapis.com/auth/drive.readonly',
  });

Error

When I run

  const auth = new google.auth.GoogleAuth({
    keyFile: path.join(__dirname, "TEST"), // <-- __dirname == /srv/ at runtime
    scopes: 'https://www.googleapis.com/auth/drive.readonly',
  });

From the GCP Logs I get this error:

Error: ENOENT: no such file or directory, open '/srv/TEST'

Obviously TEST isn't valid, but is '/srv/?

What is the keyFile, a file path? a credential?

Another Example

https://github.com/googleapis/google-api-nodejs-client#service-to-service-authentication

like image 748
Chadd Avatar asked Oct 16 '25 04:10

Chadd


1 Answers

I found documentation here:

https://googleapis.dev/nodejs/google-auth-library/5.10.1/classes/JWT.html

If you do not want to include a file, you can use key, keyId, and email to submit credentials when requesting authorization.

like image 137
Chadd Avatar answered Oct 19 '25 13:10

Chadd



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!