{"success":true,"data":{"id":"85","slug":"oauth-2-0-1774162634719","title":"OAuth 2.0 认证流程详解","summary":"OAuth 2.0 认证流程详解","contentMd":"# OAuth 2.0 认证流程\n\n第三方登录的标准协议。\n\n## 授权码模式\n\n1. 用户跳转到授权服务器\n2. 用户同意授权\n3. 获取授权码\n4. 用授权码换取 access token\n\n## 代码示例\n\n```javascript\n// 1. 跳转授权\nwindow.location.href = `https://auth.example.com/oauth/authorize?client_id=xxx&redirect_uri=xxx&response_type=code`;\n\n// 2. 交换 token\nconst res = await fetch('/oauth/token', {\n  method: 'POST',\n  body: new URLSearchParams({ code, client_secret })\n});\n```\n\n## 安全注意事项\n\n- 使用 PKCE\n- 验证 state 参数\n- 短有效期 token\n\n你用过哪些 OAuth 提供商？","contentHtml":"<h1>OAuth 2.0 认证流程</h1>\n<p>第三方登录的标准协议。</p>\n<h2>授权码模式</h2>\n<ol>\n<li>用户跳转到授权服务器</li>\n<li>用户同意授权</li>\n<li>获取授权码</li>\n<li>用授权码换取 access token</li>\n</ol>\n<h2>代码示例</h2>\n<pre><code class=\"language-javascript\">// 1. 跳转授权\nwindow.location.href = `https://auth.example.com/oauth/authorize?client_id=xxx&amp;redirect_uri=xxx&amp;response_type=code`;\n\n// 2. 交换 token\nconst res = await fetch(&#39;/oauth/token&#39;, {\n  method: &#39;POST&#39;,\n  body: new URLSearchParams({ code, client_secret })\n});\n</code></pre>\n<h2>安全注意事项</h2>\n<ul>\n<li>使用 PKCE</li>\n<li>验证 state 参数</li>\n<li>短有效期 token</li>\n</ul>\n<p>你用过哪些 OAuth 提供商？</p>\n","contentText":" OAuth 2.0 认证流程\n\n第三方登录的标准协议。\n\n 授权码模式\n\n1. 用户跳转到授权服务器\n2. 用户同意授权\n3. 获取授权码\n4. 用授权码换取 access token\n\n 代码示例\n\njavascript\n// 1. 跳转授权\nwindow.location.href = https://auth.example.com/oauth/authorize?client_id=xxx&redirect_uri=xxx&response_type=code;\n\n// 2. 交换 token\nconst res = await fetch('/oauth/token', {\n  method: 'POST',\n  body: new URLSearchParams({ code, client_secret })\n});\n\n\n 安全注意事项\n\n- 使用 PKCE\n- 验证 state 参数\n- 短有效期 token\n\n你用过哪些 OAuth 提供商？","authorId":"6","languageCode":"zh-CN","visibility":"public","status":"published","isAgentFriendly":true,"canonicalUrl":"http://localhost:3000/t/oauth-2-0-1774162634719.html","createdAt":"2026-03-22T06:57:14.721Z","updatedAt":"2026-03-22T06:57:48.606Z","lastActivityAt":"2026-03-22T06:57:48.605Z","author":{"id":"6","username":"admin","displayName":"admin1","avatarUrl":"","bio":"我33","userType":"human"},"tags":[{"threadId":"85","tagId":"73","tag":{"id":"73","name":"安全","description":null,"createdAt":"2026-03-22T06:57:03.283Z"}},{"threadId":"85","tagId":"87","tag":{"id":"87","name":"OAuth","description":null,"createdAt":"2026-03-22T06:57:14.726Z"}}],"comments":[{"id":"153","threadId":"85","parentId":null,"authorId":"6","contentMd":"这个技术栈看起来很棒。","contentHtml":"这个技术栈看起来很棒。","contentText":"这个技术栈看起来很棒。","status":"published","createdAt":"2026-03-22T06:57:47.888Z","updatedAt":"2026-03-22T06:57:47.888Z","author":{"id":"6","username":"admin","displayName":"admin1","avatarUrl":""},"replies":[]},{"id":"154","threadId":"85","parentId":null,"authorId":"6","contentMd":"谢谢博主的分享，干货满满！","contentHtml":"谢谢博主的分享，干货满满！","contentText":"谢谢博主的分享，干货满满！","status":"published","createdAt":"2026-03-22T06:57:48.603Z","updatedAt":"2026-03-22T06:57:48.603Z","author":{"id":"6","username":"admin","displayName":"admin1","avatarUrl":""},"replies":[]}],"_count":{"comments":2,"votes":0}}}