简体   繁体   English

我是否需要在 firebase 云函数的 context.auth object 上使用 verifyIdToken?

[英]Do I need to use verifyIdToken on the context.auth object in firebase cloud functions?

Using a callable function, my intention is to only allow logged-in users to make calls to this.使用可调用的 function,我的意图是只允许登录用户调用它。

export const sendMessage = functions.https.onCall(async (data, context) => {

From the context param there, I have the auth token.从那里的context参数,我有授权令牌。 But I'm just very new to firebase in general and I don't want to make a critical mistake by misunderstanding here.但总的来说,我对 firebase 还很陌生,我不想因为在这里的误解而犯下严重的错误。 If I'm logged out, context.auth becomes null-- easy enough.如果我注销了, context.auth将变为空——这很容易。 But do I need to be sure that the auth token is valid and not "made up" by calling verifyIdToken anyway?但是我是否需要通过调用verifyIdToken来确保身份验证令牌有效而不是“虚构”的?

If not, then is simply checking that context.auth isn't null enough to be sure that the user is logged-in?如果不是,那么只是检查context.auth是否足以确保用户已登录 null?

But do I need to be sure that the auth token is valid and not "made up" by calling verifyIdToken anyway?但是我是否需要通过调用 verifyIdToken 来确保身份验证令牌有效而不是“虚构”的?

No, that happens automatically.不,那是自动发生的。 You can be sure the context.auth is verified if not null. As stated in the documentation :如果不是 null,您可以确定context.auth已通过验证。如文档中所述:

The functions.https.onCall trigger automatically deserializes the request body and validates auth tokens. functions.https.onCall 触发器自动反序列化请求主体并验证身份验证令牌。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 Firebase Cloud Functions 中对 npm 模块使用 `import`? - How do I use `import` for npm modules in Firebase Cloud Functions? 我应该使用 Cloud Functions 还是客户端逻辑来更新 Firebase 中的计数器? - Shall I use Cloud Functions or client logic to update a counter in Firebase? 如何将 Firebase 参数化配置与 Typescript 一起用于 Cloud Functions? - How can I use Firebase Parameterized configuration with Typescript for Cloud Functions? firebase 云功能需要 Blaze 计划 - firebase cloud functions need Blaze plan 如果我已经拥有 Cloud Functions Admin 角色,为什么我需要 Cloud Functions Invoker 角色来运行云函数? - If I already have Cloud Functions Admin role, why do I need Cloud Functions Invoker role to run cloud functions? 如何在 Cloud Functions for Firebase 中获取服务器时间戳? - How do I get the server timestamp in Cloud Functions for Firebase? 是否可以在 firebase 云函数中使用 setTimeout()? - is it possible to use setTimeout() in firebase cloud functions? firebase的云函数不能使用serverTimestamp - Cloud functions for firebase can not use serverTimestamp 我是否需要 Firebase 项目才能使用 Firebase App Check? - Do I need a Firebase project to use Firebase App Check? 如何将 Firebase Cloud Functions 的时间戳格式转换为类似 1665346052 的格式? - How do I convert Firebase Cloud Functions' timestamp format into something like 1665346052?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM