简体   繁体   English

即使用户已登录,如何强制用户重新输入Facebook密码

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

I am trying to get the user to re-enter the password when they are entering certain part of my website. 我试图让用户在进入我网站的某些部分时重新输入密码。 I've read that I should be using the "Reauthenticate" authorization type to solve this, but I am encountering two issues. 我已经阅读到我应该使用“重新认证”授权类型来解决此问题,但是遇到两个问题。

  1. When user clicks on "Reauthenticate" button the password is already filled out in the "Password" input box. 当用户单击“重新认证”按钮时,密码已在“密码”输入框中填写。

  2. When user clicks on "Reauthentice" button and then closes or clicks cancel on authorization window, I still get the response back with logged in data and basically it "tells" my code that the user has signed in. 当用户单击“重新认证”按钮,然后关闭或单击授权窗口上的取消时,我仍然会返回登录数据的响应,并且基本上可以“告诉”用户已登录的代码。

Did anyone ever encountered those issues? 有没有人遇到过这些问题? Here is part of my code: 这是我的代码的一部分:

<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>

EDIT: 编辑:

I tried changing the <fb:login-button /> to <div /> tag but it did not help at all. 我尝试将<fb:login-button />更改为<div />标记,但是它根本没有帮助。

Thanks a lot! 非常感谢!

  1. The password field is probably pre-filled cuz your browser just remembers the password for you, try to clear that in your browser, or try to use a different e-mail which the browser does not remember. 密码字段可能是预先填写的,因为您的浏览器只会为您记住密码,尝试在浏览器中清除密码,或者尝试使用浏览器无法记住的其他电子邮件。

  2. I think that you just forgot to check for response.authResponse , so it should probably be: 我认为您只是忘了检查response.authResponse ,所以它应该是:

.

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

Edit 编辑

Yes, you are right, 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 from the tests I did now it looks like if the user finished the re-authentication process successfully then the token changes, and so this should probably work: 这可能是错误或其他问题,但是从我现在进行的测试来看,如果用户成功完成了重新身份验证过程,则令牌会发生更改,因此这应该可行:

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' });

In addition (or instead) of Nitzan's solution it is possible to add a validation on the backend. 除了(或替代地)Nitzan的解决方案,还可以在后端添加验证。

If you call: 如果你打电话:

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

You will get the following response: 您将收到以下响应:

"access_token: ..., “ access_token:...,

token_type: "bearer", token_type:“轴承”,

expires_in: 5937, expires_in:5937,

auth_type: "reauthenticate" auth_type:“重新认证”

The auth_type will be set to "reauthenticate" only if they user successfully re-authenticated via the authorization modal. 仅当用户通过授权模式成功重新验证后,auth_type才会设置为“ reauthenticate”。

It is also advised to validate that the expires_in > 0 to make sure that the token is still valid. 还建议您验证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.

相关问题 如何强制facebook android 4.x sdk让用户重新输入其凭据? - How to force the facebook android 4.x sdk to have the user re-enter their credentials? Facebook要求用户即使已经登录也要登录 - Facebook asks user to log in even though they're already logged in 即使使用Facebook Connect登录,也强制用户输入登录 - Force user to enter login even if logged in with Facebook Connect 用户登录后重新输入特定页面的密码 - re-enter password for specific pages after user login 如果没有登录Facebook用户ID,该如何获取? - How to get a facebook user id if he is not logged into your app? 即使他们没有登录,用户也应该查看我的Facebook Wall页面? - User should view my facebook Wall page, even though they are not logged in? 当用户注销我的iOS应用程序时,下次他们尝试使用Facebook登录时,应该重新输入其登录凭据 - When a user logs out of my iOS app, the next time they try to login with Facebook, they should have to re-enter their login credentials Facebook PHP SDK-即使从Facebook注销,用户仍显示为登录Web应用程序 - Facebook PHP SDK - User still shows as logged in on web app even though logged out of Facebook 用户通过asp.net登录到Facebook时如何阅读或保存其电子邮件? - How to read or save the email of the user when he logged in to facebook through asp.net? 即使我登录到Facebook,Facebook会话也已过期 - Facebook session is expired even though I am logged in to facebook
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM