使用twitter OAuth进行Firebase简单登录



我正试图在angularfire应用程序中实现twitter登录,但似乎无法实现。我已将回拨URL设置为https://auth.firebase.com/v2/MyFIREBASE/auth/twitter/callback,并且该应用程序确实显示了一个挂起约3秒的弹出窗口。弹出窗口上的URL为https://auth.firebase.com/v2/MyFIREBASE/auth/twitter/callback.

在我的代码中,我直接从angularfire-auth部分复制并粘贴。

HTML:

<div ng-controller="SampleCtrl">
  <div ng-show="auth.user">
    <p>Hello, {{auth.user.displayName}}</p>
    <button ng-click="auth.$logout()">Logout</button>
  </div>
  <div ng-hide="auth.user">
    <p>Welcome, please log in.</p>
    <button ng-click="auth.$login('twitter')">Login</button>
  </div>
</div>

JavaScript:

app.factory("simpleLogin",
  ["$firebaseSimpleLogin", function($firebaseSimpleLogin) {
    var ref = new Firebase("https://MyFIREBASE.firebaseio.com/");
    return $firebaseSimpleLogin(ref);
  }]
);
app.controller("SampleCtrl", 
  ["$scope", "simpleLogin", function($scope, simpleLogin) {
    $scope.auth = simpleLogin;
  }]
);

这里似乎有一个版本不匹配的地方-您使用的回调URL是针对Firebase web客户端的最新版本(>=1.1.0),而不是当前与AngularFire捆绑在一起的版本(它使用了旧的、不推荐使用的Firebase Simple Login客户端)。AngularFire的新版本将很快发布,支持更新的API。

同时,您可以跳过AngularFire工厂方法,使用Firebase web客户端>=1.0直接调用Firebase客户端(即ref.authWithOAuthPopup('twitter', ...)),也可以使用带有Firebase Simple Login的旧版本和旧格式回调URL,记录在https://github.com/firebase/firebase-simple-login/tree/master/docs/v1.

最新更新