Whats the best way to use google credentials for production app?

依然范特西╮ 提交于 2021-01-27 17:36:56

问题


I'm building a C# .net application for STT and I'm creating credentials manually. I find the documentation hugely confusing for me and I dont know how to add the credentials properly.

I added a project, created a json credential and downloaded and kept on a folder and pointing to it for manually with GoogleCredential for authorization and everythings working good. But this cant be a solution for a shipped app. Current approach:

GoogleCredential credentials =
GoogleCredential.FromFile(Path.Combine("*PATH"), "myProject-123XXXx32.json"));

        TextToSpeechClient client = TextToSpeechClient.Create(credentials);

If I use a default credential json by environment variable then how my production app that is running on users machine will have credential?

So I have to put the json directly to my app? Isn't it less secure than using a key?

What should I use to authenticate my application with GoogleCredential?


回答1:


You can set credentials using Google KMS and consume it in your application https://cloud.google.com/kms/.

1a. Save the JSON in a KMS as a JSON for the VALUE of the KEY.

2a. Decrypt JSON in your code and consume it.


1b. Alternatively, you can make it consume credentials using Environment variables

2b. And just setup Environments in your environment where you app is being shipped.

3b. You can automate 2b step using some tool like serverless framework( https://serverless.com/framework/docs/providers/google/)



来源:https://stackoverflow.com/questions/56392490/whats-the-best-way-to-use-google-credentials-for-production-app

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