buz*_*j99 6 javascript json google-api google-authentication node.js
我目前正在使用以下代码作为服务帐户进行身份验证:
const auth = new google.auth.GoogleAuth({
keyFile: "<path/to/credentials>",
scopes: [<scopes>],
});
Run Code Online (Sandbox Code Playgroud)
有没有办法使用包含与 keyFile 相同内容的 JSON 对象进行身份验证?例如,做这样的事情:
const credentials = {
"type": ...,
"project_id": ...,
"private_key_id": ...,
"private_key": ...,
"client_email": ...,
"client_id": ...,
"auth_uri": ...,
"token_uri": ...,
"auth_provider_x509_cert_url": ...,
"client_x509_cert_url": ...
}
const auth = new google.auth.GoogleAuth({
keyFile: credentials,
scopes: [<scopes>],
});
Run Code Online (Sandbox Code Playgroud)
更改keyFile: "<path/to/credentials>",为credentials: credentials可以解决问题,因为 GoogleAuthOptions 也可以与 CredentialBody 一起使用。