[英]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以及如何检索访问令牌,我的问题是:
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相关联并将用户登录。
The approach I described above works for well. 我上面描述的方法很有效。 Here's the summary: 以下是摘要:
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.