加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

angularjs – AngularFire简单登录(电子邮件/密码) – access-co

发布时间:2020-12-17 17:13:23 所属栏目:安全 来源:网络整理
导读:因此,我正在尝试在AngularJS应用程序中执行似乎是最简单的SimpleLogin电子邮件/密码身份验证版本.我为我的应用程序设置了一个forge,我可以成功地读取和写入数据,我正在使用该参考进行身份验证.我在仪表板中启用了电子邮件/密码身份验证,并添加了一个我正在尝
因此,我正在尝试在AngularJS应用程序中执行似乎是最简单的SimpleLogin电子邮件/密码身份验证版本.我为我的应用程序设置了一个forge,我可以成功地读取和写入数据,我正在使用该参考进行身份验证.我在仪表板中启用了电子邮件/密码身份验证,并添加了一个我正在尝试进行身份验证的注册用户.我没有启用其他形式的身份验证.

注意:我在127.0.0.1:9000本地运行此代码,所以我不知道这是否与结果有关(希望不是,我不想在实时服务器上构建它). ..)

无论如何,代码……

=====================================

这就是我认为的全部内容:

<button ng-click="dummySignin()">Dummy Signin</button>

这是我的Angular代码:

angular.module('myApp')
  .controller('MainCtrl',function ($scope,$firebaseSimpleLogin) {
    var ref = new Firebase('https://dummyapp.firebaseio.com/myforge');
    $scope.auth = $firebaseSimpleLogin(ref);

    $scope.dummySignin = function() {
      console.log('signing in...');

      $scope.auth.$login('password',{
        email: 'guy@face.com',password: 'cookie'
      }).then(function(user) {
        console.log('user: ',user);
      },function(error) {
        console.log('error: ',error);
      });
    };
  );
});

我知道Firebase参考设置正确,因为当我尝试随机电子邮件地址时,我收到了INVALID EMAIL错误.当我使用正确的电子邮件地址时,这是回来的JSON:

error: {
  code: "UNKNOWN_ERROR",data: {
    message: "FirebaseSimpleLogin: FirebaseSimpleLogin: An unknown error occurred."
  }
}

另外,我在我的控制台中收到此消息(作为错误,而不是通过console.log):

XMLHttpRequest cannot load https://auth.firebase.com/auth/firebase?email=guy%40face.com&password=cookie&firebase=127.0&v=1.3.1. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://127.0.0.1:9000' is therefore not allowed access.]

我的授权请求源列表中确实有localhost和127.0.0.1,但这并不重要,因为(据我所知)只会影响Facebook和Twitter等OAuth登录方式.关于该错误的另一个奇怪的部分是查询字符串中的firebase变量看起来像是指向localhost(并且显然被截断了……),所以我不知道那里到底发生了什么.

据我所知,我做的一切都是正确的,但我仍然不知道会导致什么问题.我错过了什么?

解决方法

更新:

所以在将我的实际项目代码发送到Firebase的Rob之后,他用这个回击了我:

When instantiating the Firebase Simple Login client,you need to pass
in a Firebase reference (i.e. new Firebase(...)) rather than an
Angular service or AngularFire object. Replacing itemListService in
the object above with new Firebase('https://myapp.firebaseio.com/')
seems to fix with right up.

上面的示例代码并没有反映出这一点(当然,导致问题的一件事),但假设我的服务被称为“FirebaseService”,我的实际代码就是这样:

$scope.auth = $firebaseSimpleLogin(FirebaseService);

对此:

var firebaseRef = new Firebase('http://myapp.firebasio.com');
$scope.auth = $firebaseSimpleLogin(firebaseRef);

所以现在不是使用我的服务来返回Firebase引用(我仍然使用它来读取和写入数据),我将Firebase的直接引用传递到$scope.auth,然后我可以成功调用$login( ) 上.

谢谢,罗布!

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读