[英]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.