gpt4 book ai didi

firebase - 在 Golang 中仅使用环境变量初始化 Firebase Admin SDK

转载 作者:数据小太阳 更新时间:2023-10-29 03:08:35 27 4
gpt4 key购买 nike

我正在尝试 initialize the Firebase Admin SDK , 在 go 中,仅使用环境变量(无法访问文件系统)。

我有 service-account-file.json 文件,可以通过以下方式让它在本地工作:

export GOOGLE_APPLICATION_CREDENTIALS="/path/to/service-account-file.json"

...

myfile.go:
app, err := firebase.NewApp(context.Background(), nil)

但是,我想将 service-account-file.json 的内容放入环境变量中,并使用其值初始化 firebase Admin SDK。

有一个open issue声称你可以通过 CredentialsFromJSON 做到这一点,但是我不太明白。

有人用过这个吗?如果可以,请举个例子好吗?

最佳答案

尝试:

export JSON_CREDS="{\"type\":\"service_account\",\"project_id\":\"project-id\",\"private_key_id\":\"some_number\",\"private_key\":\"\",\"client_email\":\"<api-name>api@project-id.iam.gserviceaccount.com\",\"client_id\":\"...\",\"auth_uri\":\"https:\/\/accounts.google.com\/o\/oauth2\/auth\",\"token_uri\":\"https:\/\/accounts.google.com\/o\/oauth2\/token\",\"auth_provider_x509_cert_url\":\"https:\/\/www.googleapis.com\/oauth2\/v1\/certs\",\"client_x509_cert_url\":\"https:\/\/www.googleapis.com\/...<api-name>api%40project-id.iam.gserviceaccount.com\"}"

...

import "google.golang.org/api/option"

...

app, err := firebase.NewApp(context.Background(), nil, option.WithCredentialsJSON([]byte(os.Getenv("JSON_CREDS"))))

关于firebase - 在 Golang 中仅使用环境变量初始化 Firebase Admin SDK,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56605884/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com