小编Geo*_*gii的帖子

Google 云(firebase)可调用函数 401:http 调用时出现“未经授权”错误

我有通过部署的简单测试可调用函数firebase deploy --only functions

这是内容:

export const test = region('europe-west1').https.onCall((data, context) => {
    logger.debug('test call info', data, context);
    return 'hello, world!';
});
Run Code Online (Sandbox Code Playgroud)

我可以通过 HTTP 调用https://europe-west1-{project}.cloudfunctions.net/test并接收来成功调用它{"result": "hello, world!"}

现在想通过 IAM 策略来保护此功能。

  1. 我创建新的服务帐户并加载它的凭据 json。
  2. 我转到控制台并从allUsersCloud Functions Invoker 角色中删除,并使用 Cloud Functions Invoker 角色添加在 #1 中创建的服务帐户。<--- 现在,当我尝试调用我的测试函数时,如预期的那样,我收到 403 Forbidden
  3. 我使用我的 PC 上的服务帐户创建 id-token
const auth = new GoogleAuth({keyFile: './key.json'});
targetAudience = new URL('https://europe-west1-{project}.cloudfunctions.net/test');
const client = await auth.getIdTokenClient(targetAudience as string);
const idToken = await client.idTokenProvider.fetchIdToken(targetAudience as …
Run Code Online (Sandbox Code Playgroud)

authentication firebase gcloud google-cloud-functions google-iam

1
推荐指数
1
解决办法
3052
查看次数