使用身份验证模拟器 SignInWithCustomToken returns auth/invalid-custom-token

SignInWithCustomToken with auth emulator returns auth/invalid-custom-token

我正在尝试使用模拟器和从函数发送到网页的 firebase 自定义令牌进行授权。

但是当我将它与 signInWithCustomToken();.

一起使用时,它 returns 来自 www.googleapis.comHTTP400
/** BACKEND SIDE **/
  const token = await createFirebaseToken(userid);
  res.status(200).send(token);

/** FRONTEND SIDE **/
  const res = await axios.post(endpoints.signin,{/* oauth data*/});
  await document.fApp.auth().signInWithCustomToken(res.data); /* HTTP400 here */

自定义令牌解码如下:

{
  "https://identitytoolkit.googleapis.com/google.identity.identitytoolkit.v1.IdentityToolkit",
  "iat": 1605605206,
  "exp": 1605608806,
  "iss": "firebase-auth-emulator@example.com",
  "sub": "firebase-auth-emulator@example.com",
  "uid": *userid*
}

是否应该发送到 googleapis.com 而不是本地模拟器?

我确实使用 authDomain:"localhost:9099" 设置了 firebase web 配置,并使用 powershell env 将 GOOGLE_APPLICATION_CREDENTIALS 指向服务-account.json,但是在启动时给我一个警告:

Your GOOGLE_APPLICATION_CREDENTIALS environment variable points to ***. Non-emulated services will access production using these credentials. Be careful!

当我调用 admin.auth().createUser() 时,也得到这个警告 3 次,不知道是否相关:

Received service account token strange token not from service-account.json Assuming that it owns project *** my project-id ***

忘记设置

firebase.auth().useEmulator('http://localhost:9099/');

作为stated in the documentation.

现在 customToken 被发送到模拟器。