Javascript 如何使AngularFire/Firebase中的用户访问令牌无效?

Javascript 如何使AngularFire/Firebase中的用户访问令牌无效?,javascript,angularjs,firebase,angularfire,Javascript,Angularjs,Firebase,Angularfire,上下文 使用注销用户的说明找到并删除 我正在将AngularFire与AngularJS一起使用,并使用电子邮件和密码方法对用户进行身份验证 问题 调用$unauth不会使用户的令牌无效:后续调用$authWithPassword将返回相同的身份验证令牌 注意:令牌在服务器上设置的过期时间后正确失效 代码 angular .module('app') // Auth Factory .factory("Auth", ["$firebaseAuth", "FIREBASE_

上下文

使用注销用户的说明找到并删除

我正在将AngularFire与AngularJS一起使用,并使用电子邮件和密码方法对用户进行身份验证

问题

调用
$unauth
不会使用户的令牌无效:后续调用
$authWithPassword
将返回相同的身份验证令牌

注意:令牌在服务器上设置的过期时间后正确失效

代码

angular
    .module('app')
    // Auth Factory
    .factory("Auth", ["$firebaseAuth", "FIREBASE_URI",
        function($firebaseAuth, FIREBASE_URI) {
            var ref = new Firebase(FIREBASE_URI);
            return $firebaseAuth(ref);
        }
    ])
控制器:

function authenticationCtrl($scope, $state, authService) {
    var authenticationCtrl = this;

    // LOGIN
    var login = function (userObject) {
        authService.loginWithPassword(userObject, function () {
            $state.go('[...]');
        },
        function (errorText) {
            // ERROR
            console.error("Error logging in user:", errorText)
        });
    };

    // LOGOUT
    var logout = function () {
        // Clear locally logged in user
        $scope.authData = null;
        authService.logout();
    };

    // PUBLIC
    return {
        login: login,
        logout: logout
    };
};

angular
    .module('app')
    .controller('authenticationCtrl', authenticationCtrl)
服务:

function authService($state, FIREBASE_URI, Auth) {
    var model = this,
        ref = new Firebase(FIREBASE_URI);

    // LOGIN
    model.loginWithPassword = function(credentials, callBack, errorCallBack) {
        Auth.$authWithPassword(credentials)
            .then(function(authData) {
                model.cachedUser = authData;
                callBack();
            }).catch(function(error) {
                console.error("Authentication failed:", error);
            });
    };

    // LOGOUT
    model.logout = function() {
        Auth.$unauth();
        model.cachedUser = null;
        $state.go('common.login');
    };
};

angular
    .module('app')
    .service('authService', authService)

如果使用Firebase的电子邮件和密码身份验证提供程序,则无法手动使令牌无效。实现这一点的唯一方法是使用a自己生成令牌。然后,您可以通过撤销用于生成令牌的Firebase机密来使令牌无效。

如果您使用Firebase的电子邮件和密码身份验证提供程序,则无法手动使令牌无效。实现这一点的唯一方法是使用a自己生成令牌。然后,您可以通过撤销用于生成令牌的Firebase机密来使令牌无效。

$unauth
不应使令牌无效。它只是取消客户端身份验证并从客户端存储中清除令牌。
$unauth
不应使令牌无效。它只是取消对客户端的身份验证,并从客户端存储中清除令牌。