简单来说,有人能解释一下OAuth 2和OAuth 1之间的区别吗?

OAuth 1现在过时了吗?我们应该实现OAuth 2吗?我没有看到很多OAuth 2的实现;大多数人仍在使用OAuth 1,这让我怀疑OAuth 2是否可以使用。是吗?


当前回答

OAuth 2显然是在浪费时间(来自一个参与其中的人):

https://gist.github.com/nckroy/dd2d4dfc86f7d13045ad715377b6a48f

他说(为简洁起见,加粗了):

...I can no longer be associated with the OAuth 2.0 standard. I resigned my role as lead author and editor, withdraw my name from the specification, and left the working group. Removing my name from a document I have painstakingly labored over for three years and over two dozen drafts was not easy. Deciding to move on from an effort I have led for over five years was agonizing. ...At the end, I reached the conclusion that OAuth 2.0 is a bad protocol. WS-* bad. It is bad enough that I no longer want to be associated with it. ...When compared with OAuth 1.0, the 2.0 specification is more complex, less interoperable, less useful, more incomplete, and most importantly, less secure. To be clear, OAuth 2.0 at the hand of a developer with deep understanding of web security will likely result is a secure implementation. However, at the hands of most developers – as has been the experience from the past two years – 2.0 is likely to produce insecure implementations.

其他回答

Eran Hammer-Lahav在他的文章《介绍OAuth 2.0》中出色地解释了其中的大部分差异。总结一下,这是关键的区别:

More OAuth Flows to allow better support for non-browser based applications. This is a main criticism against OAuth from client applications that were not browser based. For example, in OAuth 1.0, desktop applications or mobile phone applications had to direct the user to open their browser to the desired service, authenticate with the service, and copy the token from the service back to the application. The main criticism here is against the user experience. With OAuth 2.0, there are now new ways for an application to get authorization for a user.

OAuth 2.0不再要求客户端应用程序具有密码学。这让人想起了旧的Twitter Auth API,它不需要应用程序HMAC哈希令牌和请求字符串。使用OAuth 2.0,应用程序可以仅使用通过HTTPS发出的令牌发出请求。

OAuth 2.0签名要简单得多。没有更多特殊的解析、排序或编码。

OAuth 2.0访问令牌是“短命的”。通常,OAuth 1.0访问令牌可以存储一年或更长时间(Twitter从不让它们过期)。OAuth 2.0有刷新令牌的概念。虽然我不完全确定这些是什么,我的猜测是你的访问令牌可以是短期的(即基于会话),而你的刷新令牌可以是“生命时间”。您将使用刷新令牌来获取新的访问令牌,而不是让用户重新授权您的应用程序。

最后,OAuth 2.0意味着在负责处理OAuth请求的服务器和处理用户授权的服务器之间有一个清晰的角色分离。在前面提到的文章中有详细的信息。

OAuth 2.0承诺在以下方面简化事情:

SSL is required for all the communications required to generate the token. This is a huge decrease in complexity because those complex signatures are no longer required. Signatures are not required for the actual API calls once the token has been generated -- SSL is also strongly recommended here. Once the token was generated, OAuth 1.0 required that the client send two security tokens on every API call, and use both to generate the signature. OAuth 2.0 has only one security token, and no signature is required. It is clearly specified which parts of the protocol are implemented by the "resource owner," which is the actual server that implements the API, and which parts may be implemented by a separate "authorization server." That will make it easier for products like Apigee to offer OAuth 2.0 support to existing APIs.

来源:http://blog.apigee.com/detail/oauth_differences

如果你需要一些高级解释,你需要阅读这两个规范:

https://oauth.net/core/1.0a/

https://oauth.net/2/

正如您将看到的,有几个概念上的差异。

如果你需要使用oauth1或oauth2来消费或发布某个服务,这里我向你展示了一个技术上的区别:

OAuth 1.0流程

客户端应用程序向提供者注册,比如Twitter。 Twitter为客户端提供了该应用程序独有的“消费者秘密”。 客户端应用程序用其独特的“消费者秘密”向Twitter签署所有OAuth请求。 如果任何OAuth请求格式不正确、缺少数据或签名不正确,该请求将被拒绝。

OAuth 2.0流程

客户端应用程序向提供者注册,比如Twitter。 Twitter为客户端提供了该应用程序独有的“客户端秘密”。 客户端应用程序包含“客户端秘密”的每个请求通常作为http头。 如果任何OAuth请求格式不正确、缺少数据或包含错误的秘密,该请求将被拒绝。

来源:

https://www.synopsys.com/blogs/software-security/oauth-2-0-vs-oauth-1-0/

OAuth 2显然是在浪费时间(来自一个参与其中的人):

https://gist.github.com/nckroy/dd2d4dfc86f7d13045ad715377b6a48f

他说(为简洁起见,加粗了):

...I can no longer be associated with the OAuth 2.0 standard. I resigned my role as lead author and editor, withdraw my name from the specification, and left the working group. Removing my name from a document I have painstakingly labored over for three years and over two dozen drafts was not easy. Deciding to move on from an effort I have led for over five years was agonizing. ...At the end, I reached the conclusion that OAuth 2.0 is a bad protocol. WS-* bad. It is bad enough that I no longer want to be associated with it. ...When compared with OAuth 1.0, the 2.0 specification is more complex, less interoperable, less useful, more incomplete, and most importantly, less secure. To be clear, OAuth 2.0 at the hand of a developer with deep understanding of web security will likely result is a secure implementation. However, at the hands of most developers – as has been the experience from the past two years – 2.0 is likely to produce insecure implementations.

OAuth 1.0协议(RFC 5849)的安全性依赖于这样一个假设,即嵌入在客户端应用程序中的密钥可以被保密。然而,这种假设是天真的。

在OAuth 2.0 (RFC 6749)中,这样的简单客户机应用程序称为机密客户机。另一方面,在难以对密钥进行保密的环境中的客户端应用程序称为公共客户端。见2.1。客户类型的详细信息。

从这个意义上说,OAuth 1.0是一个仅针对机密客户机的规范。

"OAuth 2.0 and the Road to Hell" says that OAuth 2.0 is less secure, but there is no practical difference in security level between OAuth 1.0 clients and OAuth 2.0 confidential clients. OAuth 1.0 requires to compute signature, but it does not enhance security if it is already assured that a secret key on the client side can be kept confidential. Computing signature is just a cumbersome calculation without any practical security enhancement. I mean, compared to the simplicity that an OAuth 2.0 client connects to a server over TLS and just presents client_id and client_secret, it cannot be said that the cumbersome calculation is better in terms of security.

此外,RFC 5849 (OAuth 1.0)没有提到任何关于开放重定向器的内容,而RFC 6749 (OAuth 2.0)提到了。即OAuth 1.0的oauth_callback参数可能成为一个安全漏洞。

因此,我不认为OAuth 1.0比OAuth 2.0更安全。


[2016年4月14日]补充澄清我的观点

OAuth 1.0的安全性依赖于签名计算。签名使用密钥计算,其中密钥是HMAC-SHA1的共享密钥(RFC 5849, 3.4.2)或RSA-SHA1的私钥(RFC 5849, 3.4.3)。任何知道密钥的人都可以计算签名。因此,如果密钥被泄露,再复杂的签名计算也没有意义。

这意味着OAuth 1.0的安全性不依赖于签名计算的复杂性和逻辑,而仅仅依赖于秘密密钥的保密性。换句话说,OAuth 1.0安全性所需要的仅仅是一个秘密密钥可以保密的条件。这听起来可能很极端,但是如果条件已经满足,签名计算不会增加安全性增强。

同样,OAuth 2.0机密客户机依赖于相同的条件。如果条件已经满足,那么使用TLS创建安全连接并通过安全连接将client_id和client_secret发送到授权服务器是否存在问题?如果OAuth 1.0和OAuth 2.0机密客户端依赖相同的条件,那么两者的安全级别是否有很大差异?

我找不到OAuth 1.0责怪OAuth 2.0的理由。事实很简单,(1)OAuth 1.0只是一个仅针对机密客户端的规范,(2)OAuth 2.0简化了机密客户端的协议,也支持公共客户端。不管是否众所周知,智能手机应用程序被归类为公共客户端(RFC 6749, 9),它们受益于OAuth 2.0。