在此处的身份验证流程文档中,它提到了在 oAuth 身份验证时返回的 CODE。
这是 Javascript SDK 所必需的,还是在此代码的后台自动处理?
通过“这是必需的吗?” 我的意思是,我是否必须处理此代码来验证请求的真实性,或者 JavaScript SDK 是否自动使用该代码来获取access_token.
该文档解释了客户端流程,以及如何使用“代码”获取访问令牌,直到现在。我一直假设 SDK 在后台自动管理它,因为它生成的访问代码为response.authResponse.accessToken.
FB.login(function(response) {
if (response.authResponse) {
// User is logged in to Facebook and accepted permissions
// Assign the variables required
var access_token = response.authResponse.accessToken;
var fb_uid = response.authResponse.userID;
alert(dump(response.authResponse));
// Construct data string to pass to create temporary session using PHP
var fbDataString = "uid=" + fb_uid + "&access_token=" + access_token;
// Call doLogin.php to log the user in
$.ajax({
type: "POST",
url: "ajax/doLogin.php",
data: fbDataString,
dataType: "json",
success: function(data) {
// Get JSON response
if (data.result == "failure")
{
alert(data.error_message);
window.location.reload();
return false;
}
else if (data.result == "success")
{
window.location.reload();
return true;
}
},
error: function() {
return false;
}
});
} else {
// user is not logged in and did not accept any permissions
return false;
}
}, {scope:'publish_stream,email'});
我想知道,因为我想确保我的代码是安全的。