use Google Application Default Credentials without json file

不问归期 提交于 2019-12-10 17:35:46

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!