使用我的应用程序密钥生成 Facebook 签名?
当您使用“facebook connect”建立网站并使用用户名和密码登录 facebook 时,facebook 就会在您的网站上设置一个会话。
在该会话中会生成一个“签名”。
该签名是通过将只有您和 Facebook 知道的“应用程序机密”数据与 MD5 散列结果相结合而创建的。
我需要用于生成该签名的算法,以便我可以重新创建它并确保它与 Facebook 创建的签名相匹配。
if($_SESSION['facebookSignature'] == reGeneratedSignature){
// save to database
}else{
// go away I don't trust you
}
这样我就可以验证用户,并且不需要对 Facebook 进行不必要的调用并允许用户继续使用该网站。
When you build a website with "facebook connect" and you log into facebook with your username and password, facebook then sets a session on your website.
In that session is a generated "signature"
This signature is created by combining the data of your "application secret" that only you and Facebook know, and the result MD5 hashed.
I need the algorithm used to generate that signature so that I can recreate it and make sure it matches the one signature created by facebook.
if($_SESSION['facebookSignature'] == reGeneratedSignature){
// save to database
}else{
// go away I don't trust you
}
This way I can validate the user and I don't need to make unnecessary calls to Facebook and alow the user to continue to use the website.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
验证签名链接是可行的方法,因此应该适合您。
查看 FBConnectAuth 的源代码,它确实你想要什么,并且是通用的,以便它能够适应可能出现的任何新的 FB Connect cookie - 因此希望它能够适应新的 JS 库。
希望有帮助,
亚当
The Verifying The Signature link is the way to go, so that should be working for you.
Have a look at the source code for FBConnectAuth, it does what you want, and is generic so that it will adapt to any new FB Connect cookies that may appear - so hopefully that will adapt to the new JS library.
Hope that helps,
Adam
重建 Facebook 创建的签名相当简单。您只需附加所有
key=value
对,然后附加您的私钥,最后计算结果字符串的 MD5 哈希值。有关如何构建签名的更多详细信息,请参阅此 答案。
Facebook 在 此处 中提供了一个 PHP 示例,说明如何重建 sig单点登录部分。
我写了一篇 博客文章 做的完全一样,但是用 Ruby 代替。
Reconstructing the signature created by Facebook is rather simple. You just need to append all
key=value
pairs, then append your private key, and finally compute the MD5 hash of the resulting string.More details on how the signature is constructed can be found on this answer.
Facebook has provided a PHP example of how to do reconstruct the sig here in the Single Sign-On section.
I have written a blog post doing exactly the same, but in Ruby instead.