firebase - 将 FirebaseAuth 的当前会话/令牌从本机 Android 应用程序传递到 WebView 的 Firebase 应用程序
问题描述
设想
- 它是一个混合应用程序(大部分 Android Native Java 和部分 html/ javascript在WebView中)
- FirebaseAuth用于身份验证/登录 [在 Android 本机应用程序中]
- Firestore作为数据库
- 无服务器应用
我想将
通过FirebaseAuth
完成的 Android Native 应用程序的身份验证传递
到
嵌入Webview
在我的应用程序中的 html/javascript 屏幕,这样我就可以调用我的 Firebase DB 而无需要求用户重新登录。
我尝试了什么我尝试
使用signInWithCustomToken 登录并使用从getidtokenresult生成的令牌,该令牌引发错误“INVALID_CUSTOM_TOKEN”
任何指导都会有所帮助
解决方案
您可以在 Native 应用程序中使用 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 文档中有关于此的更多信息
推荐阅读
- python-3.x - Pytesseract 语言列表
- sql - Tableau SQL 查询:Oracle 数据库错误 907:ORA-00907:缺少右括号
- java - 在android中使用cpp和java时任务':app:externalNativeBuildDebug'执行失败
- python - 使用 python pyodbc 库创建 AWS Lambda 函数会引发错误“模块‘pyodbc’没有属性‘连接’
- angular - 如何在我的数据库的单个列中注册多个文件?
- nginx - 尝试使用 SSL 为多个域设置反向代理时遇到“111:未知错误”
- r - R ggplot - 如何向点添加第三个信息(除了颜色)
- methods - 不能从静态概念引用非静态方法距离
- numpy - 具有减少功能的自定义 numpy 函数
- javascript - 如何在 HTML/CSS 中的垂直菜单旁边创建内容部分