对网站的REST API,它使用Facebook的身份验证 [英] REST API for website which uses Facebook for authentication

查看:178
本文介绍了对网站的REST API,它使用Facebook的身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个网站,其中的只有的方式登录,并与该网站与Facebook验证自己的身份(这不是我的选择)。你与Facebook首次登录,账号就会自动为您创建。

We have a website where the only way to login and authenticate yourself with the site is with Facebook (this was not my choice). The first time you login with Facebook, an account gets automatically created for you.

我们现在要创造我们的网站其他iPhone应用程序,也是一个公共API来使用我们的服务。

We now want to create an iPhone application for our site and also a public API for others to use our service.

这个问题是关于如何使用我们的网站从应用程序/ API认证,并分为两部分:

This question is about how to authenticate with our website from the app/API and is broken into 2 parts:


  1. 什么是从一个API处理REST身份验证一个网站,只使用Facebook的OAuth的作为身份验证方法的正确方法是什么?

  1. What is the correct way to handle REST authentication from an API to a website which only uses Facebook OAuth as an authentication method?

我已阅读并研究了很多有关REST API认证的标准方法。我们不能用这样的方法如基本认证通过HTTPS ,因为没有凭据,请用户本身。类似<一个href=\"http://www.thebuzzmedia.com/designing-a-secure-rest-api-without-oauth-authentication/\">this似乎只有使用API​​认证的应用程序。

I have read and researched a lot about standard methods of authentication for REST API. We can't use such methods as Basic Auth over HTTPS, as there are no credentials for a user as such. Something like this seems to be only for authenticating applications using the API.

目前,我能想到的最好的办法就是你打我们的API AN /授权终点,它重定向到Facebook的OAuth的,然后重定向回网站,并提供了一​​个令牌的API的用户可以使用哪些验证后续请求。

Currently, the best way I can think is you hit an /authorize end-point on our API, it redirects to Facebook OAuth, then redirects back to the site and provides a 'token' which the user of the API can use to authenticate subsequent requests.

有关,我们创建一个正式的申请,我们不一定需要使用公共API以同样的方式。什么是最好的方式再谈谈我们的网站和用户进行身份验证?

For an official application that we create, we wouldn't necessarily need to use the public API in the same way. What would be the best way then to talk to our website and authenticate users?

我的理解(我认为)如何进行身份验证正在使用我们的API,使用API​​(公共)密钥和密钥(私有)密钥第三方应用程序。然而,当涉及到验证谁在使用应用程序的用户,我得到相当困惑如何去了解它时,唯一的办法,我们必须验证用户是Facebook的。

I understand (I think) how to authenticate 3rd-party applications that are using our API, using API (public) keys and secret (private) keys. However, when it comes to authenticating the user who is using the app, I am getting rather confused about how to go about it when the only way we have to authenticate a user is Facebook.

我觉得我失去了一些东西很明显,或者没有完全理解REST API的应该怎么公开工作,所以任何的建议和帮助将不胜AP preciated。

I feel like I'm missing something very obvious, or don't fully understand how public REST APIs should work, so any advice and help would be greatly appreciated.

推荐答案

我一直在苦苦思考这个问题了。这并不完全清楚,我还没有,但这里是我想到的是去的路线。我创建一个REST API的我的用户的只有的与Facebook连接权威性

UPDATE: see below

I've been thinking hard about this question too. It's not entirely clear to me yet but here's the route I am thinking of going. I am creating a REST API an my users only auth with Facebook connect.

上的客户端:


  1. 使用Facebook的API来登录并获得了OAuth2 code。

  2. 交换这code一个访问令牌。

  3. 在每次调用我的自定义API,我会包括Facebook的用户ID和访问令牌。

在(需要用户身份验证每一个方法)的API:

On the API (for every method that requires user authentication):


  1. 使用访问令牌上面做的/我的Facebook图形的请求。

  2. 验证Facebook用户ID返回传递给我的API从上面的用户ID相匹配。

  3. 如果访问令牌已过期额外的通信是必需的。

我还没有进行测试。音质如何?

I have yet to test this. How does it sound?

我只在登录时使用上述交流一次。一旦我确定哪些用户登录,创建我自己的访问令牌,以及令牌从该点前进中。因此,新的流程是这样的...

I only use the above exchange once upon login. Once I determine which user is logging in, I create my own access token, and that token is used from that point going forward. So the new flow looks like this...

上的客户端:


  1. 使用Facebook的API来登录并获得了OAuth2 code。

  2. 交换这code一个访问令牌。

  3. 从请求访问令牌的我的的API,其中包括Facebook的令牌作为参数

  1. Use the Facebook API to login and get an OAUTH2 code.
  2. Exchange this code for an access token.
  3. Request an access token from my API, including the Facebook token as a parameter

在API


  1. 接收接入令牌请求。

  2. 使用Facebook访问令牌做的/我的Facebook图形的要求

  3. 验证Facebook的用户存在和匹配,以用户在我的数据库

  4. 创建我自己的访问令牌,将其保存并返回给客户端从这个角度提出
  5. 使用

这篇关于对网站的REST API,它使用Facebook的身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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