如何强制用户在登录后重新输入facebook密码
我试图让用户在进入我网站的某些部分时重新输入密码。我已经读到我应该使用“重新验证”授权类型来解决这个问题,但是我遇到了两个问题如何强制用户在登录后重新输入facebook密码,facebook,authentication,facebook-authentication,Facebook,Authentication,Facebook Authentication,我试图让用户在进入我网站的某些部分时重新输入密码。我已经读到我应该使用“重新验证”授权类型来解决这个问题,但是我遇到了两个问题 当用户单击“重新验证”按钮时,“密码”输入框中已填写密码 当用户单击“重新验证”按钮,然后关闭或单击授权窗口上的“取消”时,我仍然会收到带有登录数据的响应,基本上它会“告诉”我的代码用户已登录 有人遇到过这些问题吗?以下是我的部分代码: <fb:login-button id="facebook-reauth" onclick="return false;">
<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>
使用Facebook登录
$(文档).ready(函数(){
document.getElementById('facebook-reauth')。onclick=function(){
FB.登录(功能(响应){
如果(答复){
window.location='/Account/FacebookLogin?isCheckout=false';
}
否则{
window.location='/';
}
},{scope:'email',auth_type:'reaauthenticate'});
};
});
编辑:
我尝试将
更改为
标记,但没有任何帮助
非常感谢
response.authResponse
,所以它应该是:编辑 是的,您是对的,即使用户取消了重新身份验证,也会执行回调,并且状态为“已连接”。
这可能是一个bug或其他问题,但从我现在所做的测试来看,如果用户成功完成了重新身份验证过程,则令牌会发生更改,因此这可能会起作用:
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的解决方案,还可以在后端添加验证
如果你打电话:
“”
您将得到以下响应:
“访问令牌:
令牌类型:“承载者”
地址:5937
验证类型:“重新验证”
只有通过授权模式成功地对用户重新进行身份验证时,身份验证类型才会设置为“重新身份验证”
此外,还建议验证expires\u in>0以确保令牌仍然有效。“只是一个想法:是否可能使用标记作为按钮会破坏它?”–也是一个想法:请在询问之前验证这些内容。不,这不起作用。响应状态为“已连接”,因此,基本上即使用户单击“取消”或关闭窗口,他仍会获得身份验证。应用程序的后端应将访问令牌发送到
access\u token\u info
API。如果您向FB.login()
提供了一个auth\u nonce
,它就会在那里。虽然这个答案可能是正确的和有用的,但最好是随附一些解释来解释它如何帮助解决问题。如果有一个变化(可能是无关的)导致它停止工作,并且用户需要了解它曾经是如何工作的,那么这在将来变得特别有用。
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
}
});
}
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
}
});
}