{"id":142,"date":"2016-09-14T10:26:54","date_gmt":"2016-09-14T02:26:54","guid":{"rendered":"http:\/\/www.secondsend.com\/wordpress\/?p=142"},"modified":"2016-09-14T10:26:54","modified_gmt":"2016-09-14T02:26:54","slug":"%e7%90%86%e8%a7%a3oauth-2-0","status":"publish","type":"post","link":"http:\/\/www.homconnect.cn\/?p=142","title":{"rendered":"\u7406\u89e3OAuth 2.0"},"content":{"rendered":"<p><a href=\"http:\/\/en.wikipedia.org\/wiki\/OAuth\" target=\"_blank\">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<!--more--><\/p>\n<p>\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\">RFC 6749<\/a>\u3002<\/p>\n<p><img decoding=\"async\" title=\"\" src=\"http:\/\/image.beekka.com\/blog\/2014\/bg2014051201.png\" alt=\"OAuth Logo\" \/><\/p>\n<h2>\u4e00\u3001\u5e94\u7528\u573a\u666f<\/h2>\n<p>\u4e3a\u4e86\u7406\u89e3OAuth\u7684\u9002\u7528\u573a\u5408\uff0c\u8ba9\u6211\u4e3e\u4e00\u4e2a\u5047\u8bbe\u7684\u4f8b\u5b50\u3002<\/p>\n<p>\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<p><img decoding=\"async\" title=\"\" src=\"http:\/\/image.beekka.com\/blog\/2014\/bg2014051202.png\" alt=\"\u4e91\u51b2\u5370\" \/><\/p>\n<p>\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<p>\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<blockquote><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>\n<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>\n<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>\n<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>\n<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<p>OAuth\u5c31\u662f\u4e3a\u4e86\u89e3\u51b3\u4e0a\u9762\u8fd9\u4e9b\u95ee\u9898\u800c\u8bde\u751f\u7684\u3002<\/p>\n<h2>\u4e8c\u3001\u540d\u8bcd\u5b9a\u4e49<\/h2>\n<p>\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<blockquote><p>\uff081\uff09 <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>\n<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>\n<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>\n<p>\uff084\uff09<strong>User Agent<\/strong>\uff1a\u7528\u6237\u4ee3\u7406\uff0c\u672c\u6587\u4e2d\u5c31\u662f\u6307\u6d4f\u89c8\u5668\u3002<\/p>\n<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>\n<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<p>\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<h2>\u4e09\u3001OAuth\u7684\u601d\u8def<\/h2>\n<p>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<p>&#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<h2>\u56db\u3001\u8fd0\u884c\u6d41\u7a0b<\/h2>\n<p>OAuth 2.0\u7684\u8fd0\u884c\u6d41\u7a0b\u5982\u4e0b\u56fe\uff0c\u6458\u81eaRFC 6749\u3002<\/p>\n<p><img decoding=\"async\" title=\"\" src=\"http:\/\/image.beekka.com\/blog\/2014\/bg2014051203.png\" alt=\"OAuth\u8fd0\u884c\u6d41\u7a0b\" \/><\/p>\n<blockquote><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>\n<p>\uff08B\uff09\u7528\u6237\u540c\u610f\u7ed9\u4e88\u5ba2\u6237\u7aef\u6388\u6743\u3002<\/p>\n<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>\n<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>\n<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>\n<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<p>\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<p>\u4e0b\u9762\u4e00\u4e00\u8bb2\u89e3\u5ba2\u6237\u7aef\u83b7\u53d6\u6388\u6743\u7684\u56db\u79cd\u6a21\u5f0f\u3002<\/p>\n<h2>\u4e94\u3001\u5ba2\u6237\u7aef\u7684\u6388\u6743\u6a21\u5f0f<\/h2>\n<p>\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<ul>\n<li>\u6388\u6743\u7801\u6a21\u5f0f\uff08authorization code\uff09<\/li>\n<li>\u7b80\u5316\u6a21\u5f0f\uff08implicit\uff09<\/li>\n<li>\u5bc6\u7801\u6a21\u5f0f\uff08resource owner password credentials\uff09<\/li>\n<li>\u5ba2\u6237\u7aef\u6a21\u5f0f\uff08client credentials\uff09<\/li>\n<\/ul>\n<h2>\u516d\u3001\u6388\u6743\u7801\u6a21\u5f0f<\/h2>\n<p>\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<p><img decoding=\"async\" title=\"\" src=\"http:\/\/image.beekka.com\/blog\/2014\/bg2014051204.png\" alt=\"\u6388\u6743\u7801\u6a21\u5f0f\" \/><\/p>\n<p>\u5b83\u7684\u6b65\u9aa4\u5982\u4e0b\uff1a<\/p>\n<blockquote><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>\n<p>\uff08B\uff09\u7528\u6237\u9009\u62e9\u662f\u5426\u7ed9\u4e88\u5ba2\u6237\u7aef\u6388\u6743\u3002<\/p>\n<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>\n<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>\n<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<p>\u4e0b\u9762\u662f\u4e0a\u9762\u8fd9\u4e9b\u6b65\u9aa4\u6240\u9700\u8981\u7684\u53c2\u6570\u3002<\/p>\n<p>A\u6b65\u9aa4\u4e2d\uff0c\u5ba2\u6237\u7aef\u7533\u8bf7\u8ba4\u8bc1\u7684URI\uff0c\u5305\u542b\u4ee5\u4e0b\u53c2\u6570\uff1a<\/p>\n<ul>\n<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>\n<li>client_id\uff1a\u8868\u793a\u5ba2\u6237\u7aef\u7684ID\uff0c\u5fc5\u9009\u9879<\/li>\n<li>redirect_uri\uff1a\u8868\u793a\u91cd\u5b9a\u5411URI\uff0c\u53ef\u9009\u9879<\/li>\n<li>scope\uff1a\u8868\u793a\u7533\u8bf7\u7684\u6743\u9650\u8303\u56f4\uff0c\u53ef\u9009\u9879<\/li>\n<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>\n<\/ul>\n<p>\u4e0b\u9762\u662f\u4e00\u4e2a\u4f8b\u5b50\u3002<\/p>\n<blockquote>\n<pre class=\" language-http\"><code class=\" language-http\">\r\nGET \/authorize?response_type=code&amp;client_id=s6BhdRkqt3&amp;state=xyz\r\n        &amp;redirect_uri=https%3A%2F%2Fclient%2Eexample%2Ecom%2Fcb HTTP\/1.1\r\n<span class=\"token keyword\">Host:<\/span> server.example.com\r\n\r\n<\/code><\/pre>\n<\/blockquote>\n<p>C\u6b65\u9aa4\u4e2d\uff0c\u670d\u52a1\u5668\u56de\u5e94\u5ba2\u6237\u7aef\u7684URI\uff0c\u5305\u542b\u4ee5\u4e0b\u53c2\u6570\uff1a<\/p>\n<ul>\n<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>\n<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>\n<\/ul>\n<p>\u4e0b\u9762\u662f\u4e00\u4e2a\u4f8b\u5b50\u3002<\/p>\n<blockquote>\n<pre class=\" language-http\"><code class=\" language-http\">\r\nHTTP\/1.1 302 Found\r\n<span class=\"token keyword\">Location:<\/span> <a class=\"token url-link\" href=\"https:\/\/client.example.com\/cb\">https:\/\/client.example.com\/cb<\/a>?code=SplxlOBeZQQYbYS6WxSbIA\r\n          &amp;state=xyz\r\n\r\n<\/code><\/pre>\n<\/blockquote>\n<p>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<ul>\n<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>\n<li>code\uff1a\u8868\u793a\u4e0a\u4e00\u6b65\u83b7\u5f97\u7684\u6388\u6743\u7801\uff0c\u5fc5\u9009\u9879\u3002<\/li>\n<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>\n<li>client_id\uff1a\u8868\u793a\u5ba2\u6237\u7aefID\uff0c\u5fc5\u9009\u9879\u3002<\/li>\n<\/ul>\n<p>\u4e0b\u9762\u662f\u4e00\u4e2a\u4f8b\u5b50\u3002<\/p>\n<blockquote>\n<pre class=\" language-http\"><code class=\" language-http\">\r\nPOST \/token HTTP\/1.1\r\n<span class=\"token keyword\">Host:<\/span> server.example.com\r\n<span class=\"token keyword\">Authorization:<\/span> Basic czZCaGRSa3F0MzpnWDFmQmF0M2JW\r\n<span class=\"token keyword\">Content-Type:<\/span> application\/x-www-form-urlencoded\r\n\r\ngrant_type=authorization_code&amp;code=SplxlOBeZQQYbYS6WxSbIA\r\n&amp;redirect_uri=https%3A%2F%2Fclient%2Eexample%2Ecom%2Fcb\r\n\r\n<\/code><\/pre>\n<\/blockquote>\n<p>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<ul>\n<li>access_token\uff1a\u8868\u793a\u8bbf\u95ee\u4ee4\u724c\uff0c\u5fc5\u9009\u9879\u3002<\/li>\n<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>\n<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>\n<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>\n<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>\n<\/ul>\n<p>\u4e0b\u9762\u662f\u4e00\u4e2a\u4f8b\u5b50\u3002<\/p>\n<blockquote>\n<pre class=\" language-http\"><code class=\" language-http\">\r\n     HTTP\/1.1 200 OK\r\n     Content-Type: application\/json;charset=UTF-8\r\n     Cache-Control: no-store\r\n     Pragma: no-cache<span class=\"token application\/json\">\r\n\r\n     <span class=\"token punctuation\">{<\/span>\r\n       <span class=\"token string\">\"access_token\"<\/span><span class=\"token punctuation\">:<\/span><span class=\"token string\">\"2YotnFZFEjr1zCsicMWpAA\"<\/span><span class=\"token punctuation\">,<\/span>\r\n       <span class=\"token string\">\"token_type\"<\/span><span class=\"token punctuation\">:<\/span><span class=\"token string\">\"example\"<\/span><span class=\"token punctuation\">,<\/span>\r\n       <span class=\"token string\">\"expires_in\"<\/span><span class=\"token punctuation\">:<\/span><span class=\"token number\">3600<\/span><span class=\"token punctuation\">,<\/span>\r\n       <span class=\"token string\">\"refresh_token\"<\/span><span class=\"token punctuation\">:<\/span><span class=\"token string\">\"tGzv3JOkF0XG5Qx2TlKWIA\"<\/span><span class=\"token punctuation\">,<\/span>\r\n       <span class=\"token string\">\"example_parameter\"<\/span><span class=\"token punctuation\">:<\/span><span class=\"token string\">\"example_value\"<\/span>\r\n     <span class=\"token punctuation\">}<\/span>\r\n\r\n<\/span><\/code><\/pre>\n<\/blockquote>\n<p>\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<h2>\u4e03\u3001\u7b80\u5316\u6a21\u5f0f<\/h2>\n<p>\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<p><img decoding=\"async\" title=\"\" src=\"http:\/\/image.beekka.com\/blog\/2014\/bg2014051205.png\" alt=\"\u7b80\u5316\u6a21\u5f0f\" \/><\/p>\n<p>\u5b83\u7684\u6b65\u9aa4\u5982\u4e0b\uff1a<\/p>\n<blockquote><p>\uff08A\uff09\u5ba2\u6237\u7aef\u5c06\u7528\u6237\u5bfc\u5411\u8ba4\u8bc1\u670d\u52a1\u5668\u3002<\/p>\n<p>\uff08B\uff09\u7528\u6237\u51b3\u5b9a\u662f\u5426\u7ed9\u4e8e\u5ba2\u6237\u7aef\u6388\u6743\u3002<\/p>\n<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>\n<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>\n<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>\n<p>\uff08F\uff09\u6d4f\u89c8\u5668\u6267\u884c\u4e0a\u4e00\u6b65\u83b7\u5f97\u7684\u811a\u672c\uff0c\u63d0\u53d6\u51fa\u4ee4\u724c\u3002<\/p>\n<p>\uff08G\uff09\u6d4f\u89c8\u5668\u5c06\u4ee4\u724c\u53d1\u7ed9\u5ba2\u6237\u7aef\u3002<\/p><\/blockquote>\n<p>\u4e0b\u9762\u662f\u4e0a\u9762\u8fd9\u4e9b\u6b65\u9aa4\u6240\u9700\u8981\u7684\u53c2\u6570\u3002<\/p>\n<p>A\u6b65\u9aa4\u4e2d\uff0c\u5ba2\u6237\u7aef\u53d1\u51fa\u7684HTTP\u8bf7\u6c42\uff0c\u5305\u542b\u4ee5\u4e0b\u53c2\u6570\uff1a<\/p>\n<ul>\n<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>\n<li>client_id\uff1a\u8868\u793a\u5ba2\u6237\u7aef\u7684ID\uff0c\u5fc5\u9009\u9879\u3002<\/li>\n<li>redirect_uri\uff1a\u8868\u793a\u91cd\u5b9a\u5411\u7684URI\uff0c\u53ef\u9009\u9879\u3002<\/li>\n<li>scope\uff1a\u8868\u793a\u6743\u9650\u8303\u56f4\uff0c\u53ef\u9009\u9879\u3002<\/li>\n<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>\n<\/ul>\n<p>\u4e0b\u9762\u662f\u4e00\u4e2a\u4f8b\u5b50\u3002<\/p>\n<blockquote>\n<pre class=\" language-http\"><code class=\" language-http\">\r\n    GET \/authorize?response_type=token&amp;client_id=s6BhdRkqt3&amp;state=xyz\r\n        &amp;redirect_uri=https%3A%2F%2Fclient%2Eexample%2Ecom%2Fcb HTTP\/1.1\r\n    Host: server.example.com\r\n\r\n<\/code><\/pre>\n<\/blockquote>\n<p>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<ul>\n<li>access_token\uff1a\u8868\u793a\u8bbf\u95ee\u4ee4\u724c\uff0c\u5fc5\u9009\u9879\u3002<\/li>\n<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>\n<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>\n<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>\n<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>\n<\/ul>\n<p>\u4e0b\u9762\u662f\u4e00\u4e2a\u4f8b\u5b50\u3002<\/p>\n<blockquote>\n<pre class=\" language-http\"><code class=\" language-http\">\r\n     HTTP\/1.1 302 Found\r\n     Location: <a class=\"token url-link\" href=\"http:\/\/example.com\/cb\">http:\/\/example.com\/cb<\/a>#access_token=2YotnFZFEjr1zCsicMWpAA\r\n               &amp;state=xyz&amp;token_type=example&amp;expires_in=3600\r\n\r\n<\/code><\/pre>\n<\/blockquote>\n<p>\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<p>\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<h2>\u516b\u3001\u5bc6\u7801\u6a21\u5f0f<\/h2>\n<p>\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<p>\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<p><img decoding=\"async\" title=\"\" src=\"http:\/\/image.beekka.com\/blog\/2014\/bg2014051206.png\" alt=\"\u5bc6\u7801\u6a21\u5f0f\" \/><\/p>\n<p>\u5b83\u7684\u6b65\u9aa4\u5982\u4e0b\uff1a<\/p>\n<blockquote><p>\uff08A\uff09\u7528\u6237\u5411\u5ba2\u6237\u7aef\u63d0\u4f9b\u7528\u6237\u540d\u548c\u5bc6\u7801\u3002<\/p>\n<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>\n<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<p>B\u6b65\u9aa4\u4e2d\uff0c\u5ba2\u6237\u7aef\u53d1\u51fa\u7684HTTP\u8bf7\u6c42\uff0c\u5305\u542b\u4ee5\u4e0b\u53c2\u6570\uff1a<\/p>\n<ul>\n<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>\n<li>username\uff1a\u8868\u793a\u7528\u6237\u540d\uff0c\u5fc5\u9009\u9879\u3002<\/li>\n<li>password\uff1a\u8868\u793a\u7528\u6237\u7684\u5bc6\u7801\uff0c\u5fc5\u9009\u9879\u3002<\/li>\n<li>scope\uff1a\u8868\u793a\u6743\u9650\u8303\u56f4\uff0c\u53ef\u9009\u9879\u3002<\/li>\n<\/ul>\n<p>\u4e0b\u9762\u662f\u4e00\u4e2a\u4f8b\u5b50\u3002<\/p>\n<blockquote>\n<pre class=\" language-http\"><code class=\" language-http\">\r\n     POST \/token HTTP\/1.1\r\n     Host: server.example.com\r\n     Authorization: Basic czZCaGRSa3F0MzpnWDFmQmF0M2JW\r\n     Content-Type: application\/x-www-form-urlencoded\r\n\r\n     grant_type=password&amp;username=johndoe&amp;password=A3ddj3w\r\n\r\n<\/code><\/pre>\n<\/blockquote>\n<p>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<blockquote>\n<pre class=\" language-http\"><code class=\" language-http\">\r\n     HTTP\/1.1 200 OK\r\n     Content-Type: application\/json;charset=UTF-8\r\n     Cache-Control: no-store\r\n     Pragma: no-cache<span class=\"token application\/json\">\r\n\r\n     <span class=\"token punctuation\">{<\/span>\r\n       <span class=\"token string\">\"access_token\"<\/span><span class=\"token punctuation\">:<\/span><span class=\"token string\">\"2YotnFZFEjr1zCsicMWpAA\"<\/span><span class=\"token punctuation\">,<\/span>\r\n       <span class=\"token string\">\"token_type\"<\/span><span class=\"token punctuation\">:<\/span><span class=\"token string\">\"example\"<\/span><span class=\"token punctuation\">,<\/span>\r\n       <span class=\"token string\">\"expires_in\"<\/span><span class=\"token punctuation\">:<\/span><span class=\"token number\">3600<\/span><span class=\"token punctuation\">,<\/span>\r\n       <span class=\"token string\">\"refresh_token\"<\/span><span class=\"token punctuation\">:<\/span><span class=\"token string\">\"tGzv3JOkF0XG5Qx2TlKWIA\"<\/span><span class=\"token punctuation\">,<\/span>\r\n       <span class=\"token string\">\"example_parameter\"<\/span><span class=\"token punctuation\">:<\/span><span class=\"token string\">\"example_value\"<\/span>\r\n     <span class=\"token punctuation\">}<\/span>\r\n\r\n<\/span><\/code><\/pre>\n<\/blockquote>\n<p>\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<p>\u6574\u4e2a\u8fc7\u7a0b\u4e2d\uff0c\u5ba2\u6237\u7aef\u4e0d\u5f97\u4fdd\u5b58\u7528\u6237\u7684\u5bc6\u7801\u3002<\/p>\n<h2>\u4e5d\u3001\u5ba2\u6237\u7aef\u6a21\u5f0f<\/h2>\n<p>\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<p><img decoding=\"async\" title=\"\" src=\"http:\/\/image.beekka.com\/blog\/2014\/bg2014051207.png\" alt=\"\u5ba2\u6237\u7aef\u6a21\u5f0f\" \/><\/p>\n<p>\u5b83\u7684\u6b65\u9aa4\u5982\u4e0b\uff1a<\/p>\n<blockquote><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>\n<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<p>A\u6b65\u9aa4\u4e2d\uff0c\u5ba2\u6237\u7aef\u53d1\u51fa\u7684HTTP\u8bf7\u6c42\uff0c\u5305\u542b\u4ee5\u4e0b\u53c2\u6570\uff1a<\/p>\n<ul>\n<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>\n<li>scope\uff1a\u8868\u793a\u6743\u9650\u8303\u56f4\uff0c\u53ef\u9009\u9879\u3002<\/li>\n<\/ul>\n<blockquote>\n<pre class=\" language-http\"><code class=\" language-http\">\r\n     POST \/token HTTP\/1.1\r\n     Host: server.example.com\r\n     Authorization: Basic czZCaGRSa3F0MzpnWDFmQmF0M2JW\r\n     Content-Type: application\/x-www-form-urlencoded\r\n\r\n     grant_type=client_credentials\r\n\r\n<\/code><\/pre>\n<\/blockquote>\n<p>\u8ba4\u8bc1\u670d\u52a1\u5668\u5fc5\u987b\u4ee5\u67d0\u79cd\u65b9\u5f0f\uff0c\u9a8c\u8bc1\u5ba2\u6237\u7aef\u8eab\u4efd\u3002<\/p>\n<p>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<blockquote>\n<pre class=\" language-http\"><code class=\" language-http\">\r\n     HTTP\/1.1 200 OK\r\n     Content-Type: application\/json;charset=UTF-8\r\n     Cache-Control: no-store\r\n     Pragma: no-cache<span class=\"token application\/json\">\r\n\r\n     <span class=\"token punctuation\">{<\/span>\r\n       <span class=\"token string\">\"access_token\"<\/span><span class=\"token punctuation\">:<\/span><span class=\"token string\">\"2YotnFZFEjr1zCsicMWpAA\"<\/span><span class=\"token punctuation\">,<\/span>\r\n       <span class=\"token string\">\"token_type\"<\/span><span class=\"token punctuation\">:<\/span><span class=\"token string\">\"example\"<\/span><span class=\"token punctuation\">,<\/span>\r\n       <span class=\"token string\">\"expires_in\"<\/span><span class=\"token punctuation\">:<\/span><span class=\"token number\">3600<\/span><span class=\"token punctuation\">,<\/span>\r\n       <span class=\"token string\">\"example_parameter\"<\/span><span class=\"token punctuation\">:<\/span><span class=\"token string\">\"example_value\"<\/span>\r\n     <span class=\"token punctuation\">}<\/span>\r\n\r\n<\/span><\/code><\/pre>\n<\/blockquote>\n<p>\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<h2>\u5341\u3001\u66f4\u65b0\u4ee4\u724c<\/h2>\n<p>\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<p>\u5ba2\u6237\u7aef\u53d1\u51fa\u66f4\u65b0\u4ee4\u724c\u7684HTTP\u8bf7\u6c42\uff0c\u5305\u542b\u4ee5\u4e0b\u53c2\u6570\uff1a<\/p>\n<ul>\n<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>\n<li>refresh_token\uff1a\u8868\u793a\u65e9\u524d\u6536\u5230\u7684\u66f4\u65b0\u4ee4\u724c\uff0c\u5fc5\u9009\u9879\u3002<\/li>\n<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>\n<\/ul>\n<p>\u4e0b\u9762\u662f\u4e00\u4e2a\u4f8b\u5b50\u3002<\/p>\n<blockquote>\n<pre class=\" language-http\"><code class=\" language-http\">\r\n     POST \/token HTTP\/1.1\r\n     Host: server.example.com\r\n     Authorization: Basic czZCaGRSa3F0MzpnWDFmQmF0M2JW\r\n     Content-Type: application\/x-www-form-urlencoded\r\n\r\n     grant_type=refresh_token&amp;refresh_token=tGzv3JOkF0XG5Qx2TlKWIA\r\n\r\n<\/code><\/pre>\n<\/blockquote>\n<p>\uff08\u5b8c\uff09<\/p>\n<p>\u539f\u6587\u94fe\u63a5\uff1ahttp:\/\/www.ruanyifeng.com\/blog\/2014\/05\/oauth_2_0.html<\/p>\n","protected":false},"excerpt":{"rendered":"<p>OAuth\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 &hellip; <a href=\"http:\/\/www.homconnect.cn\/?p=142\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">\u201c\u7406\u89e3OAuth 2.0\u201d<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[54],"tags":[55],"_links":{"self":[{"href":"http:\/\/www.homconnect.cn\/index.php?rest_route=\/wp\/v2\/posts\/142"}],"collection":[{"href":"http:\/\/www.homconnect.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.homconnect.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.homconnect.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.homconnect.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=142"}],"version-history":[{"count":1,"href":"http:\/\/www.homconnect.cn\/index.php?rest_route=\/wp\/v2\/posts\/142\/revisions"}],"predecessor-version":[{"id":143,"href":"http:\/\/www.homconnect.cn\/index.php?rest_route=\/wp\/v2\/posts\/142\/revisions\/143"}],"wp:attachment":[{"href":"http:\/\/www.homconnect.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=142"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.homconnect.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=142"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.homconnect.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=142"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}