I am developing a small App that uses one GCP API (Natural Language) on Node.js. I followed the instructions here: https://cloud.google.com/docs/authentication/getting-started and downloaded the key file and setup up the env var GOOGLE_APPLICATION_CREDENTIALS.
Everything works fine on my local.
Now I want to run it from https://glitch.com/. There, I have a private .env which is not shared, but everything else is public. So I cannot upload the key file there as it would be public.
Is there a way to have an env var (which I can keep secret) which all the information that the key file contains?
Thanks!
Two ways I can think of:
1) Use an API key. The Natural Language API is one of the APIs that supports using API keys. You can store this key in .env.
2) Don't use the GOOGLE_APPLICATION_CREDENTIALS, but create the client by providing explicit credentials using a JSON.
This sample explains how to provide explicit credentials.
You can store this JSON in .data, which is private as per Glitch's docs.
EDIT: changed implicit to explicit
// 1. read json by InputStream
InputStream stream = context.getAssets().open("-----.json");
GoogleCredentials credentials = GoogleCredentials.fromStream(stream);
String projectId = ((ServiceAccountCredentials)credentials).getProjectId();
// 2. build SessionSettings
SessionsSettings.Builder settingsBuilder = SessionsSettings.newBuilder();
SessionsSettings sessionsSettings = settingsBuilder.setCredentialsProvider(FixedCredentialsProvider.create(credentials)).build();
// 3. create SessionsClient
SessionsClient sessionsClient = SessionsClient.create(sessionsSettings)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With