将当前FirebaseAuth的sessiontoken从Native Andorid App传递到WebView的Firebase App。

问题描述 投票:1回答:1

场景

  • 它是一个混合型的应用(大部分Andriod公司都是这样做的)。本地人 Java和部分htmljavascript 在...中 webView)
  • FirebaseAuth 对于authenticationignIn [在Andoid Native应用中] 。
  • 火库 作为数据库
  • 无服务器应用

我想... 传递来自Andorid Native应用的认证,该认证是通过 FirebaseAuth 在我的应用程序中嵌入htmljavascript屏幕作为webview,这样我就可以调用我的firebase数据库,而不要求用户重新登录。

我的尝试 我尝试用以下方法登录 用自定义标记登录 并使用从 getidtokenresult 引起错误 "INVALID_CUSTOM_TOKEN"。

任何指导将是有益的

firebase google-cloud-firestore firebase-authentication android-webview firebase-security
1个回答
0
投票

您可以使用Firebase Admin SDK在您的Native应用程序生成一个有效的令牌为您的客户端应用程序使用与 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文档

© www.soinside.com 2019 - 2024. All rights reserved.