将 FirebaseAuth 的当前 session/token 从本机 Android 应用程序传递到 WebView 的 Firebase 应用程序

Passing current session/token of FirebaseAuth from Native Android App to a WebView's Firebase App

场景

我要
通过 Android 本机应用程序通过 FirebaseAuth
完成的身份验证 到
html/javascript 屏幕作为 Webview 嵌入到我的应用程序中,这样我就可以在不要求用户重新登录的情况下调用我的 Firebase 数据库。

我试过的
我尝试使用 signInWithCustomToken and used the token generated from getidtokenresult 登录,但出现错误“INVALID_CUSTOM_TOKEN”

任何指导都会有所帮助

您可以在您的原生应用中使用 Firebase Admin SDK 为您的客户端应用生成一个有效令牌,以便与 signInWithCustomToken()

一起使用

令牌生成:

//The uid should uniquely identify the user or device you are authenticating
String uid = "some-uid";

String customToken = FirebaseAuth.getInstance().createCustomToken(uid);
// Send token back to client

在客户端应用中使用:

firebase.auth().signInWithCustomToken(token).catch(function(error) {
  // Handle Errors here.
  var errorCode = error.code;
  var errorMessage = error.message;
  // ...
});

Firebase docs

中有关于此的更多信息