简体   繁体   English

Firebase函数context.auth和context.authType未定义

[英]Firebase function context.auth and context.authType undefined

I am diving into Firebase functions (server-side), and having trouble grabbing the authentication information from within the function. 我正在深入Firebase功能(服务器端),并且无法从功能中获取身份验证信息。 In it's simplest form, my index.ts that is getting deployed to Firebase functions looks like this : 在它最简单的形式中,我将部署到Firebase函数的index.ts如下所示:

import * as functions from 'firebase-functions';
import * as admin from 'firebase-admin';

admin.initializeApp();
export const createOrganization = functions.firestore.document("Organizations/{organizationId}").
    onCreate((snap, context) => {
      console.log(context)
});

I can see from Firebase's logging that this function is indeed getting called, and the context that gets logged looks something like this : 我可以从Firebase的日志记录中看到这个函数确实被调用,并且记录的上下文看起来像这样:

{ eventId: 'XXXXX-XXXX-XXXX',
  timestamp: '2018-04-13T21:37:33.349247Z',
  eventType: 'google.firestore.document.write',
  resource: 
  { service: 'firestore.googleapis.com',
     name: 'projects/XXXX/databases/(default)/documents/Organizations/XXXXXXXXXXXX'
  },
  params: { organizationId: 'XXXXXXXXXXXX' } 
}

I would expect from the documentation that the context parameter would also include properties called "authType" and "auth" that contain information about the user who is making the request. 我希望从文档中可以看到context参数还包含名为“authType”和“auth”的属性,这些属性包含有关发出请求的用户的信息。 However, after trying all sorts of things, context.authType and context.auth are always undefined. 但是,在尝试了各种各样的事情之后,context.authType和context.auth总是未定义的。

I have tried this both as an authorized user and unauthorized user with no changes. 我作为授权用户和未经授权的用户尝试了这一点,没有任何变化。

Any help figuring out why context.authType and context.auth are not populated would be really helpful, thanks! 任何帮助搞清楚为什么没有填充context.authType和context.auth会非常有帮助,谢谢!

Auth information is only given for Firebase products that provide auth information to Cloud Functions for each triggered event. 仅为Firebase产品提供身份验证信息,这些产品为每个触发事件的云功能提供身份验证信息。 Currently, only Realtime Database supports this. 目前,只有实时数据库支持此功能。 Firestore support is being worked on. Firestore支持正在进行中。 In theory, Cloud Storage could provide support as well. 从理论上讲,云存储也可以提供支持。

It's inconsistent because each event provider in Cloud Functions for Firebase is driven by different teams, each with different implementations and priorities. 它不一致,因为Cloud Functions for Firebase中的每个事件提供程序都由不同的团队驱动,每个团队都有不同的实现和优先级。

暂无
暂无

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

相关问题 firebase 函数模拟器:context.auth 未定义 - firebase functions emulator: context.auth is undefined 为什么 context.auth 没有出现在 Firebase 函数 onCreate 文档触发器的 context:EventContext 参数中? - Why isn't context.auth appearing in the context:EventContext parameter on the Firebase function onCreate document trigger? Firebase HTTPS 可调用 function context.auth 在与自定义令牌一起使用时始终为 Z37A6259CC0C1DAE29Z0A76 - Firebase HTTPS callable function context.auth is always null when used with custom token auth Firebase 用户的 context.auth 仍然存在 allAuthenticatedUsers 使用 UNAUTHENTICATED 保护 Google 功能错误 - Firebase user's context.auth is present still allAuthenticatedUsers secured Google function error with UNAUTHENTICATED firebase云功能 - https.onCall(...)可以使用Context.Auth吗? - firebase cloud functions - https.onCall(…) can Context.Auth be used? 我是否需要在 firebase 云函数的 context.auth object 上使用 verifyIdToken? - Do I need to use verifyIdToken on the context.auth object in firebase cloud functions? Firebase Callable Function上下文未定义 - Firebase Callable Function context is undefined 将身份验证上下文发送到 unittest 中的 firebase 可调用函数 - Send auth context to firebase callable function in unittest 将 Firebase callablle function 上下文身份验证与其他 Google API 一起使用 - Use Firebase callablle function context auth with other Google APIs JS,firebase.auth() 在全局上下文中不起作用,但在函数内部起作用? - firebase.Auth 不是函数 - JS, firebase.auth() doesn't work in global context but works inside the functions? - firebase.Auth is not a function
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM