网络中的Firebase Google身份验证不适用于android app webview [英] firebase google authentication in web does not work on android app webview
问题描述
我正在创建一个使用Firebase Google身份验证登录的网站.在所有浏览器中都可以正常工作.但是,当我将该网站作为webview添加到我的应用程序中时,它将无法正常工作.
I am creating a website that has login with firebase google authentication. It's working fine in all browsers. But when I add this website in my app as webview it does not work.
显示此错误的网站:
在运行该应用程序的环境中不支持此操作."location.protocol"必须为http,https或chrome-extension,并且必须启用网络存储.
This operation is not supported in the environment this application is running on. "location.protocol" must be http, https or chrome-extension and web storage must be enabled.
以下代码如下:
here some code bellow:
javascript代码:
function login(){
console.log('login called');
function newLoginHappend(user){
if(user){
model_questions(user);
}else{
var provider = new firebase.auth.GoogleAuthProvider();
firebase.auth().signInWithPopup(provider).then(function(result) {
// This gives you a Google Access Token. You can use it to access the Google API.
var token = result.credential.accessToken;
// The signed-in user info.
var user = result.user;
// ...
}).catch(function(error) {
// Handle Errors here.
var errorCode = error.code;
var errorMessage = error.message;
// The email of the user's account used.
var email = error.email;
// The firebase.auth.AuthCredential type that was used.
var credential = error.credential;
// ...
});
}
}
firebase.auth().onAuthStateChanged(newLoginHappend);
}
window.onload = login();
网络视图代码:
WebSettings webSettings =webView.getSettings();
webSettings.setJavaScriptEnabled(true);
webView.setWebViewClient(new WebViewClient());
webView.loadUrl("https://mahmud-cse16.github.io/CBAP_Handout/");
有什么方法或技术可以解决此问题?如果您有任何想法,请与我们分享.
谢谢
thanks
推荐答案
尝试为Webview启用DOM存储
Try enabling DOM Storage for the webview
WebSettings webSettings = myWebView.getSettings();
webSettings.setDomStorageEnabled(true); // localStorage
设置是否启用DOM存储API.默认值为false.
Sets whether the DOM storage API is enabled. The default value is false.
这篇关于网络中的Firebase Google身份验证不适用于android app webview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!