7

I'm currently using the following code to authenticate as a service account:

const auth = new google.auth.GoogleAuth({
    keyFile: "<path/to/credentials>",
    scopes: [<scopes>],
});

Is there a way to authenticate using a JSON object containing the same content as the keyFile? For example, doing something like this:

const credentials = {
  "type": ...,
  "project_id": ...,
  "private_key_id": ...,
  "private_key": ...,
  "client_email": ...,
  "client_id": ...,
  "auth_uri": ...,
  "token_uri": ...,
  "auth_provider_x509_cert_url": ...,
  "client_x509_cert_url": ...
}

const auth = new google.auth.GoogleAuth({
  keyFile: credentials,
  scopes: [<scopes>],
});
1
  • 1
    have you tried digging around in the code for the client library to see if there is an overload Commented Jun 14, 2022 at 16:34

1 Answer 1

11

Changing keyFile: "<path/to/credentials>", to credentials: credentials did the trick as GoogleAuthOptions can also be used with a CredentialBody.

Source: Google Cloud Node.js Docs

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.