【发布时间】:2020-04-30 20:30:21
【问题描述】:
我的 express 服务器有一个 credentials.json,其中包含 google 服务帐户的凭据。这些凭据用于从 google 获取 jwt,并且我的服务器使用该 jwt 来更新服务帐户拥有的 google 表格。
var jwt_client = null;
// load credentials form a local file
fs.readFile('./private/credentials.json', (err, content) => {
if (err) return console.log('Error loading client secret file:', err);
// Authorize a client with credentials, then call the Google Sheets API.
authorize(JSON.parse(content));
});
// get JWT
function authorize(credentials) {
const {client_email, private_key} = credentials;
jwt_client = new google.auth.JWT(client_email, null, private_key, SCOPES);
}
var sheets = google.sheets({version: 'v4', auth: jwt_client });
// at this point i can call google api and make authorized requests
问题是我正在尝试从 node/express 迁移到 npm serverless/aws。我使用相同的代码,但得到 403 - 禁止。
errors:
[ { message: 'The request is missing a valid API key.',
domain: 'global',
reason: 'forbidden' } ] }
研究向我指出了许多事情,包括:AWS Cognito、storing credentials in environment variables、custom authorizers in API gateway。所有这些对我来说似乎都是可行的,但我是 AWS 的新手,所以任何关于采取哪个方向的建议都将不胜感激。
【问题讨论】:
标签: amazon-web-services aws-api-gateway serverless service-accounts