安全的方式来OAuth的令牌传达给JavaScript客户端 [英] Secure way to communicate OAuth token to javascript client

查看:107
本文介绍了安全的方式来OAuth的令牌传达给JavaScript客户端的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我设计的那一刻一个多平台的应用程序(客户端将包括内部开发的移动应用程序,以及一个AJAX沉重的JavaScript客户端最初)围绕着一个REST API。由于在未来的API可以是向第三方开放,我期待在使用OAuth 2.0认证授权的API。

I am designing a multi-platform application at the moment (clients would include internally developed mobile apps, and an AJAX heavy javascript client initially) centred around a REST API. Since in the future the API may be open to third parties, I am looking at using OAuth 2.0 for authentication and authorization with the API.

我试图让我的头周围的一些安全问题,这样的安排,特别是关于JavaScript客户端。我不希望这个客户的行为像一个第三方客户端可能,有一大堆重定向和弹出窗口之类的东西,这是大多数OAuth的文档似乎集中在。因为它会从我自己的域发表的,我在想,在Web应用程序的服务器端可以是实际的客户端,并存储在客户端秘密和刷新令牌,而JavaScript的检索新的身份验证令牌从服务器,因为它需要他们。

I am trying to get my head around some of the security issues with this arrangement, particularly with regard to the javascript client. I don't want this client to behave like a third party client might, with a whole bunch of redirects and popups and stuff, which is what most OAuth documentation seems to focus on. Since it will be delivered from my own domain, I am thinking that the server side of the webapp can be the actual client, and store the client secrets and refresh tokens, while the javascript retrieves new auth tokens from the server as it needs them.

要把它在一步一步的形式:

To put it in step by step form:

  1. 在使用非Ajax HTML表单,产生这些存储的服务器端身份验证和刷新令牌的用户登录。这将设置一个HTTP-唯一的登录会话cookie。
  2. 在JavaScript客户端code登录后发送到用户的浏览器。
  3. 在JavaScript客户端发出请求的资源是它自己的应用程序(REST API的一部分)来获取令牌的一部分。会话cookie确保客户端是真诚的,并引用者也将被检查。身份验证令牌返回。
  4. 在JavaScript客户端验证与REST API的令牌。
  5. 客户端现在可以使用该令牌,直到它过期,使对REST API请求。
  6. 如果该身份验证令牌到期或页面被关闭并重新打开时,JavaScript客户端可以请求一个新的令牌。 web应用程序的服务器端负责刷新令牌并发送新的令牌,只要登录会话cookie仍然有效。

这是否有道理呢,还是会留在系统中大量的漏洞?特别是它疯狂的有动手了基于一个cookie被设置?

Does this make sense, or would it leave massive holes in the system? In particular, is it insane to have a resource on the web that hands out authentication tokens based on a cookie being set?

推荐答案

只要确保浏览器的任何通信是HTTPS,所以没有人在中间可以窃取您的令牌。并设置了安全的标志在你的AUTH的cookie。

Just make sure that any communication to browser is HTTPS, so that no one in the middle can steal your tokens. And set the "secure" flag on your auth cookies.

  • 大多数浏览器的授权方案现在可以归结为多数民众赞成通过在Cookie会话令牌。基于OAuth的认证2方案是未来几个步骤,因为一)的标记(可以)哑令牌里面没有危险的用户信息,和b)到期。

  • Most browser authorization schemes nowadays boil down to a session token that's passed in a cookie. The OAuth 2 scheme is a couple steps ahead because a) the tokens (can be) dumb tokens with no dangerous user info inside, and b) they expire.

(只是把在上下文中的评论:!有一次我突然打开的会话令牌从网站,发现我家的地址和电话号码,在那里确认)

(Just to put that comment in context: one time I popped open a session token from a site and discovered my home address and phone number was in there. Ack!)

我见过code,做HMAC签署布劳尔的JavaScript内的请求,但它想出了一个巨大免责声明:不要在生产中使用它。签约方案需要在客户端(JavaScript)的知道一个秘密的字符串,但浏览器/ JavaScript是如此不安全,它相当于交给你的秘密字符串到世界各地。

I've seen code that does HMAC signing of requests inside the brower javascript, but it came with a huge disclaimer: don't use this in production. A signing scheme requires the client (javascript) to know a "secret" string, but the browser/javascript is so insecure that it amounts to handing your secret strings to the world.

但是,如果你把所有的commuinication通过HTTPS,那么你真的只是把一个OAuth的捻传递会话令牌饼干熟悉的方案。

But if you keep all your commuinication over HTTPS, then you're really just putting an OAuth twist on the familiar scheme of passing session tokens as cookies.

这篇关于安全的方式来OAuth的令牌传达给JavaScript客户端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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