【发布时间】:2015-06-11 03:48:06
【问题描述】:
我正在尝试在我的 AngularJS Web 应用程序中使用基于重定向的 OAuth 流和 FireBase 后端来设置 AngularFire 登录。 我正在使用 AngularJS 1.3.14、Firebase 2.2.3 和 AngularFire 1.0.0。
我尝试设置一个基本示例,以最简单的方式完成身份验证,遵循 AngularFire 库文档:https://www.firebase.com/docs/web/libraries/angular/api.html#angularfire-users-and-authentication
我完成了 Google 应用程序身份验证设置,如下所述:https://www.firebase.com/docs/web/guide/login/google.html
在我的控制器中我这样做:
var ref = new Firebase("https://xxxxxxx.firebaseio.com");
$scope.authObj = $firebaseAuth(ref);
然后下面的例程绑定到我界面中的“登录”按钮。
$scope.authObj.$authWithOAuthRedirect("google");
只要我点击“登录”按钮,我就会被重定向到 Google,在那里我可以授权我的应用程序并可以使用我的帐户登录。然后我被重定向回我的应用程序,但我在 javascript 浏览器 (Chrome) 控制台中看到此错误:
Error: [$rootScope:infdig] 10 $digest() iterations reached. Aborting!
Watchers fired in the last 5 iterations: []
http://errors.angularjs.org/1.3.14/$rootScope/infdig?p0=10&p1=%5B%5D
at REGEX_STRING_REGEXP (angular.js:63)
at Scope.$get.Scope.$digest (angular.js:14281)
at Scope.$get.Scope.$apply (angular.js:14506)
at bootstrapApply (angular.js:1448)
at Object.invoke (angular.js:4185)
at doBootstrap (angular.js:1446)
at bootstrap (angular.js:1466)
at angularInit (angular.js:1360)
at angular.js:26176
at HTMLDocument.trigger (angular.js:2744)
我无法弄清楚为什么会发生这种情况以及如何解决。 AngularJS 引导时似乎发生了某种循环。
如果我用$authWithOAuthPopup 调用更改我的$scope.authObj.$authWithOAuthRedirect("google"); 行(请参阅下面的确切代码),一切正常:
$scope.authObj.$authWithOAuthPopup("google")
.then(function(authData) {
$log.info("Logged in as:", authData.uid);
}).catch(function(error) {
$log.info("Authentication failed:", error);
});
将此代码绑定到我的“登录”按钮后,会出现一个弹出窗口,允许我使用 Google 登录,然后我可以在控制台中读取预期的身份验证消息:Logged in as: google:[undisclosed-21-digit-number]。
任何有助于更好地理解 AngularFire 身份验证库的帮助将不胜感激。 提前谢谢你。
【问题讨论】:
-
如果我在 Chrome for iOS(不支持弹出窗口)上尝试使用 Firebase 文档 firebase.com/docs/web/guide/user-auth.html#section-popups 的 snipplet 表单,我会得到一个无限循环,如下所述:stackoverflow.com/questions/27927200/…。但在我的情况下,我没有无限重定向,因为我将身份验证绑定到视图按钮。目前我正在处理一个 AngularJS 摘要循环。
标签: angularjs authentication firebase angularfire firebase-security