如何安全地将Facebook ID从客户端传递到服务器(How to pass Facebook Id from client to server securely)
我有一个Facebook的画布应用程序。 我使用JS SDK在浏览器端对用户进行身份验证,并通过FB.api(例如姓名,朋友等)请求各种信息。
我还想通过发出ajax调用来将一些额外的用户信息(不在Facebook上)保存到服务器上的数据库中:
{ userFavouriteColour: "Red" }
为了将其保存在服务器上并与正确的用户相关联,我需要知道Facebook的uid,这就提出了一个问题。 我如何将客户端的uid传递给服务器。
选项1:将uid添加到ajax请求中 :
{ uid: "1234567890", userFavouriteColour: "Red" }
这显然不好。 任何人使用其他人的Facebook ID向我的网络服务发出ajax请求并改变他们最喜欢的颜色是微不足道的。
选项2:在服务器上,从cookie中提取uid :这甚至可能吗? 我读过Facebook设置了一个包含uid和访问令牌的cookie,但是我有权访问我的域上的这个cookie吗? 更重要的是,我可以安全地从cookie中提取uid,或者可以像选项1那样公开欺骗。
选项3:服务器上的用户服务器端身份验证 :我可以使用服务器端身份验证来验证服务器上的用户身份。 但是,如果我已经在浏览器上使用客户端身份验证,这将工作吗? 我最终会得到两个不同的访问令牌吗? 我想从浏览器发出FB.api请求,所以我需要客户端上的访问令牌(不只是在服务器上)。
这一定是非常普遍的情况,所以我认为我错过了一些基本的东西。 我已经阅读了大量的Facebook文档(各种认证流程,访问令牌,signed_request等)和许多帖子,但我仍不明白客户端身份验证和服务器端身份验证如何良好地结合在一起。
总之,我想知道用户在服务器上的身份,但仍然从客户端浏览器向Facebook API发出请求?
(我正在使用ASP.NET和服务器上的Facebook C#SDK)
编辑 :增加赏金。 我希望得到一个更明确的官方建议如何处理这种情况,甚至是一个例子。 如上所述,我已经阅读了很多关于认证流程的官方FB文档,但我仍然无法找到关于客户端和服务器端认证如何协同工作的任何明确信息。
I have a Facebook canvas app. I am using the JS SDK to authenticate the user on the browser-side and request various information via FB.api (e.g. name, friends, etc.).
I also want to persist some additional user information (not held on Facebook) to the database on my server by making an ajax call:
{ userFavouriteColour: "Red" }
To save this on the server and associate with the correct user, I need to know the Facebook uid and this presents a problem. How do I pass the uid from the client to the server.
Option 1: Add uid to the ajax request:
{ uid: "1234567890", userFavouriteColour: "Red" }
This is obviously no good. It would be trivial for anyone to make an ajax request to my web service using someone else's Facebook Id and change their favourite colour.
Option 2: On the server, extract the uid from a cookie: Is this even possible? I have read that Facebook sets a cookie containing the uid and access token but do I have access to this cookie on my domain? More importantly, can I securely extract the uid form the cookie or is this open to spoofing just like option 1.
Option 3: User server-side authentication on the server: I could use the server-side authentication to validate the user identity on my server. But will this work if I am already using client-side authentication on the browser? Will I end up with two different access tokens? I would like to make FB.api requests from the browser so I need the access token on the client (not just on the server).
This must be a very common scenario so I think I'm missing something fundamental. I have read a lot of the Facebook documentation (various authentication flows, access tokens, signed_request, etc.) and many posts on SO, but I still don't understand how client-side authentication and server-side authentication play nicely together.
In short, I want to know the user's identity on the server but still make requests to the Facebook api from the client browser?
(I am using ASP.NET and the Facebook C# SDK on the server)
EDIT: Added bounty. I was hoping to get a more deifnitive, official recommendation on how to handle this situation, or even an example. As said, I have already read a lot of the official FB docs on authentication flows but I still can't find anything definitive on how client-side and server-side authentication work together.
原文:https://stackoverflow.com/questions/10738068
最满意答案
如果你可以全局安装gulp,那就去做吧
npm install -g gulp
(可能需要
sudo
- 使用sudo,或谷歌“修复npm权限”)如果你不能全局安装gulp,这里有一些解决方案:
使用gulp而不使用全局gulp //编辑:并且不链接到bin js文件If you can install gulp globally, do it
npm install -g gulp
(may require
sudo
- use sudo, or google "fix npm permissions")If you can't install gulp globally, there are some solutions here:
Using gulp without global gulp //edit: and without linking to the bin js file
相关问答
更多-
如果未设置则抛出错误: gulp.task('myBuild', function () { if (providedSubdir === undefined) throw new Error("you need to specify `providedSubdir`"); // Rest of the task }); Just throw an error if it is not set: gulp.task('myBuild', function () { ...
-
如果你可以全局安装gulp,那就去做吧 npm install -g gulp (可能需要sudo - 使用sudo,或谷歌“修复npm权限”) 如果你不能全局安装gulp,这里有一些解决方案: 使用gulp而不使用全局gulp //编辑:并且不链接到bin js文件 If you can install gulp globally, do it npm install -g gulp (may require sudo - use sudo, or google "fix npm permission ...
-
我已经确定了一种我认为合适的解决方法,除了添加的目标以外,它似乎没有明显的缺点。 简而言之:解决方案包括添加一个静态库目标 ,以利用Xcode在这样的目标周围创建和运行单元测试代码的能力。 然后,命令行工具目标将委托给静态库,在该静态库中,由真正的main()入口点定义并调用备用的类似main()的函数。 命令行工具没有非平凡的代码,因此单元测试目标可以访问所有值得测试的东西。 这里是步骤: 从空的Xcode中,从菜单中选择File ... New Project 。 在出现的对话框中,选择OS X ... ...
-
根据相关的Gem文档 ,您可以指定(在您的.gemspec中): spec.executables = ['bin/foo', 'bin/bar'] spec.default_executable = 'bin/bar' 并让你的宝石安装一堆可执行文件( foo和bar )。 或者你为你所有的Thor脚本编写一个包装器并指定: spec.executables = ['bin/wrapper'] 并让你的宝石只安装一个可执行文件( wrapper )。 According to the relevant ...
-
似乎没有任何选择gulp-ruby-sass会有所帮助,而且现在已经有几个月关于这个问题的开放GitHub问题了 ,所以我认为你必须通过hacky解决方案来弥补。 我唯一能想到的是将所有SCSS文件分成批处理并为每个批处理调用一次sass然后使用merge-stream 。 为此,您必须首先找到所有SCSS文件,这意味着您需要直接使用glob 。 以下是这样的解决方案的样子: var glob = require('glob'); var merge = require('merge-stream'); ...
-
将参数传递给gulpfile.js中的Gulp任务(不是命令行)(Pass parameter to Gulp task in gulpfile.js (not command-line))[2022-08-08]
我发现gulp手表有一个变化的事件。 所以这可能是你正在寻找的: var pagesDir = 'sass/pages/'; gulp.task('watch_pages', function() { gulp.watch(pagesDir + '**/*') .on("change", function(file) { // absolute path to folder that needs watching var change ... -
我假设您已经在InterfaceBuilder中正确连接了NSDatePicker,因此它连接到DatePicker。 如果是这样,您应该能够分配如下: NSDate * unformattedDate = [ datePicker dateValue ]; 然后使用unformattedDate作为格式化程序的输入,像以前一样进行格式化。 I'm assuming you have the NSDatePicker correctly hooked up in InterfaceBuilder so i ...
-
如何创建使用gulp的node.js命令行实用程序(How do I create a node.js command line utility that uses gulp)[2023-05-19]
Gulpfiles只是节点应用程序。 您可以在节点应用中像任何模块一样要求它们: var gulpfile = require('./gulpfile.js'); 然后你可以调用gulpfile中定义的gulp任务: gulp.start('someTask'); 请注意, .start()将在gulp 4.0中弃用 把它们放在一起,看起来像是这样的: var gulp = require('gulp'); require('./gulpfile'); gulp.start('someTask'); ... -
删除方法在纽曼不工作(邮递员工具为命令行)(Delete method not working in Newman ( Postman tool for command line))[2022-02-19]
我使用POSTMAN Chrome客户端执行DELETE时从Chrome网络工具复制了curl,并发现它在请求标头中使用邮递员令牌。 在Newman中添加Postman Token到删除操作的头部,并且工作正常。 I copied the curl from chrome network tool while performing DELETE using POSTMAN Chrome client and saw that it does use postman token in the request ... -
这取决于你想要什么, 你可以: taskkill /IM dbgview.exe 但这可能无法保证所有日志都写入输出文件(我不确定会发生什么)。 您可以使用https://github.com/djeedjay/DebugViewPP/releases中的 Debugview ++ UI 并定义一个'停止'过滤器。 这将停止滚动,但不会停止收集数据。 我在https://github.com/djeedjay/DebugViewPP/issues/270上发表评论,我刚刚提交了添加命令行选项来做这件事;) ...