我怎么可以验证从web应用程序的API用户? [英] how can I authenticate a user from a web app to an API?

查看:228
本文介绍了我怎么可以验证从web应用程序的API用户?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这似乎是一个被广泛提出的问题,并有关于这个问题的读吨单证后,我真不知道要正确明白了一切(我认为是愚蠢的是一个可能的答案)。)

It seems to be a widely asked questions and after having read tons of documentations on the subject, I'm still not sure to have understood everything correctly (I assume that being dumb is a possible answer ;)).

我想建立一个API,它会向用户提供的服务。用户将通过Facebook或任何OpenID提供商进行连接(我因为他们的实现自己的连接系统分开Facebook的)。

I'm trying to build an API that will provide a service to users. The users will be connected through Facebook or any OpenId provider (I separate Facebook since their implement their own connecting system).

(我认为这是一个很好的方式,因为我不会存储用户的密码,并最终将在一个类似Gawker的问题的情况下,较少的问题。)

当一个请求从客户端(web应用程序,移动应用,等等)的API,一个指标的必须与请求,以确定哪个用户正在使用的应用程序发送的。这是通过通常使用的标记,在验证过程中定义的。

When a request is made from the client (web app, mobile app, whatever) to the API, an indicator must be sent with the request in order to identify which user is using the app. This is generally used via a token, defined during the Authentication.

而对于身份验证,我的不能找到任何有价值的例子,教程,了解如何正确地实现它的解释。

But regarding the Authentication, I can't find any valuable example, tutorial, explanations about how to implement it correctly.

我会(尽量)解释:

在我的(幸福护理熊美妙的世界),我结构性我的项目在不同的部分:

In my (wonderful world of happy care bears), I structured my project in various parts :


  • 一个RESTful API

  • 将使用该API上的Web应用程序。理想情况下,我在想制作完整的HTML / CSS / JS项目,没有任何服务器端工作(PHP / Python的/ java或其他)

  • 移动应用

  • 的Windows / Mac的/ Linux应用程序

据我所看到的,每次有人问如何实现一个RESTful API认证,三大答案弹出:

As far as I saw, every time someone ask how to implement a RESTful API authentication, three major answers pops out :


  • HTTP基本(+ preferably SSL)/消化方式

  • 的OAuth

  • 的OpenID

由于我不会存储用户的密码,第一个是为我,但其他两个离开我困扰。

Since I will not store the user's password, the first one is out for me, but the two other leave me perplex.

不过的OAuth和OpenID是的不可以萨姆斯,一个(的OpenID)代表在验证(即提问的基地),其中第二(的OAuth)代表在授权

But OAuth and OpenId are not the sames, one (OpenId) stand for the Authentication (that the base of the questions) where the second (OAuth) stand for the Authorization!

在微博实现OAuth的为他们的API,他们没有实施身份验证系统中,有正在建立一种方式来表明自己的用户该应用程序x要访问的用户帐户(在不同的访问级别)。如果用户没有在当前的Twitter登录,他将第一要亲自验证,,然后授权当前的应用程序来访问他的数据。

When Twitter implements OAuth for their API, they are not implementing an Authentication system, there are setting up a way to indicate their users that the application X want to have access to the user account (in various level of access). If the user is not currently logged in Twitter, he will first have to authenticate himself, and then authorize the current application to access his data.

所以,只是为了澄清事实, OAuth是不是一个认证机制,它是:

So, just to clear things up, OAuth is NOT an authentication mechanism, it's a :

这是开放的协议,允许安全API
  授权
  (来源: http://oauth.net/

An open protocol to allow secure API authorization (source: http://oauth.net/)

然后,验证用户身份的唯一方法是使用OpenID。然后,地狱成真。

Then, the only way to authenticate a user would be using OpenId. And then, the hell comes true.

如果我以一个例子是专门制作HTML / CSS / JS的,没有服务器端组件的Web应用程序,使用API​​沟通。

If I take as an example a web application that is exclusively made of html/css/js, with no server side components, communicate with an API.

Web应用程序必须指示到当前使用API​​用户老总X中的API。

The web app must indicate to the API that the user currently using the API is mister X.

要做到这一点,Web应用程序显示包含的OpenID提供商的名单弹出,要求用户自己进行认证。其中之一的用户点击,被重定向(或一个新的弹出窗口打开)的OpenID提供商,表明他的登录/通行证,得到了OpenID提供商,即与令牌返回成功认证(我简化了通信)。

To do so, the web app show a popup containing a list of OpenId providers, asking the user to authenticate himself. The user click on one of them, get redirected (or a new popup open up) to the OpenId provider, indicate his login/pass, get authenticated by the OpenId provider, that return the success with a token (I simplified the communication).

这是伟大的,Web应用程序现在知道用户是真正的老总X.但仍然API有任何线索!

That's great, the web app know now that the user is really mister X. But the API still have any clue !

最后,我的问题很简单:我怎样才能通过Web应用程序通过OpenID和之后的API认证老总X,Web应用程序和API如何能保持信息,这是当前正在使用的老总点¯x Web应用程序,当然,这个API。

Finally, my question is quite simple : how can I authenticate mister x through the web app to the API via OpenId and after that, how can the web app and the api keep the information that this is mister X that is currently using the web app and of course, the API.

非常感谢你的帮助!

-edited格式

推荐答案

(如果你不想读,名单娄总结整个想法)

一个可能的解决方案的(告诉我,如果我错了)的将是显示在消费者的登录表单(Web应用程序,移动应用等),就可以在用户点击的供应商(者myOpenID ,谷歌等)打开一个弹出做登录。
最棘手的部分是,的return_to参数将被设置为API,而不是网站

A possible solution (tell me if I'm wrong) would be to display the login form in the consumer (web apps, mobile apps, etc), the user click on it's provider (myopenid, google, etc) that opens a popup to do the login. The tricky part is that the return_to parameter would be set to the API, not the website

该API将然后重新发送check_authentication并获得is_valid:真(或没有)。
在此步骤中,应用程序会查询API来返回验证状态的特定的URL(加工,失败,成功)。虽然它的处理。第,指示器被显示给用户(加载GIF),并且如果它是成功/失败被显示给用户的结果。

The API will then resend the check_authentication and get the is_valid:true (or not). During this step, the app would query the api to a specific url that return the state of the authentication (processing, failed, success). While it's procesing, an indicator is displayed to the user (loading gif), and if it's success/fail the result is displayed to the user.

如果该API收到is_valid:真的,那么它会问有关的信息的用户对OpenID的服务器,如电子邮件,名字,姓氏,并比较它们与它的用户的数据库。如果存在匹配,则API创建本身和该应用之间的会话,如果用户是新的,它创建一个新的条目,然后会话

If the api receive a is_valid:true, then it will ask informations about the user to the openid server, like email, firstname, lastname, and compare them with it's user's database. If there is a match, the api create a session between itself and the app, if the user is new, it create a new entry and then the session.

该会议将是一个独特的标记与特定的时间(也许等于OpenID的服务器把assoc_handle时间?)

The session would be a unique token with a specific duration (maybe equal to the openid server assoc_handle duration ?)

这似乎是可能的事情,但我不是在安全方面的专家。

It seems to be something possible, but I'm not an expert in security.

为了解释的事情simplier,这里是一个小地图:

In order to explain things simplier, here is a little "map" :

注:供应商是OpenID服务器(即提供有关认证信息)

Note: Provider is the OpenId server (that provide the informations about the authentication)


  • 用户去web应用程序,点击他的供应商(谷歌为前)的登录图标

  • web应用程序打开一个包含供应商登录页并访问页面弹出,并指定的return_to 对API

  • 提供商发送信息给API

  • 在API通过check_authentication验证这些信息

  • 如果无效,则API指示web应用程序(即要求每x秒的API)失败

  • 如果有效,则API询问用户对供应商,如电子邮件,显示名称,信息等

  • 如果该用户存在,会话创建

  • 如果用户是新的,他添加到数据库和会话创建

  • API返回的身份验证的状态(在这种情况下,成功)与将进一步请求的web应用程序中使用令牌会话。

这篇关于我怎么可以验证从web应用程序的API用户?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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