# OAuth

OAuth 是一种用于委托授权的开放标准：它允许用户授予第三方应用对受保护资源的有限访问权限，而无需向该应用透露自己的密码。该框架由[互联网工程任务组](https://www.edgepedia.org/zh/internet-engineering-task-force)（IETF）发布；1.0 版于 2010 年 4 月标准化为 RFC 5849，2.0 版于 2012 年 10 月标准化为 RFC 6749。<sup>[1](https://www.rfc-editor.org/info/rfc5849/)</sup><sup> • </sup><sup>[2](https://www.rfc-editor.org/info/rfc6749/)</sup>

| 关键事实 | 详情 |
|---|---|
| 目的 | 通过令牌实现对受保护资源的委托访问，使客户端始终无需处理资源所有者的密码<sup>[1](https://www.rfc-editor.org/info/rfc5849/)</sup> |
| 核心规范 | OAuth 1.0：RFC 5849（2010 年 4 月）；OAuth 2.0：RFC 6749（2012 年 10 月），持有者令牌用法 RFC 6750<sup>[1](https://www.rfc-editor.org/info/rfc5849/)</sup><sup> • </sup><sup>[2](https://www.rfc-editor.org/info/rfc6749/)</sup> |
| 四种角色（2.0） | 资源所有者、资源服务器、客户端和授权服务器<sup>[2](https://www.rfc-editor.org/info/rfc6749/)</sup> |
| 授权类型（2.0） | 授权码、隐式、资源所有者密码凭据和客户端凭据，外加扩展机制<sup>[2](https://www.rfc-editor.org/info/rfc6749/)</sup> |
| 当前安全基线 | RFC 9700（2025 年 1 月，BCP 240）：公共客户端必须使用 PKCE，重定向 URI 须精确匹配，不鼓励使用隐式授权<sup>[3](https://www.rfc-editor.org/rfc/rfc9700.html)</sup> |
| 与身份认证的关系 | OAuth 2.0 授权访问但不识别用户身份；OpenID Connect 在其之上增加了身份层<sup>[4](https://www.oauth.com/oauth2-servers/openid-connect/authorization-vs-authentication/)</sup><sup> • </sup><sup>[5](https://learn.microsoft.com/en-us/entra/identity/enterprise-apps/saml-vs-oidc-decision-guide)</sup> |
| 后继草案 | OAuth 2.1（draft-ietf-oauth-v2-1）将取代并废止 RFC 6749 和 RFC 6750<sup>[6](https://datatracker.ietf.org/doc/draft-ietf-oauth-v2-1/)</sup> |

## 起源与 1.0 版

OAuth 始于 2006 年 11 月前后，当时时任 Twitter 首席架构师的布莱恩·库克（Blaine Cook）正在开发 Twitter 的 [OpenID](https://www.edgepedia.org/zh/openid) 实现，希望找到一种将 OpenID 与 Twitter API 结合使用以委托身份认证的方法。他联系了[克里斯·梅西纳](https://www.edgepedia.org/zh/chris-messina)（Chris Messina），两人与大卫·雷科登（David Recordon）、拉里·哈尔夫（Larry Halff）等人会面，评估现有方案。他们得出结论：API 访问委托尚无开放标准。2007 年 4 月，一个由实现者组成的谷歌小组开始起草提案。OAuth Core 1.0 最终草案于 2007 年 10 月 3 日发布。<sup>[7](https://oauth.net/about/introduction/)</sup><sup> • </sup><sup>[8](https://www.oauth.com/oauth2-servers/background/)</sup>

该协议于 2007 年 10 月稳定为 1.0 版，并于 2009 年 6 月修订为修订版 A。IETF 于 2010 年 4 月将 1.0 规范的最终版本发布为 RFC 5849。<sup>[1](https://www.rfc-editor.org/info/rfc5849/)</sup><sup> • </sup><sup>[9](https://oauth.net/1/)</sup> OAuth 1.0 对每个请求使用加密签名（如 HMAC-SHA1），令牌凭据携带匹配的共享密钥，用于确立客户端对令牌的所有权。<sup>[1](https://www.rfc-editor.org/info/rfc5849/)</sup>

## OAuth 2.0

2012 年 10 月发布的 RFC 6749 重构了该框架。它定义了四种角色：资源所有者（当其为自然人时为最终用户）、托管受保护资源的资源服务器、代表所有者发起受保护资源请求的客户端，以及在成功认证所有者并获得授权后颁发访问令牌的授权服务器。<sup>[2](https://www.rfc-editor.org/info/rfc6749/)</sup>

该框架定义了四种授权类型：授权码、隐式、资源所有者密码凭据和客户端凭据，外加用于其他授权类型的扩展机制。<sup>[2](https://www.rfc-editor.org/info/rfc6749/)</sup> 客户端分为机密客户端——即能够维护其凭据机密性的客户端——和公共客户端——即无法做到这一点的客户端，例如基于浏览器的应用或已安装的原生应用。<sup>[2](https://www.rfc-editor.org/info/rfc6749/)</sup>

**授权码流程**是最广泛使用的授权类型。<sup>[10](https://oauth.net/2/grant-types/authorization-code/)</sup> 在该流程中，客户端将资源所有者的用户代理引导至授权端点，并附上其客户端标识符、请求范围、本地状态和重定向 URI。授权服务器对资源所有者进行认证，若授予访问权限，则携带授权码将用户代理重定向回客户端。客户端随后将授权码发送至令牌端点，进行自我认证，并获得访问令牌，还可选获得刷新令牌。若授权码被使用超过一次，授权服务器必须拒绝该请求，并应撤销此前基于该授权码颁发的令牌。<sup>[2](https://www.rfc-editor.org/info/rfc6749/)</sup>

访问令牌抽象掉了底层的授权构造：资源服务器只需验证单个令牌，而无需理解一系列认证方案，这使得颁发仅在短时间内有效的令牌成为可能。<sup>[11](https://www.rfc-editor.org/rfc/rfc6750.html)</sup> RFC 6750 定义了持有者令牌的用法，即任何持有该令牌的人都可以使用它，无需证明持有加密密钥材料。<sup>[11](https://www.rfc-editor.org/rfc/rfc6750.html)</sup>

## 安全实践：PKCE 与 RFC 9700

**PKCE**（Proof Key for Code Exchange，授权码交换证明密钥）于 2015 年 9 月发布为 RFC 7636，用于缓解授权码被截获的风险。客户端创建一个名为 code_verifier 的一次性密钥，并将转换后的值 code_challenge 随授权请求一同发送。在令牌端点，客户端出示 code_verifier；服务器对其进行转换并与记录的 code_challenge 比对，若不一致则拒绝访问。截获了授权码的攻击者若无 code_verifier 则无法兑换该授权码。<sup>[12](https://www.rfc-editor.org/rfc/rfc7636.html)</sup>

2025 年 1 月，IETF 发布了 RFC 9700，即 [OAuth 2.0](https://www.edgepedia.org/zh/oauth-2-0) 安全最佳当前实践（BCP 240），它更新并扩展了 RFC 6749、6750 和 6819 中的威胁模型与建议，并弃用了被认为安全性较低或不安全的运行模式。<sup>[3](https://www.rfc-editor.org/rfc/rfc9700.html)</sup> 其核心要求包括：

- 公共客户端必须使用 PKCE；对于机密客户端，建议使用 PKCE，因为它可防止授权码的误用和注入，并作为附带效果防止 CSRF。<sup>[3](https://www.rfc-editor.org/rfc/rfc9700.html)</sup>
- 授权服务器必须支持 PKCE，当发送了 code_challenge 时必须强制执行 code_verifier 的正确使用，并且必须通过仅在授权请求中存在 code_challenge 时才接受包含 code_verifier 的令牌请求，来缓解 PKCE 降级攻击。<sup>[3](https://www.rfc-editor.org/rfc/rfc9700.html)</sup>
- 客户端应使用 S256 码挑战方法，这是目前唯一不会在授权请求中暴露 code_verifier 的方法。<sup>[3](https://www.rfc-editor.org/rfc/rfc9700.html)</sup>
- 重定向 URI 比较必须使用精确字符串匹配，原生应用 localhost 重定向 URI 中的端口号除外；不得暴露开放重定向器，因为它们会导致授权码和访问令牌的外泄。<sup>[3](https://www.rfc-editor.org/rfc/rfc9700.html)</sup>
- 隐式授权（响应类型 `token`）及其他在[授权](https://www.edgepedia.org/zh/authorization)响应中直接颁发访问令牌的响应类型易受令牌泄露和重放攻击，且对于以此方式颁发的令牌不存在标准化的发送方约束方法；客户端不应使用它们，而应使用响应类型 `code`。<sup>[3](https://www.rfc-editor.org/rfc/rfc9700.html)</sup>
- 与多个授权服务器交互的客户端必须防御混淆攻击，通常按照 RFC 9207 使用 `iss` 参数。<sup>[3](https://www.rfc-editor.org/rfc/rfc9700.html)</sup>

oauth.net 对该文档的摘要列出了其关键建议：始终使用 PKCE，使用精确的重定向 URI 匹配，不使用隐式授权或密码授权，高安全性部署优先使用 PAR（Pushed Authorization Requests，推送授权请求），并在可能时使用发送方约束令牌，如 DPoP 或 mTLS。<sup>[13](https://oauth.net/2/oauth-best-practice/)</sup>

## OAuth、OpenID Connect 与 SAML

OAuth 2.0 有意设计为提供授权而不提供用户身份或身份认证，因为这些问题具有不同的安全考量。它没有机制来说明用户是谁或用户如何完成认证；它只说明用户委托了某个应用代表其行事。<sup>[4](https://www.oauth.com/oauth2-servers/openid-connect/authorization-vs-authentication/)</sup> 在实践中，开发者仍然将 OAuth 用于登录，研究人员已将严重漏洞与这种误用联系起来。<sup>[14](https://arxiv.org/abs/1508.04324)</sup>

[OpenID Connect](https://www.edgepedia.org/zh/openid-connect)（OIDC）填补了这一空白：它是一种构建在 OAuth 2.0 之上的登录协议，增加了一种称为 ID token 的 [JSON Web Token](https://www.edgepedia.org/zh/json-web-token)，并对 OAuth 2.0 未作规定的部分（如范围和端点发现）进行了标准化。<sup>[5](https://learn.microsoft.com/en-us/entra/identity/enterprise-apps/saml-vs-oidc-decision-guide)</sup><sup> • </sup><sup>[15](https://www.okta.com/identity-101/whats-the-difference-between-oauth-openid-connect-and-saml/)</sup> 相比之下，[SAML 2.0](https://www.edgepedia.org/zh/saml-2-0) 是一种成熟的基于 XML 的联合协议，独立于 OAuth，十多年来在企业中广泛使用；OIDC 基于 JSON，契合现代应用设计，包括单页应用、移动应用和微服务。<sup>[5](https://learn.microsoft.com/en-us/entra/identity/enterprise-apps/saml-vs-oidc-decision-guide)</sup>

## 安全研究与现实世界的失败案例

形式化分析塑造了该协议的指导方针。一项在表达力丰富的 Web 模型中对 OAuth 2.0 进行的全面形式化分析，覆盖了全部四种授权类型与恶意依赖方、身份提供者和浏览器同时运行的情形，发现了四种破坏协议安全性的攻击；作者提出了修复方案，并首次证明了采用最佳实践的修复版 OAuth 的安全性。<sup>[16](https://arxiv.org/abs/1601.01229)</sup>

实现质量仍然是一个薄弱环节。一项针对支持谷歌登录的 1,000 个排名靠前网站的 OAuthGuard 研究发现，在 137 个使用谷歌登录的网站中，69 个存在至少一个严重漏洞；53 个（39%）的 redirect_uri 端点易受 CSRF 攻击，9 个通过 Referer 头泄露令牌，13 个未使用 HTTPS 传输用户令牌。<sup>[17](https://arxiv.org/abs/1901.08960)</sup> 在 USENIX Security 2025 上发表的一项关于集成平台的研究识别了两种新的平台级攻击——跨应用 OAuth 账户接管（COAT）和跨应用 OAuth 请求伪造（CORF）；在 18 个流行集成平台中，11 个易受 COAT 攻击，5 个易受 CORF 攻击，包括微软、谷歌和亚马逊构建的平台。<sup>[18](https://www.usenix.org/conference/usenixsecurity25/presentation/luo-kaixuan)</sup>

## OAuth 2.1 与当前方向

OAuth 工作组正在制定 OAuth 2.1（draft-ietf-oauth-v2-1），它将取代并废止 RFC 6749 的 OAuth 2.0 授权框架和 RFC 6750 的持有者令牌用法，将安全最佳实践整合进基础框架。<sup>[6](https://datatracker.ietf.org/doc/draft-ietf-oauth-v2-1/)</sup> 该工作组的里程碑目标是在 2026 年 12 月向 IESG 提交 OAuth 2.1 授权框架。<sup>[6](https://datatracker.ietf.org/doc/draft-ietf-oauth-v2-1/)</sup>

## References

1. [RFC 5849: The OAuth 1.0 Protocol, RFC Editor (April 2010)](https://www.rfc-editor.org/info/rfc5849/)
2. [RFC 6749: The OAuth 2.0 Authorization Framework, RFC Editor (October 2012)](https://www.rfc-editor.org/info/rfc6749/)
3. [RFC 9700: Best Current Practice for OAuth 2.0 Security, RFC Editor (January 2025)](https://www.rfc-editor.org/rfc/rfc9700.html)
4. [Authorization vs Authentication, OAuth 2.0 Simplified](https://www.oauth.com/oauth2-servers/openid-connect/authorization-vs-authentication/)
5. [SAML versus OpenID Connect: Choose the right SSO protocol, Microsoft Learn](https://learn.microsoft.com/en-us/entra/identity/enterprise-apps/saml-vs-oidc-decision-guide)
6. [draft-ietf-oauth-v2-1-16: The OAuth 2.1 Authorization Framework, IETF Datatracker](https://datatracker.ietf.org/doc/draft-ietf-oauth-v2-1/)
7. [Introduction, OAuth.net](https://oauth.net/about/introduction/)
8. [Background, OAuth 2.0 Simplified](https://www.oauth.com/oauth2-servers/background/)
9. [OAuth 1, OAuth.net](https://oauth.net/1/)
10. [Authorization Code Grant, OAuth.net](https://oauth.net/2/grant-types/authorization-code/)
11. [RFC 6750: OAuth 2.0 Bearer Token Usage, RFC Editor](https://www.rfc-editor.org/rfc/rfc6750.html)
12. [RFC 7636: Proof Key for Code Exchange (PKCE), RFC Editor (September 2015)](https://www.rfc-editor.org/rfc/rfc7636.html)
13. [OAuth 2.0 Security Best Current Practice, OAuth.net](https://oauth.net/2/oauth-best-practice/)
14. [On the security of modern Single Sign-On Protocols: Second-Order Vulnerabilities in OpenID Connect, arXiv](https://arxiv.org/abs/1508.04324)
15. [What's the Difference Between OAuth, OpenID Connect, and SAML?, Okta](https://www.okta.com/identity-101/whats-the-difference-between-oauth-openid-connect-and-saml/)
16. [A Comprehensive Formal Security Analysis of OAuth 2.0, arXiv](https://arxiv.org/abs/1601.01229)
17. [OAuthGuard: Protecting User Security and Privacy with OAuth 2.0 and OpenID Connect, arXiv](https://arxiv.org/abs/1901.08960)
18. [Universal Cross-app Attacks: Exploiting and Securing OAuth 2.0 in Integration Platforms, USENIX Security 2025](https://www.usenix.org/conference/usenixsecurity25/presentation/luo-kaixuan)

---
*Initially written Sep 17, 2026 · Reviewed: Sep 17, 2026; Oct 15, 2026 · Edited: Oct 15, 2026 · Last review: Oct 15, 2026*

Topic: 技术与人造世界 › 计算技术与数字系统 › 网络与安全 › Security governance and internet policy › Cryptographic protocols

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/oauth

English original: https://www.edgepedia.org/oauth
