簡體   English   中英

即使用戶已登錄,如何強制用戶重新輸入Facebook密碼

[英]How to force the user to re-enter facebook password even though he/she is logged in

我試圖讓用戶在進入我網站的某些部分時重新輸入密碼。 我已經閱讀到我應該使用“重新認證”授權類型來解決此問題,但是遇到兩個問題。

  1. 當用戶單擊“重新認證”按鈕時,密碼已在“密碼”輸入框中填寫。

  2. 當用戶單擊“重新認證”按鈕,然后關閉或單擊授權窗口上的取消時,我仍然會返回登錄數據的響應,並且基本上可以“告訴”用戶已登錄的代碼。

有沒有人遇到過這些問題? 這是我的代碼的一部分:

<fb:login-button id="facebook-reauth" onclick="return false;">Login with Facebook</fb:login-button>


<script type="text/javascript">
    $(document).ready(function () {
        document.getElementById('facebook-reauth').onclick = function () {
            FB.login(function (response) {
                if (response) {
                    window.location = '/Account/FacebookLogin?isCheckout=false';
                }
                else {
                    window.location = '/';
                }
            }, { scope: 'email', auth_type: 'reauthenticate' });
        };
    });
</script>

編輯:

我嘗試將<fb:login-button />更改為<div />標記,但是它根本沒有幫助。

非常感謝!

  1. 密碼字段可能是預先填寫的,因為您的瀏覽器只會為您記住密碼,嘗試在瀏覽器中清除密碼,或者嘗試使用瀏覽器無法記住的其他電子郵件。

  2. 我認為您只是忘了檢查response.authResponse ,所以它應該是:

FB.login(function (response) {
    if (response.authResponse) {
        window.location = '/Account/FacebookLogin?isCheckout=false';
    }
    else {
        window.location = '/';
    }
}, { scope: 'email', auth_type: 'reauthenticate' });

編輯

是的,沒錯,即使用戶取消了重新身份驗證,也會執行回調,並且狀態為“已連接”。
這可能是錯誤或其他問題,但是從我現在進行的測試來看,如果用戶成功完成了重新身份驗證過程,則令牌會發生更改,因此這應該可行:

var oldToken = FB.getAccessToken();

FB.login(function (response) {
    if (response.authResponse && response.authResponse.accessToken != oldToken) {
        window.location = '/Account/FacebookLogin?isCheckout=false';
    }
    else {
        window.location = '/';
    }
}, { scope: 'email', auth_type: 'reauthenticate' });

除了(或替代地)Nitzan的解決方案,還可以在后端添加驗證。

如果你打電話:

https://graph.facebook.com/oauth/access_token_info?client_id=CLIENT_ID&access_token=ACCESS_TOKEN

您將收到以下響應:

“ access_token:...,

token_type:“軸承”,

expires_in:5937,

auth_type:“重新認證”

僅當用戶通過授權模式成功重新驗證后,auth_type才會設置為“ reauthenticate”。

還建議您驗證expires_in> 0以確保令牌仍然有效。

if (response.status === 'connected') {
    /**
     * Even if the user cancels the re-authentication the callback is executed and the status is "connected".
     * This is probably a bug or something, but you can get info about the token and check that.    
     */
    FB.api('/debug_token', {
        input_token: response.authResponse.accessToken
    }, function(token_info) {

        if (typeof token_info.data.metadata != 'undefined') {

            if (token_info.data.metadata.auth_type == "reauthenticate") {

            }
        } else {
            //user did not re-authenticate so do nothing
        }
    });
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM