OAuth的传输不可用

Transport Unavailable for OAuth

本文关键字:传输 OAuth      更新时间:2023-09-26

我正试图用谷歌登录到我的firebase项目中,但firebase的弹出和重定向功能都出现了传输不可用错误。是因为我在当地工作,还是我在这里做错了什么?

var app = angular.module('WOM', ["firebase"]);
app.controller('SampleCtrl', ['$scope', '$firebaseObject', '$firebaseAuth', function($scope, $firebaseObject, $firebaseAuth){
var ref = new Firebase('https://who-owes-me.firebaseio.com/'); //Where data is stored
var auth = $firebaseAuth(ref);
$scope.login = function() {
    $scope.authData = null;
    $scope.error = null;
    auth.$authWithOAuthPopup("google").then(function(authData){
        $scope.authData = authData;
    }).catch(function(error){
        $scope.error = error;
    });
}
$scope.data = $firebaseObject(ref); //assign data to scope
$scope.data.$loaded()
    .then(function(){
        console.log($scope.data);
    })
    .catch(function(err){
        console.error(err);
    })
}]);

这可能意味着您正在脱离文件系统

为了运行Auth方法,您必须在真正的服务器上工作。一般来说,从本地服务器而不是文件系统进行开发是一种很好的做法,因为这更接近于生产环境的行为。

尝试http-server npm模块以快速启动和运行。

我在开发firebase中托管的angular应用程序时遇到了同样的问题。

它在浏览器中运行良好,但当在iOS网络视图应用程序中打开它时,当尝试登录facebook时,它开始获得TRANSPORT_UNAVAILABLE。

首先,我进入了处理弹出和重定向的firebase文档,这让我进入了authWithOAuthRedirect,但它也不起作用。

在这之后,我发现我使用的是一个关于authWithOAuthRedirect的已知问题的firebase版本,该问题在2.4.1版本上得到了解决因此,请确保您使用的是2.4.2版本,或者将您的应用程序迁移到firebase3.0

我仍然遇到了另一个问题,在对此进行了更多的研究后,我开始将onAuth与身份验证一起使用。每次用户成功进行身份验证时都会调用onAuth。这让一切都变得容易多了。

所以我的登录控制器现在看起来如下:

.controller('LoginCtrl', ['$scope', 'Auth', 'fbutil', 'FBURL', function($scope, Auth, fbutil, FBURL) {
    var ref = new Firebase(FBURL);
    ref.onAuth( function(authData){
      if (authData){
        //User authenticated. Do your logic.
      }
    });
    $scope.fbLogin = function() {
      ref.authWithOAuthPopup("facebook", function(error, authData) {
          if (error){
            if (error.code === "TRANSPORT_UNAVAILABLE") {
              Auth.$authWithOAuthRedirect("facebook", function(error) {
                console.log(error);
              });
            }
            $scope.err = errMessage(error);
          }
      });
    };
})