【问题标题】:Do I need to call verifyIdToken() when using custom claims in callable functions? [duplicate]在可调用函数中使用自定义声明时是否需要调用 verifyIdToken()? [复制]
【发布时间】:2022-01-17 10:48:53
【问题描述】:

Custom Claims 上的文档说应该在每次调用时验证 ID 令牌,但 callable functions 的文档说令牌是自动验证的。

我假设自定义声明文档引用“不可调用”函数,但它仍然相当混乱。

如果令牌被自动验证,是否也像调用admin.auth().verifyIdToken(idToken, true) 时一样检查它们是否被撤销?

【问题讨论】:

  • verifyIdToken 可调用函数在内部工作以在上下文中提供身份验证信息的方式。
  • 谢谢道格!这就是我所需要的。

标签: node.js firebase firebase-authentication google-cloud-functions


【解决方案1】:

使用可自动验证身份验证令牌的可调用函数时,您不必自己验证令牌。 context.auth.tokenDecodedIdToken 对象,其中包含所有用户的自定义声明。

// Saves a message to the Firebase Realtime Database but sanitizes the text by removing swearwords.
exports.addMessage = functions.https.onCall((data, context) => {
  if (!context.auth) {
    return { error: "No User" }
  }

  console.log(context.auth.token);
});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-04-05
    • 1970-01-01
    • 2016-02-24
    • 2016-04-04
    • 1970-01-01
    • 2021-01-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多