From 6df828cd9ac71069ed6c89f7997c08a1cf4cbe00 Mon Sep 17 00:00:00 2001 From: Peeter Tomberg Date: Sun, 13 Aug 2023 21:11:44 +0300 Subject: [PATCH] chore: working secrets being setup properly --- apps/graphql-gateway/src/app.module.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/apps/graphql-gateway/src/app.module.ts b/apps/graphql-gateway/src/app.module.ts index 3876a0a5..8a0dafc9 100644 --- a/apps/graphql-gateway/src/app.module.ts +++ b/apps/graphql-gateway/src/app.module.ts @@ -9,20 +9,23 @@ import { HealthModule } from '@package/nestjs-health'; import { GoogleAuth } from 'google-auth-library'; import { FetcherRequestInit } from '@apollo/utils.fetcher'; -const auth = new GoogleAuth(); - const fetcher = async (url: string, init: FetcherRequestInit | undefined): Promise => { + const auth = new GoogleAuth({ + scopes: 'https://www.googleapis.com/auth/cloud-platform', + }); const headers = await auth.getRequestHeaders(url); const credentialBody = await auth.getCredentials(); + const { credential } = await auth.getApplicationDefault(); const customInit = { ...init, headers: { ...init?.headers, - ...headers, + 'X-Serverless-Authorization': `Bearer ${credential.credentials.id_token}`, }, }; console.log('credentialBody', credentialBody); + console.log('credential, projectId', credential.credentials.id_token); console.log('headers', headers); console.log('customInit', customInit); return await fetch(url, customInit);