{"id":4735,"date":"2020-02-06T15:45:49","date_gmt":"2020-02-06T07:45:49","guid":{"rendered":"https:\/\/www.xttblog.com\/?p=4735"},"modified":"2020-02-06T15:47:06","modified_gmt":"2020-02-06T07:47:06","slug":"%e7%90%86%e8%a7%a3oauth-2-0-%e9%98%ae%e4%b8%80%e5%b3%b0%e7%9a%84%e7%bd%91%e7%bb%9c%e6%97%a5%e5%bf%97","status":"publish","type":"post","link":"https:\/\/www.xttblog.com\/?p=4735","title":{"rendered":"\u7406\u89e3OAuth 2.0 &#8211; \u962e\u4e00\u5cf0\u7684\u7f51\u7edc\u65e5\u5fd7"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">\u962e\u4e00\u5cf0\u7684\u8fd9\u7bc7\u6587\u7ae0\u88ab\u5e7f\u6cdb\u8f6c\u8f7d\uff01\u5199\u7684\u975e\u5e38\u597d\uff0c\u5f88\u591a\u5927\u4f6c\u90fd\u62ff\u6765\u501f\u9274\uff01<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd9\u7bc7\u6587\u7ae0\u8bc4\u8bba\u4e5f\u5f88\u591a\uff0c\u8bc4\u8bba\u5185\u5bb9\u8d85\u8fc7\u4e86\u539f\u6587\u5b57\u6570\u3002\u5f88\u4e45\u4e4b\u524d\u6211\u770b\u8fc7\u8fd9\u7bc7\u6587\u7ae0\uff0c\u6700\u8fd1\u88ab\u4eba\u95ee\u8d77\uff0c\u627e\u4e0d\u5230\u539f\u6587\u4e86\uff0c\u56e0\u4e3a\u88ab\u592a\u591a\u7684\u4eba\u8f6c\u8f7d\uff0c\u800c\u767e\u5ea6\u641c\u7d22\u7684\u7ed3\u679c\u628a\u8f6c\u8f7d\u7684\u6587\u7ae0\u653e\u5230\u9996\u9875\u4e0a\uff0c\u539f\u6587\u6bd4\u8f83\u9760\u540e\u3002\u6211\u8fd9\u91cc\u6458\u5f55\u4e00\u4e0b\uff0c\u65b9\u4fbf\u4ee5\u540e\u590d\u4e60\u3002\u539f\u6587\u5730\u5740\u9644\u5728\u6587\u672b\uff01<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"http:\/\/en.wikipedia.org\/wiki\/OAuth\" target=\"_blank\" rel=\"noreferrer noopener\">OAuth<\/a>\u662f\u4e00\u4e2a\u5173\u4e8e\u6388\u6743\uff08authorization\uff09\u7684\u5f00\u653e\u7f51\u7edc\u6807\u51c6\uff0c\u5728\u5168\u4e16\u754c\u5f97\u5230\u5e7f\u6cdb\u5e94\u7528\uff0c\u76ee\u524d\u7684\u7248\u672c\u662f2.0\u7248\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u672c\u6587\u5bf9OAuth 2.0\u7684\u8bbe\u8ba1\u601d\u8def\u548c\u8fd0\u884c\u6d41\u7a0b\uff0c\u505a\u4e00\u4e2a\u7b80\u660e\u901a\u4fd7\u7684\u89e3\u91ca\uff0c\u4e3b\u8981\u53c2\u8003\u6750\u6599\u4e3a<a href=\"http:\/\/www.rfcreader.com\/#rfc6749\" target=\"_blank\" rel=\"noreferrer noopener\">RFC 6749<\/a>\u3002<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img decoding=\"async\" src=\"http:\/\/www.ruanyifeng.com\/blogimg\/asset\/2014\/bg2014051201.png\" alt=\"OAuth Logo\" \/><figcaption>OAuth2<\/figcaption><\/figure><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e00\u3001\u5e94\u7528\u573a\u666f<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e3a\u4e86\u7406\u89e3OAuth\u7684\u9002\u7528\u573a\u5408\uff0c\u8ba9\u6211\u4e3e\u4e00\u4e2a\u5047\u8bbe\u7684\u4f8b\u5b50\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u6709\u4e00\u4e2a&#8221;\u4e91\u51b2\u5370&#8221;\u7684\u7f51\u7ad9\uff0c\u53ef\u4ee5\u5c06\u7528\u6237\u50a8\u5b58\u5728Google\u7684\u7167\u7247\uff0c\u51b2\u5370\u51fa\u6765\u3002\u7528\u6237\u4e3a\u4e86\u4f7f\u7528\u8be5\u670d\u52a1\uff0c\u5fc5\u987b\u8ba9&#8221;\u4e91\u51b2\u5370&#8221;\u8bfb\u53d6\u81ea\u5df1\u50a8\u5b58\u5728Google\u4e0a\u7684\u7167\u7247\u3002<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img decoding=\"async\" src=\"http:\/\/www.ruanyifeng.com\/blogimg\/asset\/2014\/bg2014051202.png\" alt=\"\u4e91\u51b2\u5370\" \/><\/figure><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">\u95ee\u9898\u662f\u53ea\u6709\u5f97\u5230\u7528\u6237\u7684\u6388\u6743\uff0cGoogle\u624d\u4f1a\u540c\u610f&#8221;\u4e91\u51b2\u5370&#8221;\u8bfb\u53d6\u8fd9\u4e9b\u7167\u7247\u3002\u90a3\u4e48\uff0c&#8221;\u4e91\u51b2\u5370&#8221;\u600e\u6837\u83b7\u5f97\u7528\u6237\u7684\u6388\u6743\u5462\uff1f<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4f20\u7edf\u65b9\u6cd5\u662f\uff0c\u7528\u6237\u5c06\u81ea\u5df1\u7684Google\u7528\u6237\u540d\u548c\u5bc6\u7801\uff0c\u544a\u8bc9&#8221;\u4e91\u51b2\u5370&#8221;\uff0c\u540e\u8005\u5c31\u53ef\u4ee5\u8bfb\u53d6\u7528\u6237\u7684\u7167\u7247\u4e86\u3002\u8fd9\u6837\u7684\u505a\u6cd5\u6709\u4ee5\u4e0b\u51e0\u4e2a\u4e25\u91cd\u7684\u7f3a\u70b9\u3002<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>\uff081\uff09&#8221;\u4e91\u51b2\u5370&#8221;\u4e3a\u4e86\u540e\u7eed\u7684\u670d\u52a1\uff0c\u4f1a\u4fdd\u5b58\u7528\u6237\u7684\u5bc6\u7801\uff0c\u8fd9\u6837\u5f88\u4e0d\u5b89\u5168\u3002<\/p><p>\uff082\uff09Google\u4e0d\u5f97\u4e0d\u90e8\u7f72\u5bc6\u7801\u767b\u5f55\uff0c\u800c\u6211\u4eec\u77e5\u9053\uff0c\u5355\u7eaf\u7684\u5bc6\u7801\u767b\u5f55\u5e76\u4e0d\u5b89\u5168\u3002<\/p><p>\uff083\uff09&#8221;\u4e91\u51b2\u5370&#8221;\u62e5\u6709\u4e86\u83b7\u53d6\u7528\u6237\u50a8\u5b58\u5728Google\u6240\u6709\u8d44\u6599\u7684\u6743\u529b\uff0c\u7528\u6237\u6ca1\u6cd5\u9650\u5236&#8221;\u4e91\u51b2\u5370&#8221;\u83b7\u5f97\u6388\u6743\u7684\u8303\u56f4\u548c\u6709\u6548\u671f\u3002<\/p><p>\uff084\uff09\u7528\u6237\u53ea\u6709\u4fee\u6539\u5bc6\u7801\uff0c\u624d\u80fd\u6536\u56de\u8d4b\u4e88&#8221;\u4e91\u51b2\u5370&#8221;\u7684\u6743\u529b\u3002\u4f46\u662f\u8fd9\u6837\u505a\uff0c\u4f1a\u4f7f\u5f97\u5176\u4ed6\u6240\u6709\u83b7\u5f97\u7528\u6237\u6388\u6743\u7684\u7b2c\u4e09\u65b9\u5e94\u7528\u7a0b\u5e8f\u5168\u90e8\u5931\u6548\u3002<\/p><p>\uff085\uff09\u53ea\u8981\u6709\u4e00\u4e2a\u7b2c\u4e09\u65b9\u5e94\u7528\u7a0b\u5e8f\u88ab\u7834\u89e3\uff0c\u5c31\u4f1a\u5bfc\u81f4\u7528\u6237\u5bc6\u7801\u6cc4\u6f0f\uff0c\u4ee5\u53ca\u6240\u6709\u88ab\u5bc6\u7801\u4fdd\u62a4\u7684\u6570\u636e\u6cc4\u6f0f\u3002<\/p><\/blockquote>\n\n\n\n<p class=\"wp-block-paragraph\">OAuth\u5c31\u662f\u4e3a\u4e86\u89e3\u51b3\u4e0a\u9762\u8fd9\u4e9b\u95ee\u9898\u800c\u8bde\u751f\u7684\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e8c\u3001\u540d\u8bcd\u5b9a\u4e49<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728\u8be6\u7ec6\u8bb2\u89e3OAuth 2.0\u4e4b\u524d\uff0c\u9700\u8981\u4e86\u89e3\u51e0\u4e2a\u4e13\u7528\u540d\u8bcd\u3002\u5b83\u4eec\u5bf9\u8bfb\u61c2\u540e\u9762\u7684\u8bb2\u89e3\uff0c\u5c24\u5176\u662f\u51e0\u5f20\u56fe\uff0c\u81f3\u5173\u91cd\u8981\u3002<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>\uff081\uff09&nbsp;<strong>Third-party application<\/strong>\uff1a\u7b2c\u4e09\u65b9\u5e94\u7528\u7a0b\u5e8f\uff0c\u672c\u6587\u4e2d\u53c8\u79f0&#8221;\u5ba2\u6237\u7aef&#8221;\uff08client\uff09\uff0c\u5373\u4e0a\u4e00\u8282\u4f8b\u5b50\u4e2d\u7684&#8221;\u4e91\u51b2\u5370&#8221;\u3002<\/p><p>\uff082\uff09<strong>HTTP service<\/strong>\uff1aHTTP\u670d\u52a1\u63d0\u4f9b\u5546\uff0c\u672c\u6587\u4e2d\u7b80\u79f0&#8221;\u670d\u52a1\u63d0\u4f9b\u5546&#8221;\uff0c\u5373\u4e0a\u4e00\u8282\u4f8b\u5b50\u4e2d\u7684Google\u3002<\/p><p>\uff083\uff09<strong>Resource Owner<\/strong>\uff1a\u8d44\u6e90\u6240\u6709\u8005\uff0c\u672c\u6587\u4e2d\u53c8\u79f0&#8221;\u7528\u6237&#8221;\uff08user\uff09\u3002<\/p><p>\uff084\uff09<strong>User Agent<\/strong>\uff1a\u7528\u6237\u4ee3\u7406\uff0c\u672c\u6587\u4e2d\u5c31\u662f\u6307\u6d4f\u89c8\u5668\u3002<\/p><p>\uff085\uff09<strong>Authorization server<\/strong>\uff1a\u8ba4\u8bc1\u670d\u52a1\u5668\uff0c\u5373\u670d\u52a1\u63d0\u4f9b\u5546\u4e13\u95e8\u7528\u6765\u5904\u7406\u8ba4\u8bc1\u7684\u670d\u52a1\u5668\u3002<\/p><p>\uff086\uff09<strong>Resource server<\/strong>\uff1a\u8d44\u6e90\u670d\u52a1\u5668\uff0c\u5373\u670d\u52a1\u63d0\u4f9b\u5546\u5b58\u653e\u7528\u6237\u751f\u6210\u7684\u8d44\u6e90\u7684\u670d\u52a1\u5668\u3002\u5b83\u4e0e\u8ba4\u8bc1\u670d\u52a1\u5668\uff0c\u53ef\u4ee5\u662f\u540c\u4e00\u53f0\u670d\u52a1\u5668\uff0c\u4e5f\u53ef\u4ee5\u662f\u4e0d\u540c\u7684\u670d\u52a1\u5668\u3002<\/p><\/blockquote>\n\n\n\n<p class=\"wp-block-paragraph\">\u77e5\u9053\u4e86\u4e0a\u9762\u8fd9\u4e9b\u540d\u8bcd\uff0c\u5c31\u4e0d\u96be\u7406\u89e3\uff0cOAuth\u7684\u4f5c\u7528\u5c31\u662f\u8ba9&#8221;\u5ba2\u6237\u7aef&#8221;\u5b89\u5168\u53ef\u63a7\u5730\u83b7\u53d6&#8221;\u7528\u6237&#8221;\u7684\u6388\u6743\uff0c\u4e0e&#8221;\u670d\u52a1\u5546\u63d0\u4f9b\u5546&#8221;\u8fdb\u884c\u4e92\u52a8\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e09\u3001OAuth\u7684\u601d\u8def<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">OAuth\u5728&#8221;\u5ba2\u6237\u7aef&#8221;\u4e0e&#8221;\u670d\u52a1\u63d0\u4f9b\u5546&#8221;\u4e4b\u95f4\uff0c\u8bbe\u7f6e\u4e86\u4e00\u4e2a\u6388\u6743\u5c42\uff08authorization layer\uff09\u3002&#8221;\u5ba2\u6237\u7aef&#8221;\u4e0d\u80fd\u76f4\u63a5\u767b\u5f55&#8221;\u670d\u52a1\u63d0\u4f9b\u5546&#8221;\uff0c\u53ea\u80fd\u767b\u5f55\u6388\u6743\u5c42\uff0c\u4ee5\u6b64\u5c06\u7528\u6237\u4e0e\u5ba2\u6237\u7aef\u533a\u5206\u5f00\u6765\u3002&#8221;\u5ba2\u6237\u7aef&#8221;\u767b\u5f55\u6388\u6743\u5c42\u6240\u7528\u7684\u4ee4\u724c\uff08token\uff09\uff0c\u4e0e\u7528\u6237\u7684\u5bc6\u7801\u4e0d\u540c\u3002\u7528\u6237\u53ef\u4ee5\u5728\u767b\u5f55\u7684\u65f6\u5019\uff0c\u6307\u5b9a\u6388\u6743\u5c42\u4ee4\u724c\u7684\u6743\u9650\u8303\u56f4\u548c\u6709\u6548\u671f\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&#8220;\u5ba2\u6237\u7aef&#8221;\u767b\u5f55\u6388\u6743\u5c42\u4ee5\u540e\uff0c&#8221;\u670d\u52a1\u63d0\u4f9b\u5546&#8221;\u6839\u636e\u4ee4\u724c\u7684\u6743\u9650\u8303\u56f4\u548c\u6709\u6548\u671f\uff0c\u5411&#8221;\u5ba2\u6237\u7aef&#8221;\u5f00\u653e\u7528\u6237\u50a8\u5b58\u7684\u8d44\u6599\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u56db\u3001\u8fd0\u884c\u6d41\u7a0b<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">OAuth 2.0\u7684\u8fd0\u884c\u6d41\u7a0b\u5982\u4e0b\u56fe\uff0c\u6458\u81eaRFC 6749\u3002<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img decoding=\"async\" src=\"http:\/\/www.ruanyifeng.com\/blogimg\/asset\/2014\/bg2014051203.png\" alt=\"OAuth\u8fd0\u884c\u6d41\u7a0b\" \/><figcaption>OAuth2 \u8fd0\u884c\u6d41\u7a0b\u56fe<\/figcaption><\/figure><\/div>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>\uff08A\uff09\u7528\u6237\u6253\u5f00\u5ba2\u6237\u7aef\u4ee5\u540e\uff0c\u5ba2\u6237\u7aef\u8981\u6c42\u7528\u6237\u7ed9\u4e88\u6388\u6743\u3002<\/p><p>\uff08B\uff09\u7528\u6237\u540c\u610f\u7ed9\u4e88\u5ba2\u6237\u7aef\u6388\u6743\u3002<\/p><p>\uff08C\uff09\u5ba2\u6237\u7aef\u4f7f\u7528\u4e0a\u4e00\u6b65\u83b7\u5f97\u7684\u6388\u6743\uff0c\u5411\u8ba4\u8bc1\u670d\u52a1\u5668\u7533\u8bf7\u4ee4\u724c\u3002<\/p><p>\uff08D\uff09\u8ba4\u8bc1\u670d\u52a1\u5668\u5bf9\u5ba2\u6237\u7aef\u8fdb\u884c\u8ba4\u8bc1\u4ee5\u540e\uff0c\u786e\u8ba4\u65e0\u8bef\uff0c\u540c\u610f\u53d1\u653e\u4ee4\u724c\u3002<\/p><p>\uff08E\uff09\u5ba2\u6237\u7aef\u4f7f\u7528\u4ee4\u724c\uff0c\u5411\u8d44\u6e90\u670d\u52a1\u5668\u7533\u8bf7\u83b7\u53d6\u8d44\u6e90\u3002<\/p><p>\uff08F\uff09\u8d44\u6e90\u670d\u52a1\u5668\u786e\u8ba4\u4ee4\u724c\u65e0\u8bef\uff0c\u540c\u610f\u5411\u5ba2\u6237\u7aef\u5f00\u653e\u8d44\u6e90\u3002<\/p><\/blockquote>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e0d\u96be\u770b\u51fa\u6765\uff0c\u4e0a\u9762\u516d\u4e2a\u6b65\u9aa4\u4e4b\u4e2d\uff0cB\u662f\u5173\u952e\uff0c\u5373\u7528\u6237\u600e\u6837\u624d\u80fd\u7ed9\u4e8e\u5ba2\u6237\u7aef\u6388\u6743\u3002\u6709\u4e86\u8fd9\u4e2a\u6388\u6743\u4ee5\u540e\uff0c\u5ba2\u6237\u7aef\u5c31\u53ef\u4ee5\u83b7\u53d6\u4ee4\u724c\uff0c\u8fdb\u800c\u51ed\u4ee4\u724c\u83b7\u53d6\u8d44\u6e90\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e0b\u9762\u4e00\u4e00\u8bb2\u89e3\u5ba2\u6237\u7aef\u83b7\u53d6\u6388\u6743\u7684\u56db\u79cd\u6a21\u5f0f\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e94\u3001\u5ba2\u6237\u7aef\u7684\u6388\u6743\u6a21\u5f0f<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u5ba2\u6237\u7aef\u5fc5\u987b\u5f97\u5230\u7528\u6237\u7684\u6388\u6743\uff08authorization grant\uff09\uff0c\u624d\u80fd\u83b7\u5f97\u4ee4\u724c\uff08access token\uff09\u3002OAuth 2.0\u5b9a\u4e49\u4e86\u56db\u79cd\u6388\u6743\u65b9\u5f0f\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>\u6388\u6743\u7801\u6a21\u5f0f\uff08authorization code\uff09<\/li><li>\u7b80\u5316\u6a21\u5f0f\uff08implicit\uff09<\/li><li>\u5bc6\u7801\u6a21\u5f0f\uff08resource owner password credentials\uff09<\/li><li>\u5ba2\u6237\u7aef\u6a21\u5f0f\uff08client credentials\uff09<\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">\u516d\u3001\u6388\u6743\u7801\u6a21\u5f0f<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u6388\u6743\u7801\u6a21\u5f0f\uff08authorization code\uff09\u662f\u529f\u80fd\u6700\u5b8c\u6574\u3001\u6d41\u7a0b\u6700\u4e25\u5bc6\u7684\u6388\u6743\u6a21\u5f0f\u3002\u5b83\u7684\u7279\u70b9\u5c31\u662f\u901a\u8fc7\u5ba2\u6237\u7aef\u7684\u540e\u53f0\u670d\u52a1\u5668\uff0c\u4e0e&#8221;\u670d\u52a1\u63d0\u4f9b\u5546&#8221;\u7684\u8ba4\u8bc1\u670d\u52a1\u5668\u8fdb\u884c\u4e92\u52a8\u3002<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img decoding=\"async\" src=\"http:\/\/www.ruanyifeng.com\/blogimg\/asset\/2014\/bg2014051204.png\" alt=\"\u6388\u6743\u7801\u6a21\u5f0f\" \/><figcaption>OAuth2 \u6388\u6743\u7801\u6a21\u5f0f<\/figcaption><\/figure><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">\u5b83\u7684\u6b65\u9aa4\u5982\u4e0b\uff1a<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>\uff08A\uff09\u7528\u6237\u8bbf\u95ee\u5ba2\u6237\u7aef\uff0c\u540e\u8005\u5c06\u524d\u8005\u5bfc\u5411\u8ba4\u8bc1\u670d\u52a1\u5668\u3002<\/p><p>\uff08B\uff09\u7528\u6237\u9009\u62e9\u662f\u5426\u7ed9\u4e88\u5ba2\u6237\u7aef\u6388\u6743\u3002<\/p><p>\uff08C\uff09\u5047\u8bbe\u7528\u6237\u7ed9\u4e88\u6388\u6743\uff0c\u8ba4\u8bc1\u670d\u52a1\u5668\u5c06\u7528\u6237\u5bfc\u5411\u5ba2\u6237\u7aef\u4e8b\u5148\u6307\u5b9a\u7684&#8221;\u91cd\u5b9a\u5411URI&#8221;\uff08redirection URI\uff09\uff0c\u540c\u65f6\u9644\u4e0a\u4e00\u4e2a\u6388\u6743\u7801\u3002<\/p><p>\uff08D\uff09\u5ba2\u6237\u7aef\u6536\u5230\u6388\u6743\u7801\uff0c\u9644\u4e0a\u65e9\u5148\u7684&#8221;\u91cd\u5b9a\u5411URI&#8221;\uff0c\u5411\u8ba4\u8bc1\u670d\u52a1\u5668\u7533\u8bf7\u4ee4\u724c\u3002\u8fd9\u4e00\u6b65\u662f\u5728\u5ba2\u6237\u7aef\u7684\u540e\u53f0\u7684\u670d\u52a1\u5668\u4e0a\u5b8c\u6210\u7684\uff0c\u5bf9\u7528\u6237\u4e0d\u53ef\u89c1\u3002<\/p><p>\uff08E\uff09\u8ba4\u8bc1\u670d\u52a1\u5668\u6838\u5bf9\u4e86\u6388\u6743\u7801\u548c\u91cd\u5b9a\u5411URI\uff0c\u786e\u8ba4\u65e0\u8bef\u540e\uff0c\u5411\u5ba2\u6237\u7aef\u53d1\u9001\u8bbf\u95ee\u4ee4\u724c\uff08access token\uff09\u548c\u66f4\u65b0\u4ee4\u724c\uff08refresh token\uff09\u3002<\/p><\/blockquote>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e0b\u9762\u662f\u4e0a\u9762\u8fd9\u4e9b\u6b65\u9aa4\u6240\u9700\u8981\u7684\u53c2\u6570\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A\u6b65\u9aa4\u4e2d\uff0c\u5ba2\u6237\u7aef\u7533\u8bf7\u8ba4\u8bc1\u7684URI\uff0c\u5305\u542b\u4ee5\u4e0b\u53c2\u6570\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>response_type\uff1a\u8868\u793a\u6388\u6743\u7c7b\u578b\uff0c\u5fc5\u9009\u9879\uff0c\u6b64\u5904\u7684\u503c\u56fa\u5b9a\u4e3a&#8221;code&#8221;<\/li><li>client_id\uff1a\u8868\u793a\u5ba2\u6237\u7aef\u7684ID\uff0c\u5fc5\u9009\u9879<\/li><li>redirect_uri\uff1a\u8868\u793a\u91cd\u5b9a\u5411URI\uff0c\u53ef\u9009\u9879<\/li><li>scope\uff1a\u8868\u793a\u7533\u8bf7\u7684\u6743\u9650\u8303\u56f4\uff0c\u53ef\u9009\u9879<\/li><li>state\uff1a\u8868\u793a\u5ba2\u6237\u7aef\u7684\u5f53\u524d\u72b6\u6001\uff0c\u53ef\u4ee5\u6307\u5b9a\u4efb\u610f\u503c\uff0c\u8ba4\u8bc1\u670d\u52a1\u5668\u4f1a\u539f\u5c01\u4e0d\u52a8\u5730\u8fd4\u56de\u8fd9\u4e2a\u503c\u3002<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e0b\u9762\u662f\u4e00\u4e2a\u4f8b\u5b50\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\nGET \/authorize?response_type=code&amp;client_id=s6BhdRkqt3&amp;state=xyz\n        &amp;redirect_uri=https%3A%2F%2Fclient%2Eexample%2Ecom%2Fcb HTTP\/1.1\nHost: server.example.com<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">C\u6b65\u9aa4\u4e2d\uff0c\u670d\u52a1\u5668\u56de\u5e94\u5ba2\u6237\u7aef\u7684URI\uff0c\u5305\u542b\u4ee5\u4e0b\u53c2\u6570\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>code\uff1a\u8868\u793a\u6388\u6743\u7801\uff0c\u5fc5\u9009\u9879\u3002\u8be5\u7801\u7684\u6709\u6548\u671f\u5e94\u8be5\u5f88\u77ed\uff0c\u901a\u5e38\u8bbe\u4e3a10\u5206\u949f\uff0c\u5ba2\u6237\u7aef\u53ea\u80fd\u4f7f\u7528\u8be5\u7801\u4e00\u6b21\uff0c\u5426\u5219\u4f1a\u88ab\u6388\u6743\u670d\u52a1\u5668\u62d2\u7edd\u3002\u8be5\u7801\u4e0e\u5ba2\u6237\u7aefID\u548c\u91cd\u5b9a\u5411URI\uff0c\u662f\u4e00\u4e00\u5bf9\u5e94\u5173\u7cfb\u3002<\/li><li>state\uff1a\u5982\u679c\u5ba2\u6237\u7aef\u7684\u8bf7\u6c42\u4e2d\u5305\u542b\u8fd9\u4e2a\u53c2\u6570\uff0c\u8ba4\u8bc1\u670d\u52a1\u5668\u7684\u56de\u5e94\u4e5f\u5fc5\u987b\u4e00\u6a21\u4e00\u6837\u5305\u542b\u8fd9\u4e2a\u53c2\u6570\u3002<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e0b\u9762\u662f\u4e00\u4e2a\u4f8b\u5b50\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>HTTP\/1.1 302 Found\nLocation: https:\/\/client.example.com\/cb?code=SplxlOBeZQQYbYS6WxSbIA\n          &amp;state=xyz<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">D\u6b65\u9aa4\u4e2d\uff0c\u5ba2\u6237\u7aef\u5411\u8ba4\u8bc1\u670d\u52a1\u5668\u7533\u8bf7\u4ee4\u724c\u7684HTTP\u8bf7\u6c42\uff0c\u5305\u542b\u4ee5\u4e0b\u53c2\u6570\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>grant_type\uff1a\u8868\u793a\u4f7f\u7528\u7684\u6388\u6743\u6a21\u5f0f\uff0c\u5fc5\u9009\u9879\uff0c\u6b64\u5904\u7684\u503c\u56fa\u5b9a\u4e3a&#8221;authorization_code&#8221;\u3002<\/li><li>code\uff1a\u8868\u793a\u4e0a\u4e00\u6b65\u83b7\u5f97\u7684\u6388\u6743\u7801\uff0c\u5fc5\u9009\u9879\u3002<\/li><li>redirect_uri\uff1a\u8868\u793a\u91cd\u5b9a\u5411URI\uff0c\u5fc5\u9009\u9879\uff0c\u4e14\u5fc5\u987b\u4e0eA\u6b65\u9aa4\u4e2d\u7684\u8be5\u53c2\u6570\u503c\u4fdd\u6301\u4e00\u81f4\u3002<\/li><li>client_id\uff1a\u8868\u793a\u5ba2\u6237\u7aefID\uff0c\u5fc5\u9009\u9879\u3002<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e0b\u9762\u662f\u4e00\u4e2a\u4f8b\u5b50\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>POST \/token HTTP\/1.1\nHost: server.example.com\nAuthorization: Basic czZCaGRSa3F0MzpnWDFmQmF0M2JW\nContent-Type: application\/x-www-form-urlencoded\n\ngrant_type=authorization_code&amp;code=SplxlOBeZQQYbYS6WxSbIA\n&amp;redirect_uri=https%3A%2F%2Fclient%2Eexample%2Ecom%2Fcb<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">E\u6b65\u9aa4\u4e2d\uff0c\u8ba4\u8bc1\u670d\u52a1\u5668\u53d1\u9001\u7684HTTP\u56de\u590d\uff0c\u5305\u542b\u4ee5\u4e0b\u53c2\u6570\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>access_token\uff1a\u8868\u793a\u8bbf\u95ee\u4ee4\u724c\uff0c\u5fc5\u9009\u9879\u3002<\/li><li>token_type\uff1a\u8868\u793a\u4ee4\u724c\u7c7b\u578b\uff0c\u8be5\u503c\u5927\u5c0f\u5199\u4e0d\u654f\u611f\uff0c\u5fc5\u9009\u9879\uff0c\u53ef\u4ee5\u662fbearer\u7c7b\u578b\u6216mac\u7c7b\u578b\u3002<\/li><li>expires_in\uff1a\u8868\u793a\u8fc7\u671f\u65f6\u95f4\uff0c\u5355\u4f4d\u4e3a\u79d2\u3002\u5982\u679c\u7701\u7565\u8be5\u53c2\u6570\uff0c\u5fc5\u987b\u5176\u4ed6\u65b9\u5f0f\u8bbe\u7f6e\u8fc7\u671f\u65f6\u95f4\u3002<\/li><li>refresh_token\uff1a\u8868\u793a\u66f4\u65b0\u4ee4\u724c\uff0c\u7528\u6765\u83b7\u53d6\u4e0b\u4e00\u6b21\u7684\u8bbf\u95ee\u4ee4\u724c\uff0c\u53ef\u9009\u9879\u3002<\/li><li>scope\uff1a\u8868\u793a\u6743\u9650\u8303\u56f4\uff0c\u5982\u679c\u4e0e\u5ba2\u6237\u7aef\u7533\u8bf7\u7684\u8303\u56f4\u4e00\u81f4\uff0c\u6b64\u9879\u53ef\u7701\u7565\u3002<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e0b\u9762\u662f\u4e00\u4e2a\u4f8b\u5b50\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>     HTTP\/1.1 200 OK\n     Content-Type: application\/json;charset=UTF-8\n     Cache-Control: no-store\n     Pragma: no-cache\n\n     {\n       \"access_token\":\"2YotnFZFEjr1zCsicMWpAA\",\n       \"token_type\":\"example\",\n       \"expires_in\":3600,\n       \"refresh_token\":\"tGzv3JOkF0XG5Qx2TlKWIA\",\n       \"example_parameter\":\"example_value\"\n     }<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u4ece\u4e0a\u9762\u4ee3\u7801\u53ef\u4ee5\u770b\u5230\uff0c\u76f8\u5173\u53c2\u6570\u4f7f\u7528JSON\u683c\u5f0f\u53d1\u9001\uff08Content-Type: application\/json\uff09\u3002\u6b64\u5916\uff0cHTTP\u5934\u4fe1\u606f\u4e2d\u660e\u786e\u6307\u5b9a\u4e0d\u5f97\u7f13\u5b58\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e03\u3001\u7b80\u5316\u6a21\u5f0f<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u7b80\u5316\u6a21\u5f0f\uff08implicit grant type\uff09\u4e0d\u901a\u8fc7\u7b2c\u4e09\u65b9\u5e94\u7528\u7a0b\u5e8f\u7684\u670d\u52a1\u5668\uff0c\u76f4\u63a5\u5728\u6d4f\u89c8\u5668\u4e2d\u5411\u8ba4\u8bc1\u670d\u52a1\u5668\u7533\u8bf7\u4ee4\u724c\uff0c\u8df3\u8fc7\u4e86&#8221;\u6388\u6743\u7801&#8221;\u8fd9\u4e2a\u6b65\u9aa4\uff0c\u56e0\u6b64\u5f97\u540d\u3002\u6240\u6709\u6b65\u9aa4\u5728\u6d4f\u89c8\u5668\u4e2d\u5b8c\u6210\uff0c\u4ee4\u724c\u5bf9\u8bbf\u95ee\u8005\u662f\u53ef\u89c1\u7684\uff0c\u4e14\u5ba2\u6237\u7aef\u4e0d\u9700\u8981\u8ba4\u8bc1\u3002<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img decoding=\"async\" src=\"http:\/\/www.ruanyifeng.com\/blogimg\/asset\/2014\/bg2014051205.png\" alt=\"\u7b80\u5316\u6a21\u5f0f\" \/><figcaption>\u7b80\u5316\u6a21\u5f0f<\/figcaption><\/figure><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">\u5b83\u7684\u6b65\u9aa4\u5982\u4e0b\uff1a<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>\uff08A\uff09\u5ba2\u6237\u7aef\u5c06\u7528\u6237\u5bfc\u5411\u8ba4\u8bc1\u670d\u52a1\u5668\u3002<\/p><p>\uff08B\uff09\u7528\u6237\u51b3\u5b9a\u662f\u5426\u7ed9\u4e8e\u5ba2\u6237\u7aef\u6388\u6743\u3002<\/p><p>\uff08C\uff09\u5047\u8bbe\u7528\u6237\u7ed9\u4e88\u6388\u6743\uff0c\u8ba4\u8bc1\u670d\u52a1\u5668\u5c06\u7528\u6237\u5bfc\u5411\u5ba2\u6237\u7aef\u6307\u5b9a\u7684&#8221;\u91cd\u5b9a\u5411URI&#8221;\uff0c\u5e76\u5728URI\u7684Hash\u90e8\u5206\u5305\u542b\u4e86\u8bbf\u95ee\u4ee4\u724c\u3002<\/p><p>\uff08D\uff09\u6d4f\u89c8\u5668\u5411\u8d44\u6e90\u670d\u52a1\u5668\u53d1\u51fa\u8bf7\u6c42\uff0c\u5176\u4e2d\u4e0d\u5305\u62ec\u4e0a\u4e00\u6b65\u6536\u5230\u7684Hash\u503c\u3002<\/p><p>\uff08E\uff09\u8d44\u6e90\u670d\u52a1\u5668\u8fd4\u56de\u4e00\u4e2a\u7f51\u9875\uff0c\u5176\u4e2d\u5305\u542b\u7684\u4ee3\u7801\u53ef\u4ee5\u83b7\u53d6Hash\u503c\u4e2d\u7684\u4ee4\u724c\u3002<\/p><p>\uff08F\uff09\u6d4f\u89c8\u5668\u6267\u884c\u4e0a\u4e00\u6b65\u83b7\u5f97\u7684\u811a\u672c\uff0c\u63d0\u53d6\u51fa\u4ee4\u724c\u3002<\/p><p>\uff08G\uff09\u6d4f\u89c8\u5668\u5c06\u4ee4\u724c\u53d1\u7ed9\u5ba2\u6237\u7aef\u3002<\/p><\/blockquote>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e0b\u9762\u662f\u4e0a\u9762\u8fd9\u4e9b\u6b65\u9aa4\u6240\u9700\u8981\u7684\u53c2\u6570\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A\u6b65\u9aa4\u4e2d\uff0c\u5ba2\u6237\u7aef\u53d1\u51fa\u7684HTTP\u8bf7\u6c42\uff0c\u5305\u542b\u4ee5\u4e0b\u53c2\u6570\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>response_type\uff1a\u8868\u793a\u6388\u6743\u7c7b\u578b\uff0c\u6b64\u5904\u7684\u503c\u56fa\u5b9a\u4e3a&#8221;token&#8221;\uff0c\u5fc5\u9009\u9879\u3002<\/li><li>client_id\uff1a\u8868\u793a\u5ba2\u6237\u7aef\u7684ID\uff0c\u5fc5\u9009\u9879\u3002<\/li><li>redirect_uri\uff1a\u8868\u793a\u91cd\u5b9a\u5411\u7684URI\uff0c\u53ef\u9009\u9879\u3002<\/li><li>scope\uff1a\u8868\u793a\u6743\u9650\u8303\u56f4\uff0c\u53ef\u9009\u9879\u3002<\/li><li>state\uff1a\u8868\u793a\u5ba2\u6237\u7aef\u7684\u5f53\u524d\u72b6\u6001\uff0c\u53ef\u4ee5\u6307\u5b9a\u4efb\u610f\u503c\uff0c\u8ba4\u8bc1\u670d\u52a1\u5668\u4f1a\u539f\u5c01\u4e0d\u52a8\u5730\u8fd4\u56de\u8fd9\u4e2a\u503c\u3002<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e0b\u9762\u662f\u4e00\u4e2a\u4f8b\u5b50\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\n    GET \/authorize?response_type=token&amp;client_id=s6BhdRkqt3&amp;state=xyz\n        &amp;redirect_uri=https%3A%2F%2Fclient%2Eexample%2Ecom%2Fcb HTTP\/1.1\n    Host: server.example.com<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">C\u6b65\u9aa4\u4e2d\uff0c\u8ba4\u8bc1\u670d\u52a1\u5668\u56de\u5e94\u5ba2\u6237\u7aef\u7684URI\uff0c\u5305\u542b\u4ee5\u4e0b\u53c2\u6570\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>access_token\uff1a\u8868\u793a\u8bbf\u95ee\u4ee4\u724c\uff0c\u5fc5\u9009\u9879\u3002<\/li><li>token_type\uff1a\u8868\u793a\u4ee4\u724c\u7c7b\u578b\uff0c\u8be5\u503c\u5927\u5c0f\u5199\u4e0d\u654f\u611f\uff0c\u5fc5\u9009\u9879\u3002<\/li><li>expires_in\uff1a\u8868\u793a\u8fc7\u671f\u65f6\u95f4\uff0c\u5355\u4f4d\u4e3a\u79d2\u3002\u5982\u679c\u7701\u7565\u8be5\u53c2\u6570\uff0c\u5fc5\u987b\u5176\u4ed6\u65b9\u5f0f\u8bbe\u7f6e\u8fc7\u671f\u65f6\u95f4\u3002<\/li><li>scope\uff1a\u8868\u793a\u6743\u9650\u8303\u56f4\uff0c\u5982\u679c\u4e0e\u5ba2\u6237\u7aef\u7533\u8bf7\u7684\u8303\u56f4\u4e00\u81f4\uff0c\u6b64\u9879\u53ef\u7701\u7565\u3002<\/li><li>state\uff1a\u5982\u679c\u5ba2\u6237\u7aef\u7684\u8bf7\u6c42\u4e2d\u5305\u542b\u8fd9\u4e2a\u53c2\u6570\uff0c\u8ba4\u8bc1\u670d\u52a1\u5668\u7684\u56de\u5e94\u4e5f\u5fc5\u987b\u4e00\u6a21\u4e00\u6837\u5305\u542b\u8fd9\u4e2a\u53c2\u6570\u3002<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e0b\u9762\u662f\u4e00\u4e2a\u4f8b\u5b50\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\n     HTTP\/1.1 302 Found\n     Location: http:\/\/example.com\/cb#access_token=2YotnFZFEjr1zCsicMWpAA\n               &amp;state=xyz&amp;token_type=example&amp;expires_in=3600<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728\u4e0a\u9762\u7684\u4f8b\u5b50\u4e2d\uff0c\u8ba4\u8bc1\u670d\u52a1\u5668\u7528HTTP\u5934\u4fe1\u606f\u7684Location\u680f\uff0c\u6307\u5b9a\u6d4f\u89c8\u5668\u91cd\u5b9a\u5411\u7684\u7f51\u5740\u3002\u6ce8\u610f\uff0c\u5728\u8fd9\u4e2a\u7f51\u5740\u7684Hash\u90e8\u5206\u5305\u542b\u4e86\u4ee4\u724c\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u6839\u636e\u4e0a\u9762\u7684D\u6b65\u9aa4\uff0c\u4e0b\u4e00\u6b65\u6d4f\u89c8\u5668\u4f1a\u8bbf\u95eeLocation\u6307\u5b9a\u7684\u7f51\u5740\uff0c\u4f46\u662fHash\u90e8\u5206\u4e0d\u4f1a\u53d1\u9001\u3002\u63a5\u4e0b\u6765\u7684E\u6b65\u9aa4\uff0c\u670d\u52a1\u63d0\u4f9b\u5546\u7684\u8d44\u6e90\u670d\u52a1\u5668\u53d1\u9001\u8fc7\u6765\u7684\u4ee3\u7801\uff0c\u4f1a\u63d0\u53d6\u51faHash\u4e2d\u7684\u4ee4\u724c\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u516b\u3001\u5bc6\u7801\u6a21\u5f0f<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u5bc6\u7801\u6a21\u5f0f\uff08Resource Owner Password Credentials Grant\uff09\u4e2d\uff0c\u7528\u6237\u5411\u5ba2\u6237\u7aef\u63d0\u4f9b\u81ea\u5df1\u7684\u7528\u6237\u540d\u548c\u5bc6\u7801\u3002\u5ba2\u6237\u7aef\u4f7f\u7528\u8fd9\u4e9b\u4fe1\u606f\uff0c\u5411&#8221;\u670d\u52a1\u5546\u63d0\u4f9b\u5546&#8221;\u7d22\u8981\u6388\u6743\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728\u8fd9\u79cd\u6a21\u5f0f\u4e2d\uff0c\u7528\u6237\u5fc5\u987b\u628a\u81ea\u5df1\u7684\u5bc6\u7801\u7ed9\u5ba2\u6237\u7aef\uff0c\u4f46\u662f\u5ba2\u6237\u7aef\u4e0d\u5f97\u50a8\u5b58\u5bc6\u7801\u3002\u8fd9\u901a\u5e38\u7528\u5728\u7528\u6237\u5bf9\u5ba2\u6237\u7aef\u9ad8\u5ea6\u4fe1\u4efb\u7684\u60c5\u51b5\u4e0b\uff0c\u6bd4\u5982\u5ba2\u6237\u7aef\u662f\u64cd\u4f5c\u7cfb\u7edf\u7684\u4e00\u90e8\u5206\uff0c\u6216\u8005\u7531\u4e00\u4e2a\u8457\u540d\u516c\u53f8\u51fa\u54c1\u3002\u800c\u8ba4\u8bc1\u670d\u52a1\u5668\u53ea\u6709\u5728\u5176\u4ed6\u6388\u6743\u6a21\u5f0f\u65e0\u6cd5\u6267\u884c\u7684\u60c5\u51b5\u4e0b\uff0c\u624d\u80fd\u8003\u8651\u4f7f\u7528\u8fd9\u79cd\u6a21\u5f0f\u3002<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img decoding=\"async\" src=\"http:\/\/www.ruanyifeng.com\/blogimg\/asset\/2014\/bg2014051206.png\" alt=\"\u5bc6\u7801\u6a21\u5f0f\" \/><figcaption>OAuth2 \u7684\u5bc6\u7801\u6a21\u5f0f<\/figcaption><\/figure><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">\u5b83\u7684\u6b65\u9aa4\u5982\u4e0b\uff1a<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>\uff08A\uff09\u7528\u6237\u5411\u5ba2\u6237\u7aef\u63d0\u4f9b\u7528\u6237\u540d\u548c\u5bc6\u7801\u3002<\/p><p>\uff08B\uff09\u5ba2\u6237\u7aef\u5c06\u7528\u6237\u540d\u548c\u5bc6\u7801\u53d1\u7ed9\u8ba4\u8bc1\u670d\u52a1\u5668\uff0c\u5411\u540e\u8005\u8bf7\u6c42\u4ee4\u724c\u3002<\/p><p>\uff08C\uff09\u8ba4\u8bc1\u670d\u52a1\u5668\u786e\u8ba4\u65e0\u8bef\u540e\uff0c\u5411\u5ba2\u6237\u7aef\u63d0\u4f9b\u8bbf\u95ee\u4ee4\u724c\u3002<\/p><\/blockquote>\n\n\n\n<p class=\"wp-block-paragraph\">B\u6b65\u9aa4\u4e2d\uff0c\u5ba2\u6237\u7aef\u53d1\u51fa\u7684HTTP\u8bf7\u6c42\uff0c\u5305\u542b\u4ee5\u4e0b\u53c2\u6570\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>grant_type\uff1a\u8868\u793a\u6388\u6743\u7c7b\u578b\uff0c\u6b64\u5904\u7684\u503c\u56fa\u5b9a\u4e3a&#8221;password&#8221;\uff0c\u5fc5\u9009\u9879\u3002<\/li><li>username\uff1a\u8868\u793a\u7528\u6237\u540d\uff0c\u5fc5\u9009\u9879\u3002<\/li><li>password\uff1a\u8868\u793a\u7528\u6237\u7684\u5bc6\u7801\uff0c\u5fc5\u9009\u9879\u3002<\/li><li>scope\uff1a\u8868\u793a\u6743\u9650\u8303\u56f4\uff0c\u53ef\u9009\u9879\u3002<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e0b\u9762\u662f\u4e00\u4e2a\u4f8b\u5b50\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\n     POST \/token HTTP\/1.1\n     Host: server.example.com\n     Authorization: Basic czZCaGRSa3F0MzpnWDFmQmF0M2JW\n     Content-Type: application\/x-www-form-urlencoded\n\n     grant_type=password&amp;username=johndoe&amp;password=A3ddj3w<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">C\u6b65\u9aa4\u4e2d\uff0c\u8ba4\u8bc1\u670d\u52a1\u5668\u5411\u5ba2\u6237\u7aef\u53d1\u9001\u8bbf\u95ee\u4ee4\u724c\uff0c\u4e0b\u9762\u662f\u4e00\u4e2a\u4f8b\u5b50\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\n     HTTP\/1.1 200 OK\n     Content-Type: application\/json;charset=UTF-8\n     Cache-Control: no-store\n     Pragma: no-cache\n\n     {\n       \"access_token\":\"2YotnFZFEjr1zCsicMWpAA\",\n       \"token_type\":\"example\",\n       \"expires_in\":3600,\n       \"refresh_token\":\"tGzv3JOkF0XG5Qx2TlKWIA\",\n       \"example_parameter\":\"example_value\"\n     }<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e0a\u9762\u4ee3\u7801\u4e2d\uff0c\u5404\u4e2a\u53c2\u6570\u7684\u542b\u4e49\u53c2\u89c1\u300a\u6388\u6743\u7801\u6a21\u5f0f\u300b\u4e00\u8282\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u6574\u4e2a\u8fc7\u7a0b\u4e2d\uff0c\u5ba2\u6237\u7aef\u4e0d\u5f97\u4fdd\u5b58\u7528\u6237\u7684\u5bc6\u7801\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e5d\u3001\u5ba2\u6237\u7aef\u6a21\u5f0f<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u5ba2\u6237\u7aef\u6a21\u5f0f\uff08Client Credentials Grant\uff09\u6307\u5ba2\u6237\u7aef\u4ee5\u81ea\u5df1\u7684\u540d\u4e49\uff0c\u800c\u4e0d\u662f\u4ee5\u7528\u6237\u7684\u540d\u4e49\uff0c\u5411&#8221;\u670d\u52a1\u63d0\u4f9b\u5546&#8221;\u8fdb\u884c\u8ba4\u8bc1\u3002\u4e25\u683c\u5730\u8bf4\uff0c\u5ba2\u6237\u7aef\u6a21\u5f0f\u5e76\u4e0d\u5c5e\u4e8eOAuth\u6846\u67b6\u6240\u8981\u89e3\u51b3\u7684\u95ee\u9898\u3002\u5728\u8fd9\u79cd\u6a21\u5f0f\u4e2d\uff0c\u7528\u6237\u76f4\u63a5\u5411\u5ba2\u6237\u7aef\u6ce8\u518c\uff0c\u5ba2\u6237\u7aef\u4ee5\u81ea\u5df1\u7684\u540d\u4e49\u8981\u6c42&#8221;\u670d\u52a1\u63d0\u4f9b\u5546&#8221;\u63d0\u4f9b\u670d\u52a1\uff0c\u5176\u5b9e\u4e0d\u5b58\u5728\u6388\u6743\u95ee\u9898\u3002<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img decoding=\"async\" src=\"http:\/\/www.ruanyifeng.com\/blogimg\/asset\/2014\/bg2014051207.png\" alt=\"\u5ba2\u6237\u7aef\u6a21\u5f0f\" \/><figcaption>OAuth2 \u5ba2\u6237\u7aef\u6a21\u5f0f<\/figcaption><\/figure><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">\u5b83\u7684\u6b65\u9aa4\u5982\u4e0b\uff1a<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>\uff08A\uff09\u5ba2\u6237\u7aef\u5411\u8ba4\u8bc1\u670d\u52a1\u5668\u8fdb\u884c\u8eab\u4efd\u8ba4\u8bc1\uff0c\u5e76\u8981\u6c42\u4e00\u4e2a\u8bbf\u95ee\u4ee4\u724c\u3002<\/p><p>\uff08B\uff09\u8ba4\u8bc1\u670d\u52a1\u5668\u786e\u8ba4\u65e0\u8bef\u540e\uff0c\u5411\u5ba2\u6237\u7aef\u63d0\u4f9b\u8bbf\u95ee\u4ee4\u724c\u3002<\/p><\/blockquote>\n\n\n\n<p class=\"wp-block-paragraph\">A\u6b65\u9aa4\u4e2d\uff0c\u5ba2\u6237\u7aef\u53d1\u51fa\u7684HTTP\u8bf7\u6c42\uff0c\u5305\u542b\u4ee5\u4e0b\u53c2\u6570\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>grant<em>type\uff1a\u8868\u793a\u6388\u6743\u7c7b\u578b\uff0c\u6b64\u5904\u7684\u503c\u56fa\u5b9a\u4e3a&#8221;client<\/em>credentials&#8221;\uff0c\u5fc5\u9009\u9879\u3002<\/li><li>scope\uff1a\u8868\u793a\u6743\u9650\u8303\u56f4\uff0c\u53ef\u9009\u9879\u3002<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>\n     POST \/token HTTP\/1.1\n     Host: server.example.com\n     Authorization: Basic czZCaGRSa3F0MzpnWDFmQmF0M2JW\n     Content-Type: application\/x-www-form-urlencoded\n\n     grant_type=client_credentials<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u8ba4\u8bc1\u670d\u52a1\u5668\u5fc5\u987b\u4ee5\u67d0\u79cd\u65b9\u5f0f\uff0c\u9a8c\u8bc1\u5ba2\u6237\u7aef\u8eab\u4efd\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">B\u6b65\u9aa4\u4e2d\uff0c\u8ba4\u8bc1\u670d\u52a1\u5668\u5411\u5ba2\u6237\u7aef\u53d1\u9001\u8bbf\u95ee\u4ee4\u724c\uff0c\u4e0b\u9762\u662f\u4e00\u4e2a\u4f8b\u5b50\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\n     HTTP\/1.1 200 OK\n     Content-Type: application\/json;charset=UTF-8\n     Cache-Control: no-store\n     Pragma: no-cache\n\n     {\n       \"access_token\":\"2YotnFZFEjr1zCsicMWpAA\",\n       \"token_type\":\"example\",\n       \"expires_in\":3600,\n       \"example_parameter\":\"example_value\"\n     }<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e0a\u9762\u4ee3\u7801\u4e2d\uff0c\u5404\u4e2a\u53c2\u6570\u7684\u542b\u4e49\u53c2\u89c1\u300a\u6388\u6743\u7801\u6a21\u5f0f\u300b\u4e00\u8282\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u5341\u3001\u66f4\u65b0\u4ee4\u724c<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u5982\u679c\u7528\u6237\u8bbf\u95ee\u7684\u65f6\u5019\uff0c\u5ba2\u6237\u7aef\u7684&#8221;\u8bbf\u95ee\u4ee4\u724c&#8221;\u5df2\u7ecf\u8fc7\u671f\uff0c\u5219\u9700\u8981\u4f7f\u7528&#8221;\u66f4\u65b0\u4ee4\u724c&#8221;\u7533\u8bf7\u4e00\u4e2a\u65b0\u7684\u8bbf\u95ee\u4ee4\u724c\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5ba2\u6237\u7aef\u53d1\u51fa\u66f4\u65b0\u4ee4\u724c\u7684HTTP\u8bf7\u6c42\uff0c\u5305\u542b\u4ee5\u4e0b\u53c2\u6570\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>grant<em>type\uff1a\u8868\u793a\u4f7f\u7528\u7684\u6388\u6743\u6a21\u5f0f\uff0c\u6b64\u5904\u7684\u503c\u56fa\u5b9a\u4e3a&#8221;refresh<\/em>token&#8221;\uff0c\u5fc5\u9009\u9879\u3002<\/li><li>refresh_token\uff1a\u8868\u793a\u65e9\u524d\u6536\u5230\u7684\u66f4\u65b0\u4ee4\u724c\uff0c\u5fc5\u9009\u9879\u3002<\/li><li>scope\uff1a\u8868\u793a\u7533\u8bf7\u7684\u6388\u6743\u8303\u56f4\uff0c\u4e0d\u53ef\u4ee5\u8d85\u51fa\u4e0a\u4e00\u6b21\u7533\u8bf7\u7684\u8303\u56f4\uff0c\u5982\u679c\u7701\u7565\u8be5\u53c2\u6570\uff0c\u5219\u8868\u793a\u4e0e\u4e0a\u4e00\u6b21\u4e00\u81f4\u3002<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e0b\u9762\u662f\u4e00\u4e2a\u4f8b\u5b50\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\n     POST \/token HTTP\/1.1\n     Host: server.example.com\n     Authorization: Basic czZCaGRSa3F0MzpnWDFmQmF0M2JW\n     Content-Type: application\/x-www-form-urlencoded\n\n     grant_type=refresh_token&amp;refresh_token=tGzv3JOkF0XG5Qx2TlKWIA<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u539f\u6587\u5730\u5740\uff1ahttp:\/\/www.ruanyifeng.com\/blog\/2014\/05\/oauth_2_0.html<\/p>\n<!-- <audio autoplay=\"autoplay\" height=\"100\" width=\"100\" hidden=\"true\"><source src=\"https:\/\/c.coka.la\/orAvPR.mp3\" type=\"audio\/mp3\"\/><\/audio><img decoding=\"async\" src=\"https:\/\/images.weserv.nl\/?url=https:\/\/ws3.sinaimg.cn\/large\/8fa5dcfcgy1g4em3rzar5j20ib089ae0.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/> --><p><!-- <img decoding=\"async\" src=\"https:\/\/raw.githubusercontent.com\/xmt1139057136\/xttblog\/master\/8fa5dcfcgy1g4em3rzar5j20ib089ae0.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/>--><img decoding=\"async\" src=\"https:\/\/saas.51autoparts.cn\/api\/admin\/sys-file\/oss\/file?fileName=84db51f8561e448f9a4fda2eff0811f9.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/><\/p><p>\u6700\u540e\uff0c\u6b22\u8fce\u5173\u6ce8\u6211\u7684\u4e2a\u4eba\u5fae\u4fe1\u516c\u4f17\u53f7\uff1a\u4e1a\u4f59\u8349\uff08yyucao\uff09\uff01<b>\u53ef\u52a0\u4f5c\u8005\u5fae\u4fe1\u53f7\uff1a<font color=\"red\">xttblog2<\/font>\u3002\u5907\u6ce8\uff1a\u201c1\u201d\uff0c\u6dfb\u52a0\u535a\u4e3b\u5fae\u4fe1\u62c9\u4f60\u8fdb\u5fae\u4fe1\u7fa4\u3002\u5907\u6ce8\u9519\u8bef\u4e0d\u4f1a\u540c\u610f\u597d\u53cb\u7533\u8bf7\u3002<\/b>\u518d\u6b21\u611f\u8c22\u60a8\u7684\u5173\u6ce8\uff01\u540e\u7eed\u6709\u7cbe\u5f69\u5185\u5bb9\u4f1a\u7b2c\u4e00\u65f6\u95f4\u53d1\u7ed9\u60a8\uff01\u539f\u521b\u6587\u7ae0\u6295\u7a3f\u8bf7\u53d1\u9001\u81f3532009913@qq.com\u90ae\u7bb1\u3002\u5546\u52a1\u5408\u4f5c\u4e5f\u53ef\u6dfb\u52a0\u4f5c\u8005\u5fae\u4fe1\u8fdb\u884c\u8054\u7cfb\uff01<\/p><p>\u672c\u6587\u539f\u6587\u51fa\u5904\uff1a<a href=\"https:\/\/www.xttblog.com\">\u4e1a\u4f59\u8349<\/a>\uff1a &raquo; <a href=\"https:\/\/www.xttblog.com\/?p=4735\">\u7406\u89e3OAuth 2.0 &#8211; \u962e\u4e00\u5cf0\u7684\u7f51\u7edc\u65e5\u5fd7<\/a><\/p><!-- <div class=\"bd-reward-stl\"><button id=\"bdRewardBtn\"><span><\/span><\/button><\/div> -->","protected":false},"excerpt":{"rendered":"<p>\u962e\u4e00\u5cf0\u7684\u8fd9\u7bc7\u6587\u7ae0\u88ab\u5e7f\u6cdb\u8f6c\u8f7d\uff01\u5199\u7684\u975e\u5e38\u597d\uff0c\u5f88\u591a\u5927\u4f6c\u90fd\u62ff\u6765\u501f\u9274\uff01 \u8fd9\u7bc7\u6587\u7ae0\u8bc4\u8bba\u4e5f\u5f88\u591a\uff0c\u8bc4\u8bba\u5185\u5bb9\u8d85\u8fc7\u4e86\u539f\u6587\u5b57\u6570\u3002\u5f88\u4e45 [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[1599,1001,182,682,737],"class_list":["post-4735","post","type-post","status-publish","format-standard","hentry","category-yyzt","tag-jjwt","tag-oauth2","tag-oauth","tag-682","tag-737"],"_links":{"self":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/4735","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4735"}],"version-history":[{"count":2,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/4735\/revisions"}],"predecessor-version":[{"id":4738,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/4735\/revisions\/4738"}],"wp:attachment":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4735"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4735"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4735"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}