阻止Firebase身份验证记住Google帐户?

时间:2017-11-14 14:21:15

标签: firebase firebase-authentication google-oauth2 google-authentication firebaseui

因此我使用Firebase-UI对用户进行身份验证和登录,我需要使用帐户选择器才能让他们登录其他Google帐户(不使用帐户选择器导致其自动签名)但是,我想阻止它显示+保存帐户,或者在退出时删除它们。

这是我正在使用的Firebase-UI网络:Firebase UI web

当应用程序在用户的计算机上运行时,这不是一个大问题,但是,它也将在许多用户登录的公共计算机上运行,​​我们不能将它们保存为简单的一键登录。最大的安全问题是,一旦他们通过Google验证,我也可以登录他们的电子邮件。我们希望它们一旦退出就会忘记它们。

我的登录流程:

     <script type="text/javascript">
            // FirebaseUI config.
            var uiConfig = {
                callbacks: {
                    signInSuccess: function (user, credential, redirectUrl) {
                        var userSignIn = {
                            displayName: user.displayName,
                            email: user.email,
                            emailVerified: user.emailVerified,
                            photoURL: user.photoURL,
                            uid: user.uid,
                            phoneNumber: user.phoneNumber
                        };
                        /* POST signed in user to Login Controller*/
                        var csrfToken = $('input[name="csrfToken"]').attr('value');
                        $.ajaxSetup({
                            beforeSend: function(xhr) {
                                xhr.setRequestHeader('Csrf-Token', csrfToken);
                            }
                        });
                        $.ajax({
                           url: '/signedIn',
                           type: 'POST',
                           data: JSON.stringify(userSignIn),
                           contentType: 'application/json',
                           error: function(err) {
                               console.log(err);
                           }
                        });
                        return true;
                    }
                },
                signInSuccessUrl: '/Dashboard',
                signInOptions: [{
                    provider: firebase.auth.GoogleAuthProvider.PROVIDER_ID,
                    scopes: ['https://www.googleapis.com/auth/calendar']
                }],
                // Terms of service url.
                tosUrl: '/Terms'
            };

            // Initialize the FirebaseUI Widget using FirestoreDB.
            var ui = new firebaseui.auth.AuthUI(firebase.auth());
            // The start method will wait until the DOM is loaded.
            ui.start('#firebaseui-auth-container', uiConfig);
    </script>

退出流程:

initApp = function () {
firebase.auth().onAuthStateChanged(function (user) {
    if (user) {
        // User is signed in.
        if (window.location.pathname === "/Login" || window.location.pathname === "/") {
            window.location.href = '/Dashboard';
        }
        $('#sign-out').show();
    } else {
        // User is signed out.
        $('#sign-out').hide();
        disableLinks();
        switch(window.location.pathname){
            case "/Login":
            case "/Terms":
            case "/Help":
                break;
            default:
                window.location.href = '/Login';
        }
    }
}, function (error) {
    console.log(error);
});
};

window.addEventListener('load', function () {
initApp();
document.getElementById('sign-out').addEventListener('click', function () {
    firebase.auth().signOut().then(function() {
        sessionStorage.clear();
        localStorage.clear();
        window.location = "/Logout";
    }).catch(function(error) {
        console.log(error);
        });
    });
  });

1 个答案:

答案 0 :(得分:1)

从Firebase Auth注销后,重定向到Google单点注销网址:

firebase.auth().signOut()
  .then(function() {
    window.location.assign('https://accounts.google.com/Logout');
  })
  .catch(function(error) {
    console.log(error);
  });