1

GitHub との間のリダイレクト認証が成功した後、AngularFire の $onAuth() を起動する際に問題が発生しています。私が使用auth.$authWithOAuthRedirect('github')すると、GitHub にリダイレクトされ、認証が成功した後に再び戻りますが、Angular アプリに戻ったときに、auth.$onAuth()コールバックが呼び出されません。次にページを更新すると、予想される認証情報で呼び出されます。サインアウト ( $unauth()) して再度サインインすると$onAuth()、ページを更新するまでコールバックが呼び出されません。

最初はこれは私のやり方が間違っていると思いましたが、コードを変更して$authWithOAuthPopup()代わりに使用すると、アプリが期待どおりに動作$onAuth()することに気付きました。ポップアップが閉じるとすぐにコールバックが呼び出され、authdata が渡されます。

これが AngularFire のバグなのか、使い方を誤解しているだけなのかを確認してください。例を検索しましたが、正しく使用していると思いますが、コードに問題がある場合は、どうすればよいか教えてください。

最小限のリポジトリ ケースを GitHub リポジトリに入れました: https://github.com/drstearns/angularfire-oath-redir。コードは現在 を使用し$authWithOAuthRedirectており、初回認証時に GitHub から戻ったとき、またはサインアウトして再度サインインした後も、コンソールに何も記録されていないことに気付くでしょう。サインイン後にページを更新すると、正常に動作します。 . use$authWithOAuthPopup()に変更しても問題なく動作します。

関連するコードのスニペットを次に示します。

angular.module('ChatApp', ['firebase'])
    .constant('firebaseUrl', 'https://info343chat.firebaseio.com')
    .controller('ChatController', function($scope, $firebaseArray, $firebaseObject, $firebaseAuth, firebaseUrl) {
        //create reference to the Firebase
        var rootRef = new Firebase(firebaseUrl);

        //create an authentication service for this firebase
        var auth = $firebaseAuth(rootRef);

        //when the user clicks the signin button...
        $scope.signin = function() {
            //authenticate with github using a popup window
            //BUG? change this to $authWithOAuthPopup and
            //it works correctly
            auth.$authWithOAuthRedirect('github')
                .catch(function(err) {
                    console.error(err);
                });
        };

        //when the user clicks the signout button...
        $scope.signout = function() {
            //un-authenticate (sign out)
            auth.$unauth();
        };

        //when the authentication state changes...
        auth.$onAuth(function(authData) {
            //for debugging
            //not firing after initial redirect back from GitHub
            console.log('$onAuth');
            console.log(authData);

            //if we have authentication data
            if (authData) {
                //...
            }
            else {
                //...
            }
        }); //$onAuth()

        //...other controller code
    }); //ChatController
4

1 に答える 1

1

ご報告ありがとうございます!実際にはfirebase.js自体にありますが、これは確かにバグです。そして幸いなことに、それは最近修正されました。firebase.js 参照を 2.2.4 から 2.3.1 に更新すると、問題は解決するはずです。

于 2015-11-13T00:58:57.863 に答える