Google-api-nodejs-client: Unable to set subject for automatically retrieved auth client

Created on 6 Feb 2018  路  4Comments  路  Source: googleapis/google-api-nodejs-client

There is no way to set the subject (and therefore impersonate an admin user which is pretty necessary when making Admin SDK calls) when using an auth client that is automatically retrieved as outlined here: https://github.com/google/google-api-nodejs-client#choosing-the-correct-credential-type-automatically

Thanks!

Most helpful comment

Hi @JustinBeckwith

Sorry my initial question was a bit vague. I was actually referring to Application Default Credentials (ADC). The sample code https://github.com/google/google-api-nodejs-client#service-to-service-authentication did not provide such examples.

The example that you have provided indeed works for JWT tokens.

All 4 comments

the answer to this is pertinent to me but the link above is broken

馃憢 hi there! You can just set the subject on the client if you need to:

const {google} = require('googleapis');
const client = await google.auth.getClient();
if (client instanceof google.auth.JWT) {
  client.subject = '[email protected]';
}
...

Hope this helps!

Hi @JustinBeckwith

Sorry my initial question was a bit vague. I was actually referring to Application Default Credentials (ADC). The sample code https://github.com/google/google-api-nodejs-client#service-to-service-authentication did not provide such examples.

The example that you have provided indeed works for JWT tokens.

Was this page helpful?
0 / 5 - 0 ratings