【问题标题】:Using Firebase Authentication from iOS 7.1.2 Safari从 iOS 7.1.2 Safari 使用 Firebase 身份验证
【发布时间】:2017-06-08 20:41:43
【问题描述】:

我看到了这个错误:

错误:环境不支持此操作 应用程序正在运行。 “location.protocol”必须是 http、https 或 必须启用 chrome 扩展和网络存储。

当我使用时:

 firebase.auth().signInWithPopup(provider)
        .then(function(result) {
            console.log(result);
        })
        .catch(function(error) {
            console.log('popup', error);
            //webSettings.setDomStorageEnabled(true);
            firebase.auth().signInWithRedirect(provider)
                .then(function(result) {
                    console.log(result);
                })
                .catch(function(error) {
                    console.log('redirect', error);
                    firebase.auth().signInAnonymously().catch(function(error) {
                        console.log('anonymous', error);
                    });
                });
        });

通过弹出和重定向的前两次登录尝试失败。它似乎只发生在 iOS Safari 上。

我看到其他人报告了 Cordova 的问题,但我没有看到答案,我只使用 web 和 firebase。不是 Cordova 或 ionic 等。

匿名登录在 iOS 上有效,但这只是一个测试,并不是我们想要使用的。

如果你想测试它,你可以在 iOS 上使用来自 Safari 的https://meetup-reporter.firebaseapp.com/

返回的 Promise 中错误对象的示例转储是:

{"code": "auth/operation-not-supported-in-this-environment", “构造函数”:函数(a,b) {this.code="auth/"+a;this.message=b||Xf[a]||"";}, "F": 函数 () {return{code:this.code,message:this.message}},“line”:44,“message”: “此应用程序的环境不支持此操作 正在运行。 \"location.protocol\" 必须是 http、https 或 必须启用 chrome 扩展和网络存储。", "sourceURL": "https://meetup-reporter.firebaseapp.com//firebase/4.1.2/firebase-auth.js", “堆”: "https://meetup-reporter.firebaseapp.com//firebase/4.1.2/firebase-auth.js:44:638\nhttps://meetup-reporter.firebaseapp.com//firebase/4.1.2/firebase-auth.js:45:258\nA@https://meetup-reporter.firebaseapp.com//firebase/4.1 .2/firebase-auth.js:44:545\nD@https://meetup-reporter.firebaseapp.com//firebase/4.1.2/firebase-auth.js:45:242\nsignInWithPopup@https://meetup-reporter.firebaseapp.com//firebase/4.1.2/firebase-auth.js:241:48\na@https://meetup-reporter.firebaseapp.com/__/firebase/4.1.2/firebase-auth.js:260:432\nhttps://meetup-reporter.firebaseapp.com/scripts/main.js:430 :36", "toJSON": 函数 () {var a=Array.prototype.slice.call(参数);a:{var e=Array.prototype.slice.call(a);var l=0;for(var n=!1,C=0;Cl||l>=fk.length)throw new N("internal-error","Argument 验证器收到的参数数量不受支持。");e=fk[l]+" 参数 "+(e.name?'"'+e.name+'" ':"")+" 必须是 "+e.N+".";break a}e=null}}if(e)throw new N("argument-error",d+" failed: "+e);return b.apply(this,a);}}

【问题讨论】:

    标签: ios firebase firebase-authentication mobile-safari


    【解决方案1】:

    signInWithRedirect 现在实际上在 Cordova 中有效:https://firebase.google.com/docs/auth/web/cordova signInWithPopup 和 signInWithRedirect 也应该适用于 iOS7 及更高版本。我刚刚在 iOS 7 设备上进行了测试,它们都可以工作。您遇到的情况可能是您在禁用网络存储的 Safari Private/Incognito 模式下使用此操作。这些操作依赖于 Web 存储,以便将 OAuth 结果安全地传送到父页面。发生这种情况时,您需要让您的用户切换到常规模式,或者您可以使用 Google Sign-in JS SDK 获取 OAuth 凭据,然后进行 signInWithCredential。我认为它可以在隐身模式下工作。

    【讨论】:

    • 感谢@bojeil 我测试了,我无法通过 firebase signInWithPopup 或 signInWithRedirect 让移动 Safari 工作。但是 google 登录 JS SDK 确实适用于较旧的 iphone/safari/etc,谢谢!对于那些想要这样做的人,请参阅firebase.google.com/docs/auth/web/…
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-06-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多