So I have an electron app that performs:
const { v2 } = require('@google-cloud/speech');
...
client= new v2.SpeechClient({
apiEndpoint: `us-central1-speech.googleapis.com`,
keyFilename: keyFilename,
projectId: PROJECT_ID,
});
...
client._streamingRecognize()
...
now this works perfectly fine, however due to multiple reasons (mainly security) and our app is bundled, I am not allowed to provide the json key on the electron app. So what I did is setup an API on our server where I can safely have the json auth key that returns a token from it:
// server api
const auth = new GoogleAuth({
keyFilename: speech.keyFilename,
scopes: ['https://www.googleapis.com/auth/cloud-platform'],
});
const client = await auth.getClient();
const accessToken = await client.getAccessToken();
return {
token: accessToken.token,
};
I am hoping on doing something like:
const authToken = await fetch('my-api/token');
speechClient = new v2.SpeechClient({
apiEndpoint: `us-central1-speech.googleapis.com`,
// keyFilename: keyFilename,
projectId: PROJECT_ID,
authToken: `Bearer ${token}
});
Of course it does not work, but something where I can add the token with. I cannot use google's REST API directly because the functionality that I want to access (_streamingRecognize) is not available (I cannot find it in ther documentation).