简体   繁体   English

通过Facebook Connect Android验证用户

[英]Authenticate User via Facebook Connect Android

Currently on our website we enable users to login/register with their Facebook credentials using graph api . 目前在我们的网站上,我们允许用户使用图形api登录/注册他们的Facebook凭据。 We are creating a mobile app and we want to support login with Facebook as well. 我们正在创建一个移动应用程序,我们也希望支持使用Facebook登录。 I know about the Facebook Android SDK and how to retrieve the access token, my question is: 我知道Facebook Android SDK以及如何检索访问令牌,我的问题是:

  1. Once I have the facebook access token, how can I authenticate the user with our backend system. 一旦我拥有了facebook访问令牌,我该如何使用我们的后端系统对用户进行身份验证。

One idea is to pass the access_token to my backend server and query for the user's facebook id (I don't want to pass the facebook id because someone can just spoof the request). 一个想法是将access_token传递给我的后端服务器并查询用户的facebook id(我不想传递facebook id,因为有人可以欺骗请求)。 Now using the facebook id I can then associate it with our user id and log the user in. 现在使用facebook id我可以将它与我们的用户ID相关联并将用户登录。

  1. Would this method work, or there's another solution 这种方法是否有效,或者还有另一种解决方案

The approach I described above works for well. 我上面描述的方法很有效。 Here's the summary: 以下是摘要:

  1. Facebook connect through the iPhone app Facebook通过iPhone应用程序连接
  2. Retrieve the fb access token on the phone 检索手机上的fb访问令牌
  3. Send the fb access token to your Rails server 将fb访问令牌发送到您的Rails服务器
  4. The controller that you are using will check for the fb param and query the user information 您正在使用的控制器将检查fb参数并查询用户信息

    Sample of how the controller might look like 控制器的外观示例

  if params[:fb_access_token] @graph = Koala::Facebook::GraphAPI.new(params[:fb_access_token]) @me = @graph.get_object("me") if profile = Profile.find_by_facebook_uid(@me["id"]) user = profile.user render :text => user.access_token else render :text => "unregistered", :status => 401 and return end else 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM