Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

use Google Application Default Credentials without json file

I have created a console app using c#. I used google cloud speech api. I followed this sample application to create the app. To authenticate speech api, I wrote the following code in main method

Environment.SetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS", "path-to-json-file", EnvironmentVariableTarget.Process);

Everything works fine. My problem, I have to ship the exe along with the json file. I do not want to expose the json file. How can I embed the json file content in code or authenticate without json file ? so that I can only ship the exe to the user.

Any help on this will be appreciated.

Thanks.

like image 678
Amitava Karan Avatar asked Nov 20 '22 03:11

Amitava Karan


1 Answers

For the storage api I found this solution:

 Google.Apis.Auth.OAuth2.GoogleCredential cred = Google.Apis.Auth.OAuth2.GoogleCredential.FromJson(JSONString);
 var storage = Google.Cloud.Storage.V1.StorageClient.Create(cred);

I could easily imagine the same can be done with the other api's

like image 168
MrCalvin Avatar answered Apr 07 '23 19:04

MrCalvin