简体   繁体   English

Firebase HTTPS 可调用 function context.auth 在与自定义令牌一起使用时始终为 Z37A6259CC0C1DAE29Z0A76

[英]Firebase HTTPS callable function context.auth is always null when used with custom token auth

HTTPS callable function is called directly from our app after signing in using custom token (custom auth), but context.auth is null in function eventually. HTTPS callable function is called directly from our app after signing in using custom token (custom auth), but context.auth is null in function eventually.

I am wondering if this is something expected?我想知道这是否是预期的? I am not providing any specific example (our client is using Firebase SDK with Kotlin, everything is implemented accordingly to the example in docs ), just want to know if maybe someone had similar issue or maybe we need to double check our client's code (custom token authentication is actually working there, since we use firestore with security rules that require it).我没有提供任何具体的例子(我们的客户正在使用 Firebase SDK 和 Kotlin,一切都是根据文档中的示例实现的,或者我们只需要仔细检查我们的客户是否有类似的问题)令牌身份验证实际上在那里工作,因为我们使用带有需要它的安全规则的 Firestore)。

I was trying to find some information about certain restrictions, but there's none: Firebase FAQ https://firebase.google.com/support/troubleshooter/functions/auth/callable (nothing about custom token), this answer here Do I need to use verifyIdToken on the context.auth object in firebase cloud functions?我试图找到有关某些限制的一些信息,但没有: Firebase FAQ https://firebase.google.com/support/troubleshooter/functions/auth/callable (与自定义令牌无关),这个答案在这里我需要在 firebase 云函数中的 context.auth object 上使用 verifyIdToken?

Been asked to add an example of the cloud function, nothing specific, is reproducible with simple one like the following (auth will be always null in log record):被要求添加云 function 的示例,没有什么特别的,可以通过如下简单的方法重现(在日志记录中,auth 将始终为 null):

exports.getData = functions.https.onCall((data, context) => {
  functions.logger.info('Auth info', { auth: context.auth });
  return {
    success: true,
    data: null,
  };
});

Seems like a potential race condition, Ensure that Auth has created the user object before requesting the callable function if you are calling it directly after a sign-in method.似乎是潜在的竞争条件,如果您在登录方法之后直接调用它,请确保 Auth 在请求可调用 function 之前已创建用户 object。 This can be done using a callback from an onAuthStateChanged.这可以使用来自 onAuthStateChanged 的回调来完成。

firebase.auth().onAuthStateChanged(function(user) {
  if (user) {
    // User is signed in.
  } else {
    // No user is signed in.
  }
});

Source: https://firebase.google.com/docs/auth/web/manage-users#get_the_currently_signed-in_user资料来源: https://firebase.google.com/docs/auth/web/manage-users#get_the_currently_signed-in_user

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

相关问题 Firebase Auth photoURL 始终返回 null - Firebase Auth photoURL always returns null Firebase 3 Auth + Node + jsonwebtoken:自定义令牌无效 - Firebase 3 Auth + Node + jsonwebtoken: Invalid custom token Firebase身份验证为自定义令牌设置自定义过期时间 - Firebase auth set custom expiration time for custom token firebase.auth()。currentUser和onAuthStateChanged始终为null,尽管已登录 - firebase.auth().currentUser and onAuthStateChanged always null inspite of being signed in 使用 firebase.auth().oAuthStateChanged 在页面刷新时获取令牌 null - Getting token null on page refresh using firebase.auth().oAuthStateChanged Firebase 身份验证 - 自定义身份验证 - Firebase Auth - custom authentication 自定义 Firebase 身份验证中的身份验证/用户令牌过期错误 - auth/user-token-expired error in custom firebase authentication AngularFirestore 权限缺失或不足(Firebase 自定义令牌身份验证) - AngularFirestore Missing or Insufficient permission (Firebase custom token auth) 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 Firebase身份验证不是功能 - Firebase auth reauthenticate is not a function
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM