-
Notifications
You must be signed in to change notification settings - Fork 21
Description
Hello togehter,
I want to access an GCP Cloud Endpoint with workload identity federation from AWS. I have a generated impersonated key file and your first example with list buckets worked well.
For Cloud endpoints and gRPC there is the need to use GOOGLE_ID_TOKEN instead of ACCESS_TOKENS.
My code looks like this. I used the getIdTokenClient function.
`
async function main() {
const url = "https://my-cloud-endpoint-url-endpoint-pimf6a67fa-ew.a.run.app/v1/status"
const auth = new GoogleAuth({
keyFile: process.env.GOOGLE_APPLICATION_CREDENTIALS,
scopes: 'https://www.googleapis.com/auth/cloud-platform',
projectId: 'my-project',
});
const targetAudience = "this-is-my-target-audience"
const client = await auth.getIdTokenClient(targetAudience);
const res = await client.request({ url });
console.log(res.data); }
`
The error message is:
Error: Cannot fetch ID token in this environment, use GCE or set the GOOGLE_APPLICATION_CREDENTIALS environment variable to a service account credentials JSON file. at GoogleAuth.getIdTokenClient
The problem is that I have an access token. In my case I need an ID Token. I was wondering if there is a possibility to get an ID Token before I request my endpoint.
( It works in python: Python google.auth has an impersonated_credentials object with an ID Token functionality.
creds = impersonated_credentials.IDTokenCredentials( target_creds, target_audience=audience, include_email=True )
Anyway, I need a solution for nodeJs.
Thanks