在生产应用中使用Google凭据的最佳方法是什么? [英] Whats the best way to use google credentials for production app?

查看:78
本文介绍了在生产应用中使用Google凭据的最佳方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为STT构建C#.net应用程序,并且正在手动创建凭据.我发现文档对我来说非常混乱,而且我不知道如何正确添加凭据.

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.

我添加了一个项目,创建了一个JSON凭证,然后下载并保存在文件夹中,并使用 GoogleCredential 手动指向该目录以进行授权,并且一切正常.但是,这对于已交付的应用程序来说不是解决方案.当前方法:

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);

如果我通过环境变量使用默认的凭据json,那么在用户计算机上运行的生产应用程序将如何具有凭据?

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

所以我必须直接将json放到我的应用程序中?难道不比使用钥匙安全吗?

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

我该如何使用 GoogleCredential 对我的应用程序进行身份验证?

What should I use to authenticate my application with GoogleCredential?

推荐答案

您可以使用Google KMS设置凭据,并在您的应用程序中使用它 https://cloud.google.com/kms/.

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

1a.将JSON作为KEY值的JSON保存在KMS中.

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

2a.解密代码中的JSON并使用它.

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

1b.另外,您也可以使用环境变量使用它的凭据

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

2b.只需在要交付应用程序的环境中设置环境.

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

3b.您可以使用无服务器框架等工具( https://serverless.com/framework/docs/providers/google/)

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

这篇关于在生产应用中使用Google凭据的最佳方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆