问题
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.
回答1:
You may store the keyfile encrypted, then on application startup decrypt that file and in a matter of miliseconds (after reading the contents and initializing), rewrite the decrypted content back.
another solution could be grabbing from server (encrypted) and storing in application variable (decrypted) and initialize with that, and then delete the file after initilization.
回答2:
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
来源:https://stackoverflow.com/questions/42389384/use-google-application-default-credentials-without-json-file