Facebook Connect 在个人 API 上进行身份验证 [英] Facebook Connect to authenticate on a personal API

查看:39
本文介绍了Facebook Connect 在个人 API 上进行身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发了一个简单的 API 来允许我的 Android/iPhone 应用程序和我的服务器之间的通信.在我的应用程序中,用户需要通过以下 API 调用使用登录名/密码凭据进行身份验证:

I have developed a simple API to allow communication between my Android/iPhone apps and my server. In my application, users need to authenticate themselves and they do it using login/password credentials with the following API call:

http://api.myapp.com/login?user=xxx&pass=pass

应用收到的回报:

{ "api_token": "xxxx-xxxx-xxxx-xxxx" }

所以基本上我将我的凭据与 api_token 交换.

So basically I exchange my credentials against api_token.

我想添加 Facebook 连接支持.我已成功使用 Facebook SDK 并收到正确的 access_token.

I would like to add Facebook connect support. I have successfully used the Facebook SDK and receives the correct access_token.

但是,我需要实现一种机制来将 access_tokenapi_token

However, I need to implement a mechanism to exchange access_token with api_token

假设用户已经将他的帐户与 Facebook 连接(在他的网络用户面板上),进行交换的最佳实施是什么?

Assuming the user has already connected his account with Facebook (on his web user panel), what would be the best implementation to proceed to the exchange?

推荐答案

这是我最终做到的.一年多来运行良好,从未出现过任何问题.这个想法是使用以下 API 调用交换令牌:

Here is how I finally did it. It's working very well for more than one year, never had any problem. The idea is to exchange tokens using the following API call:

http://api.myapp.com/login/facebook?access_token=<facebook_access_token>

服务器端,你用一个简单的

Server side, you verify validity of the access_token with a simple

wget -qO- https://graph.facebook.com/me?access_token=<facebook_access_token>

这会向您发送回包含所有用户信息的 JSON,包括用户的 Facebook ID.假设用户已经将他的帐户连接到 Facebook,您可以查找 user_id 并发送回 api_token.

Which sends you back a JSON with all user information, including user's Facebook ID. Assuming the user has already connected his account to Facebook, you can lookup the user_id and send back an api_token.

这篇关于Facebook Connect 在个人 API 上进行身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆