[英]Should I handle CODE using Javascript SDK FB.login POP-UP or is it handled automatically to gain the access_token?
在此的身份验证流程文档中,它提到了在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'});
我想知道,因为我想确保我的代码是安全的。
从文档中
有了此代码,您就可以继续进行下一步应用程序身份验证,以获取进行API调用所需的访问令牌。
为了对您的应用进行身份验证,您必须在https://graph.facebook.com/oauth/access_token处将授权代码和应用机密传递到Graph API令牌端点。 该应用程序密码可从Developer App中获得,并且不应与任何人共享或嵌入在您将分发的任何代码中(在这些情况下,您应使用客户端流程)。
如果计划使用FB.api函数调用其Graph API,则需要代码来获取访问令牌。 但是,如果您只需要验证用户身份,那么您所拥有的就可以了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.