使用 Android 对我的服务器进行 Facebook 身份验证
我正在构建一个具有以下块的应用程序:
Android - 客户端, Java Servlet - 服务器端, Facebook 应用程序 - 用于验证用户身份并处理他们的数据。
我的问题如下: 我想通过 facebook 验证我的用户(例如使用 facebook-android-sdk 从 android 客户端发送到 facebook 的请求),但随后我想将请求发送到我的服务器(由 servlet 实现)并以某种方式进行验证发送请求的用户已通过 Facebook 和我的应用程序的身份验证。
这些是步骤:
用户 X 使用 facebook-android-sdk 向 facebook 和我的 facebook 应用程序进行身份验证。 X 正在向我的服务器发送请求
至于服务器,我只想知道它是与我一起工作的正确用户,我不需要服务器执行任何图形 API 请求。
我如何知道 X 在我的服务器中有效?在这种情况下,身份验证是在客户端执行的。
I'm building an application with the following blocks:
Android - Client Side,
Java Servlets - Sever Side,
Facebook app - used in order to authenicate users and work with their data.
My Problem is the following:
I would like to authenticate my users via facebook (such as a request sent from the android client using facebook-android-sdk to facebook) but then I would like to send requests to my server (which is implemented by servlets) and to validate somehow that the user sending the request is authenticated to facebook and my application.
So these are the steps:
user X is authenicated to facebook and my facebook app using facebook-android-sdk.
X is sending a request to my server
As for the server, I would only like to know it's a proper user which is working with me, I don't need the server to perform any Graph API requests.
How can I know that X is valid in my server? The authentication was performed on client side in that case.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
所以你有:Facebook - Android 应用程序 - 你的网络服务器。并且您的网络服务器需要知道您是您所呈现的 Facebook 用户。问题是您不能信任 Android 客户端提供给您的任何数据。
我解决了这样的问题:
如果来自您的 Web 服务器的调试端点 API 调用返回有效信息(应用程序 ID 和用户 ID),则您的服务器可以信任该 ID(并且您可以确定 Android 身份验证是真实的)
So you have: Facebook - Android Application - Your web server. And your web server needs to know that you are the Facebook user you are presenting. The problem is that you can not trust the Android client for any data it gives to you.
I solved the problem like this:
If the debug endpoint API call from your web server returns valid information (app id & user id), your server can trust the id (& you can be sure that the Android authentication is real)
这个问题的更好答案(结合 tomas.tunkl 评论中的信息)如下:
(由于我链接了文档,因此我还将在此处放置来自调试和错误处理链接的一些信息,以展示如何进行调用以及返回什么:)
这将确保您拥有 Facebook 用户的有效令牌,该令牌是根据您自己的用户密钥生成的;这意味着他们已正确进行身份验证。
The better answer to this question (incorporating info from tomas.tunkl's comment) is as follows:
(Since I linked the documentation, I'm also going to put a bit of info from that debugging-and-error-handling link in here to show how to make the call and what you get back:)
This will ensure that you have a valid token for a facebook user that has been generated from your own secret key for a user; meaning that they have authenticated properly.