【问题标题】:Identity platform auth blocking function deploy in typescript身份平台身份验证阻止功能部署在打字稿中
【发布时间】:2021-12-18 01:25:12
【问题描述】:

我正在尝试编写一个身份验证阻止功能,以防止用户在 google 身份平台中从客户端创建帐户。我已经用打字稿写了它,但我正在努力部署它

这是一个关于拦截功能的网站https://cloud.google.com/identity-platform/docs/blocking-functions

我的实际功能是这样的

import * as functions from 'firebase-functions';
import * as admin from 'firebase-admin';
import * as gcipCloudFunctions from 'gcip-cloud-functions';
const authClient = new gcipCloudFunctions.Auth();


exports.beforeCreateBlockingFunction = authClient.functions().beforeCreateHandler((user, context) => {
    throw new gcipCloudFunctions.https.HttpsError('invalid-argument', `Unauthorized email "${user.email}"`);
});

  1. 我的方法签名正确吗?

  2. 我正在尝试使用以下命令部署它。我不确定这是否适用于打字稿。这是正确的方法吗?

// Http trigger with Cloud Functions.
// gcloud functions deploy beforeCreateBlockingFunction --runtime nodejs10 --region europe-west1 --trigger-http --allow-unauthenticated

感谢任何帮助。 亲切的问候

【问题讨论】:

    标签: node.js typescript google-cloud-platform google-identity google-identity-toolkit


    【解决方案1】:

    typescript 的方法声明不正确.. 函数的名称不必是 beforeCreate.. 您可以根据您的约定命名它。请参阅下面的 TS 代码了解 beforeCreateHandler 事件

    import * as gcipCloudFunctions from 'gcip-cloud-functions';
    const authClient = new gcipCloudFunctions.Auth();
    
    export const beforeRegister = authClient.functions().beforeCreateHandler((user: gcipCloudFunctions.UserRecord, 
              context: gcipCloudFunctions.AuthEventContext) => {
      console.log("User Object: " + JSON.stringify(user));
      console.log("Context Object: " + JSON.stringify(context));
      
      return {
        customClaims: {
          verified: true
        },      
      };
    });
    

    【讨论】:

    • 我得到了这个(也事先在 /functions 文件夹中运行了 tsc):错误:(gcloud.functions.deploy)OperationError:code=3,message=Build failed:lib/index.js 确实不存在;错误 ID:bc73f5cd
    • 很可能您使用标志 --source=./lib; 提供部署命令它需要您在 lib 文件夹中编译的 js 文件。确保您的 ts 文件在 lib 文件夹下编译;还要确保你的 package.json 和 package-lock.json 与 lib 中的编译文件一起复制,因为这就是部署时引用的文件夹。
    • 搞定了...感谢您的帮助!
    【解决方案2】:

    我不确定这是否是您部署代码的方式,但我想强调一下,您可能会将 beforeCreate 函数的名称更改为 beforeCreateBlockingFunction。我以为你可以为函数选择任何你喜欢的名称,但我意识到名称应该是你所遵循的文档所说的。

    【讨论】:

      猜你喜欢
      • 2020-10-31
      • 1970-01-01
      • 2013-08-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多