{"id":217517,"date":"2020-12-05T10:59:49","date_gmt":"2020-12-05T02:59:49","guid":{"rendered":"http:\/\/4563.org\/?p=217517"},"modified":"2020-12-06T07:33:33","modified_gmt":"2020-12-05T23:33:33","slug":"%e5%85%85%e7%94%b5%e5%85%85%e7%94%b5%ef%bc%8c-oauth2-0-%e7%9a%84%e5%9b%9b%e7%a7%8d%e6%8e%88%e6%9d%83%e6%96%b9%e5%bc%8f","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=217517","title":{"rendered":"\u5145\u7535\u5145\u7535\uff0c OAuth2.0 \u7684\u56db\u79cd\u6388\u6743\u65b9\u5f0f"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  \u5145\u7535\u5145\u7535\uff0c OAuth2.0 \u7684\u56db\u79cd\u6388\u6743\u65b9\u5f0f               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : xiaofu1991 <\/span>  <span><i><\/i> 2<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<h2>\u4e00\u3001OAuth2.0 \u4e3a\u4f55\u7269<\/h2>\n<p><code>OAuth<\/code> \u7b80\u5355\u7406\u89e3\u5c31\u662f\u4e00\u79cd\u6388\u6743\u673a\u5236\uff0c\u5b83\u662f\u5728\u5ba2\u6237\u7aef\u548c\u8d44\u6e90\u6240\u6709\u8005\u4e4b\u95f4\u7684\u6388\u6743\u5c42\uff0c\u7528\u6765\u5206\u79bb\u4e24\u79cd\u4e0d\u540c\u7684\u89d2\u8272\u3002\u5728\u8d44\u6e90\u6240\u6709\u8005\u540c\u610f\u5e76\u5411\u5ba2\u6237\u7aef\u9881\u53d1\u4ee4\u724c\u540e\uff0c\u5ba2\u6237\u7aef\u643a\u5e26\u4ee4\u724c\u53ef\u4ee5\u8bbf\u95ee\u8d44\u6e90\u6240\u6709\u8005\u7684\u8d44\u6e90\u3002<\/p>\n<p><code>OAuth2.0<\/code> \u662f<code>OAuth<\/code> \u534f\u8bae\u7684\u4e00\u4e2a\u7248\u672c\uff0c\u6709<code>2.0<\/code>\u7248\u672c\u90a3\u5c31\u6709<code>1.0<\/code>\u7248\u672c\uff0c\u6709\u610f\u601d\u7684\u662f<code>OAuth2.0<\/code> \u5374\u4e0d\u5411\u4e0b\u517c\u5bb9<code>OAuth1.0<\/code> \uff0c\u76f8\u5f53\u4e8e\u5e9f\u5f03\u4e86<code>1.0<\/code>\u7248\u672c\u3002<\/p>\n<p><strong>\u4e3e\u4e2a\u5c0f\u6817\u5b50\u89e3\u91ca\u4e00\u4e0b\u4ec0\u4e48\u662f OAuth \u6388\u6743\uff1f<\/strong><\/p>\n<p>\u5728\u5bb6\u809d\u6587\u7ae0\u997f\u4e86\u5b9a\u4e86\u4e00\u4e2a\u5916\u5356\uff0c\u5916\u5356\u5c0f\u54e5 30 \u79d2\u706b\u901f\u5230\u8fbe\u4e86\u6211\u5bb6\u4e0b\uff0c\u5948\u4f55\u6709\u95e8\u7981\u8fdb\u4e0d\u6765\uff0c\u53ef\u4ee5\u8f93\u5165\u5bc6\u7801\u8fdb\u5165\uff0c\u4f46\u51fa\u4e8e\u5b89\u5168\u7684\u8003\u8651\u6211\u5e76\u4e0d\u60f3\u544a\u8bc9\u4ed6\u5bc6\u7801\u3002<\/p>\n<p>\u6b64\u65f6\u5916\u5356\u5c0f\u54e5\u770b\u5230\u95e8\u7981\u6709\u4e00\u4e2a\u9ad8\u7ea7\u6309\u94ae\u201c<code>\u4e00\u952e\u83b7\u53d6\u6388\u6743<\/code>\u201d\uff0c\u53ea\u8981\u6211\u8fd9\u8fb9\u540c\u610f\uff0c\u4ed6\u4f1a\u83b7\u53d6\u5230\u4e00\u4e2a\u6709\u6548\u671f 2 \u5c0f\u65f6\u7684\u4ee4\u724c\uff08<code>token<\/code>\uff09\u6b63\u5e38\u51fa\u5165\u3002<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" referrerpolicy=\"no-referrer\" rel=\"noreferrer\" src=\"http:\/\/4563.org\/wp-content\/uploads\/2020\/12\/20200706163230102.pngpic_center.png\" alt=\"\u5145\u7535\u5145\u7535\uff0c OAuth2.0 \u7684\u56db\u79cd\u6388\u6743\u65b9\u5f0f\" \/><\/p>\n<p>\u4ee4\u724c\uff08<code>token<\/code>\uff09\u548c <code>\u5bc6\u7801<\/code> \u7684\u4f5c\u7528\u867d\u7136\u76f8\u4f3c\u90fd\u53ef\u4ee5\u8fdb\u5165\u7cfb\u7edf\uff0c\u4f46\u8fd8\u6709\u70b9\u4e0d\u540c\u3002<code>token<\/code> \u62e5\u6709\u6743\u9650\u8303\u56f4\uff0c\u6709\u65f6\u6548\u6027\u7684\uff0c\u5230\u671f\u81ea\u52a8\u5931\u6548\uff0c\u800c\u4e14\u65e0\u6548\u4fee\u6539\u3002<\/p>\n<h2>\u4e8c\u3001OAuth2.0 \u6388\u6743\u65b9\u5f0f<\/h2>\n<p><code>OAuth2.0<\/code> \u7684\u6388\u6743\u7b80\u5355\u7406\u89e3\u5176\u5b9e\u5c31\u662f\u83b7\u53d6\u4ee4\u724c\uff08<code>token<\/code>\uff09\u7684\u8fc7\u7a0b\uff0c<code>OAuth<\/code> \u534f\u8bae\u5b9a\u4e49\u4e86\u56db\u79cd\u83b7\u5f97\u4ee4\u724c\u7684\u6388\u6743\u65b9\u5f0f\uff08<code>authorization grant<\/code> \uff09\u5982\u4e0b\uff1a<\/p>\n<ul>\n<li>\u6388\u6743\u7801\uff08<code>authorization-code<\/code>\uff09<\/li>\n<li>\u9690\u85cf\u5f0f\uff08<code>implicit<\/code>\uff09<\/li>\n<li>\u5bc6\u7801\u5f0f\uff08<code>password<\/code>\uff09\uff1a<\/li>\n<li>\u5ba2\u6237\u7aef\u51ed\u8bc1\uff08<code>client credentials<\/code>\uff09<\/li>\n<\/ul>\n<p>\u4f46\u503c\u5f97\u6ce8\u610f\u7684\u662f\uff0c\u4e0d\u7ba1\u6211\u4eec\u4f7f\u7528\u54ea\u4e00\u79cd\u6388\u6743\u65b9\u5f0f\uff0c\u5728\u4e09\u65b9\u5e94\u7528\u7533\u8bf7\u4ee4\u724c\u4e4b\u524d\uff0c\u90fd\u5fc5\u987b\u5728\u7cfb\u7edf\u4e2d\u53bb\u7533\u8bf7\u8eab\u4efd\u552f\u4e00\u6807\u8bc6\uff1a\u5ba2\u6237\u7aef ID \uff08<code>client ID<\/code>\uff09\u548c \u5ba2\u6237\u7aef\u5bc6\u94a5\uff08<code>client secret<\/code>\uff09\u3002\u8fd9\u6837\u505a\u53ef\u4ee5\u4fdd\u8bc1 <code>token<\/code> \u4e0d\u88ab\u6076\u610f\u4f7f\u7528\u3002<\/p>\n<p>\u4e0b\u9762\u6211\u4eec\u4f1a\u5206\u6790\u6bcf\u79cd\u6388\u6743\u65b9\u5f0f\u7684\u539f\u7406\uff0c\u5728\u8fdb\u5165\u6b63\u9898\u524d\uff0c\u5148\u4e86\u89e3 <code>OAuth2.0<\/code> \u6388\u6743\u8fc7\u7a0b\u4e2d\u51e0\u4e2a\u91cd\u8981\u7684\u53c2\u6570\uff1a<\/p>\n<ul>\n<li><code>response_type<\/code>\uff1acode \u8868\u793a\u8981\u6c42\u8fd4\u56de\u6388\u6743\u7801\uff0ctoken \u8868\u793a\u76f4\u63a5\u8fd4\u56de\u4ee4\u724c<\/li>\n<li><code>client_id<\/code>\uff1a\u5ba2\u6237\u7aef\u8eab\u4efd\u6807\u8bc6<\/li>\n<li><code>client_secret<\/code>\uff1a\u5ba2\u6237\u7aef\u5bc6\u94a5<\/li>\n<li><code>redirect_uri<\/code>\uff1a\u91cd\u5b9a\u5411\u5730\u5740<\/li>\n<li><code>scope<\/code>\uff1a\u8868\u793a\u6388\u6743\u7684\u8303\u56f4\uff0c<code>read<\/code>\u53ea\u8bfb\u6743\u9650\uff0c<code>all<\/code>\u8bfb\u5199\u6743\u9650<\/li>\n<li><code>grant_type<\/code>\uff1a\u8868\u793a\u6388\u6743\u7684\u65b9\u5f0f\uff0c<code>AUTHORIZATION_CODE<\/code>\uff08\u6388\u6743\u7801\uff09\u3001<code>password<\/code>\uff08\u5bc6\u7801\uff09\u3001<code>client_credentials<\/code>\uff08\u51ed\u8bc1\u5f0f\uff09\u3001<code>refresh_token<\/code> \u66f4\u65b0\u4ee4\u724c<\/li>\n<li><code>state<\/code>\uff1a\u5e94\u7528\u7a0b\u5e8f\u4f20\u9012\u7684\u4e00\u4e2a\u968f\u673a\u6570\uff0c\u7528\u6765\u9632\u6b62<code>CSRF<\/code>\u653b\u51fb\u3002<\/li>\n<\/ul>\n<h3>1 \u3001\u6388\u6743\u7801<\/h3>\n<p><code>OAuth2.0<\/code>\u56db\u79cd\u6388\u6743\u4e2d\u6388\u6743\u7801\u65b9\u5f0f\u662f\u6700\u4e3a\u590d\u6742\uff0c\u4f46\u4e5f\u662f\u5b89\u5168\u7cfb\u6570\u6700\u9ad8\u7684\uff0c\u6bd4\u8f83\u5e38\u7528\u7684\u4e00\u79cd\u65b9\u5f0f\u3002\u8fd9\u79cd\u65b9\u5f0f\u9002\u7528\u4e8e\u517c\u5177\u524d\u540e\u7aef\u7684<code>Web<\/code>\u9879\u76ee\uff0c\u56e0\u4e3a\u6709\u4e9b\u9879\u76ee\u53ea\u6709\u540e\u7aef\u6216\u53ea\u6709\u524d\u7aef\uff0c\u5e76\u4e0d\u9002\u7528\u6388\u6743\u7801\u6a21\u5f0f\u3002<\/p>\n<p>\u4e0b\u56fe\u6211\u4eec\u4ee5\u7528<code>WX<\/code>\u767b\u5f55\u6398\u91d1\u4e3a\u4f8b\uff0c\u8be6\u7ec6\u770b\u4e00\u4e0b\u6388\u6743\u7801\u65b9\u5f0f\u7684\u6574\u4f53\u6d41\u7a0b\u3002<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" referrerpolicy=\"no-referrer\" rel=\"noreferrer\" src=\"http:\/\/4563.org\/wp-content\/uploads\/2020\/12\/20200706172813832.pngpic_center.png\" alt=\"\u5145\u7535\u5145\u7535\uff0c OAuth2.0 \u7684\u56db\u79cd\u6388\u6743\u65b9\u5f0f\" \/><\/p>\n<p>\u7528\u6237\u9009\u62e9<code>WX<\/code>\u767b\u5f55\u6398\u91d1\uff0c\u6398\u91d1\u4f1a\u5411<code>WX<\/code>\u53d1\u8d77\u6388\u6743\u8bf7\u6c42\uff0c\u63a5\u4e0b\u6765 <code>WX<\/code>\u8be2\u95ee\u7528\u6237\u662f\u5426\u540c\u610f\u6388\u6743\uff08\u5e38\u89c1\u7684\u5f39\u7a97\u6388\u6743\uff09\u3002<code>response_type<\/code> \u4e3a <code>code<\/code> \u8981\u6c42\u8fd4\u56de\u6388\u6743\u7801\uff0c<code>scope<\/code> \u53c2\u6570\u8868\u793a\u672c\u6b21\u6388\u6743\u8303\u56f4\u4e3a\u53ea\u8bfb\u6743\u9650\uff0c<code>redirect_uri<\/code> \u91cd\u5b9a\u5411\u5730\u5740\u3002<\/p>\n<pre><code>https:\/\/wx.com\/oauth\/authorize?   response_type=code&amp;   client_id=CLIENT_ID&amp;   redirect_uri=http:\/\/juejin.im\/callback&amp;   scope=read <\/code><\/pre>\n<p>\u7528\u6237\u540c\u610f\u6388\u6743\u540e\uff0c<code>WX<\/code> \u6839\u636e <code>redirect_uri<\/code>\u91cd\u5b9a\u5411\u5e76\u5e26\u4e0a\u6388\u6743\u7801\u3002<\/p>\n<pre><code>http:\/\/juejin.im\/callback?code=AUTHORIZATION_CODE <\/code><\/pre>\n<p>\u5f53\u6398\u91d1\u62ff\u5230\u6388\u6743\u7801\uff08 code \uff09\u65f6\uff0c\u5e26\u6388\u6743\u7801\u548c\u5bc6\u5319\u7b49\u53c2\u6570\u5411<code>WX<\/code>\u7533\u8bf7\u4ee4\u724c\u3002<code>grant_type<\/code>\u8868\u793a\u672c\u6b21\u6388\u6743\u4e3a\u6388\u6743\u7801\u65b9\u5f0f <code>authorization_code<\/code> \uff0c\u83b7\u53d6\u4ee4\u724c\u8981\u5e26\u4e0a\u5ba2\u6237\u7aef\u5bc6\u5319 <code>client_secret<\/code>\uff0c\u548c\u4e0a\u4e00\u6b65\u5f97\u5230\u7684\u6388\u6743\u7801 <code>code<\/code>\u3002<\/p>\n<pre><code>https:\/\/wx.com\/oauth\/token?  client_id=CLIENT_ID&amp;  client_secret=CLIENT_SECRET&amp;  grant_type=authorization_code&amp;  code=AUTHORIZATION_CODE&amp;  redirect_uri=http:\/\/juejin.im\/callback <\/code><\/pre>\n<p>\u6700\u540e <code>WX<\/code> \u6536\u5230\u8bf7\u6c42\u540e\u5411 <code>redirect_uri<\/code> \u5730\u5740\u53d1\u9001 <code>JSON<\/code> \u6570\u636e\uff0c\u5176\u4e2d\u7684<code>access_token<\/code> \u5c31\u662f\u4ee4\u724c\u3002<\/p>\n<pre><code> {       \"access_token\":\"ACCESS_TOKEN\",   \"token_type\":\"bearer\",   \"expires_in\":2592000,   \"refresh_token\":\"REFRESH_TOKEN\",   \"scope\":\"read\",   ...... } <\/code><\/pre>\n<h3>2 \u3001\u9690\u85cf\u5f0f<\/h3>\n<p>\u4e0a\u8fb9\u63d0\u5230\u6709\u4e00\u4e9b<code>Web<\/code>\u5e94\u7528\u662f\u6ca1\u6709\u540e\u7aef\u7684\uff0c \u5c5e\u4e8e\u7eaf\u524d\u7aef\u5e94\u7528\uff0c\u65e0\u6cd5\u7528\u4e0a\u8fb9\u7684\u6388\u6743\u7801\u6a21\u5f0f\u3002\u4ee4\u724c\u7684\u7533\u8bf7\u4e0e\u5b58\u50a8\u90fd\u9700\u8981\u5728\u524d\u7aef\u5b8c\u6210\uff0c\u8df3\u8fc7\u4e86\u6388\u6743\u7801\u8fd9\u4e00\u6b65\u3002<\/p>\n<p>\u524d\u7aef\u5e94\u7528\u76f4\u63a5\u83b7\u53d6 <code>token<\/code>\uff0c<code>response_type<\/code> \u8bbe\u7f6e\u4e3a <code>token<\/code>\uff0c\u8981\u6c42\u76f4\u63a5\u8fd4\u56de\u4ee4\u724c\uff0c\u8df3\u8fc7\u6388\u6743\u7801\uff0c<code>WX<\/code>\u6388\u6743\u901a\u8fc7\u540e\u91cd\u5b9a\u5411\u5230\u6307\u5b9a <code>redirect_uri<\/code> \u3002<\/p>\n<pre><code>https:\/\/wx.com\/oauth\/authorize?   response_type=token&amp;   client_id=CLIENT_ID&amp;   redirect_uri=http:\/\/juejin.im\/callback&amp;   scope=read <\/code><\/pre>\n<h3>3 \u3001\u5bc6\u7801\u5f0f<\/h3>\n<p>\u5bc6\u7801\u6a21\u5f0f\u6bd4\u8f83\u597d\u7406\u89e3\uff0c\u7528\u6237\u5728\u6398\u91d1\u76f4\u63a5\u8f93\u5165\u81ea\u5df1\u7684<code>WX<\/code>\u7528\u6237\u540d\u548c\u5bc6\u7801\uff0c\u6398\u91d1\u62ff\u7740\u4fe1\u606f\u76f4\u63a5\u53bb<code>WX<\/code>\u7533\u8bf7\u4ee4\u724c\uff0c\u8bf7\u6c42\u54cd\u5e94\u7684 <code>JSON<\/code>\u7ed3\u679c\u4e2d\u8fd4\u56de <code>token<\/code>\u3002<code>grant_type<\/code> \u4e3a <code>password<\/code> \u8868\u793a\u5bc6\u7801\u5f0f\u6388\u6743\u3002<\/p>\n<pre><code>https:\/\/wx.com\/token?   grant_type=password&amp;   username=USERNAME&amp;   password=PASSWORD&amp;   client_id=CLIENT_ID <\/code><\/pre>\n<p>\u8fd9\u79cd\u6388\u6743\u65b9\u5f0f\u7f3a\u70b9\u662f\u663e\u800c\u6613\u89c1\u7684\uff0c\u975e\u5e38\u7684\u5371\u9669\uff0c\u5982\u679c\u91c7\u53d6\u6b64\u65b9\u5f0f\u6388\u6743\uff0c\u8be5\u5e94\u7528\u4e00\u5b9a\u662f\u53ef\u4ee5\u9ad8\u5ea6\u4fe1\u4efb\u7684\u3002<\/p>\n<h3>4 \u3001\u51ed\u8bc1\u5f0f<\/h3>\n<p>\u51ed\u8bc1\u5f0f\u548c\u5bc6\u7801\u5f0f\u5f88\u76f8\u4f3c\uff0c\u4e3b\u8981\u9002\u7528\u4e8e\u90a3\u4e9b\u6ca1\u6709\u524d\u7aef\u7684\u547d\u4ee4\u884c\u5e94\u7528\uff0c\u53ef\u4ee5\u7528\u6700\u7b80\u5355\u7684\u65b9\u5f0f\u83b7\u53d6\u4ee4\u724c\uff0c\u5728\u8bf7\u6c42\u54cd\u5e94\u7684 <code>JSON<\/code> \u7ed3\u679c\u4e2d\u8fd4\u56de <code>token<\/code>\u3002<\/p>\n<p><code>grant_type<\/code> \u4e3a <code>client_credentials<\/code> \u8868\u793a\u51ed\u8bc1\u5f0f\u6388\u6743\uff0c<code>client_id<\/code> \u548c <code>client_secret<\/code> \u7528\u6765\u8bc6\u522b\u8eab\u4efd\u3002<\/p>\n<pre><code>https:\/\/wx.com\/token?   grant_type=client_credentials&amp;   client_id=CLIENT_ID&amp;   client_secret=CLIENT_SECRET <\/code><\/pre>\n<h2>\u4e09\u3001\u4ee4\u724c\u7684\u4f7f\u7528\u4e0e\u66f4\u65b0<\/h2>\n<h3>1 \u3001\u4ee4\u724c\u600e\u4e48\u7528\uff1f<\/h3>\n<p>\u62ff\u5230\u4ee4\u724c\u53ef\u4ee5\u8c03\u7528 <code>WX<\/code> API \u8bf7\u6c42\u6570\u636e\u4e86\uff0c\u90a3\u4ee4\u724c\u8be5\u600e\u4e48\u7528\u5462\uff1f<\/p>\n<p>\u6bcf\u4e2a\u5230\u8fbe<code>WX<\/code>\u7684\u8bf7\u6c42\u90fd\u5fc5\u987b\u5e26\u4e0a <code>token<\/code>\uff0c\u5c06 <code>token<\/code> \u653e\u5728 <code>http<\/code> \u8bf7\u6c42\u5934\u90e8\u7684\u4e00\u4e2a<code>Authorization<\/code>\u5b57\u6bb5\u91cc\u3002<\/p>\n<p>\u5982\u679c\u4f7f\u7528<code>postman<\/code> \u6a21\u62df\u8bf7\u6c42\uff0c\u8981\u5728<code>Authorization<\/code> -&gt; <code>Bearer Token<\/code> \u653e\u5165 <code>token<\/code>\uff0c<strong>\u6ce8\u610f<\/strong>\uff1a\u4f4e\u7248\u672c<code>postman<\/code> \u6ca1\u6709\u8fd9\u4e2a\u9009\u9879\u3002<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" referrerpolicy=\"no-referrer\" rel=\"noreferrer\" src=\"http:\/\/4563.org\/wp-content\/uploads\/2020\/12\/20201205_5fcc189591066.png\" alt=\"\u5145\u7535\u5145\u7535\uff0c OAuth2.0 \u7684\u56db\u79cd\u6388\u6743\u65b9\u5f0f\" \/><\/p>\n<h3>2 \u3001\u4ee4\u724c\u8fc7\u671f\u600e\u4e48\u529e\uff1f<\/h3>\n<p><code>token<\/code>\u662f\u6709\u65f6\u6548\u6027\u7684\uff0c\u4e00\u65e6\u8fc7\u671f\u5c31\u9700\u8981\u91cd\u65b0\u83b7\u53d6\uff0c\u4f46\u662f\u91cd\u8d70\u4e00\u904d\u6388\u6743\u6d41\u7a0b\uff0c\u4e0d\u4ec5\u9ebb\u70e6\u800c\u4e14\u7528\u6237\u4f53\u9a8c\u4e5f\u4e0d\u597d\uff0c\u90a3\u5982\u4f55\u8ba9\u66f4\u65b0\u4ee4\u724c\u53d8\u5f97\u4f18\u96c5\u4e00\u70b9\u5462\uff1f<\/p>\n<p>\u4e00\u822c\u5728\u9881\u53d1\u4ee4\u724c\u65f6\u4f1a\u4e00\u6b21\u53d1\u4e24\u4e2a\u4ee4\u724c\uff0c\u4e00\u4e2a\u4ee4\u724c\u7528\u6765\u8bf7\u6c42<code>API<\/code>\uff0c\u53e6\u4e00\u4e2a\u8d1f\u8d23\u66f4\u65b0\u4ee4\u724c <code>refresh_token<\/code>\u3002<code>grant_type<\/code> \u4e3a <code>refresh_token<\/code> \u8bf7\u6c42\u4e3a\u66f4\u65b0\u4ee4\u724c\uff0c\u53c2\u6570 <code>refresh_token<\/code> \u662f\u7528\u4e8e\u66f4\u65b0\u4ee4\u724c\u7684\u4ee4\u724c\u3002<\/p>\n<pre><code>https:\/\/wx.com\/oauth\/token?   grant_type=refresh_token&amp;   client_id=CLIENT_ID&amp;   client_secret=CLIENT_SECRET&amp;   refresh_token=REFRESH_TOKEN <\/code><\/pre>\n<h2>\u603b\u7ed3<\/h2>\n<p><code>OAuth2.0<\/code> \u6388\u6743\u5176\u5b9e\u5e76\u4e0d\u662f\u5f88\u96be\uff0c\u53ea\u4e0d\u8fc7\u6388\u6743\u6d41\u7a0b\u7a0d\u663e\u9ebb\u70e6\uff0c\u903b\u8f91\u6709\u4e9b\u7ed5\uff0c<code>OAuth2.0<\/code>\u5b83\u662f\u9762\u8bd5\u7ecf\u5e38\u4f1a\u88ab\u95ee\u5230\u7684\u77e5\u8bc6\u70b9\uff0c\u8fd8\u662f\u5e94\u8be5\u591a\u4e86\u89e3\u4e00\u4e0b\u3002\u4e0b\u4e00\u7bc7\u5b9e\u6218 <code>OAuth2.0<\/code>\u56db\u79cd\u6388\u6743\uff0c\u656c\u8bf7\u671f\u5f85\uff0c\u6b22\u8fce\u5173\u6ce8\u54e6~<\/p>\n<p>\u4e0a\u5468\u6211\u7684\u81ea\u7814\u5f00\u6e90\u9879\u76ee\u5f00\u59cb\u7834\u571f\u52a8\u5de5\u4e86\uff0c\u300a\u5f00\u6e90\u9879\u76ee\u8fc8\u51fa\u7b2c\u4e00\u6b65\uff0c10 \u9009 1 \uff1f\u9875\u9762\u6a21\u677f\u6210\u4e86\u7b2c\u4e00\u4e2a\u7eca\u811a\u77f3 \u300b \uff0c\u5bc6\u8c0b\u5f88\u4e45\u624d\u4ed8\u8bf8\u884c\u52a8\uff0c\u505a\u8fd9\u4e2a\u7684\u521d\u8877\u5c31\u662f\u4e0d\u60f3\u8ba9\u81ea\u5df1\u592a\u5b89\u7a33\uff0c<strong>\u6280\u672f\u8fd9\u6761\u8def\u4e0d\u8fdb\u6b65\u5c31\u7b49\u4e8e\u540e\u9000<\/strong>\uff0c\u5fc5\u987b\u8981\u903c\u7740\u81ea\u5df1\u5b66\u4e60\u3002<\/p>\n<p>\u9879\u76ee\u504f\u5411\u4e8e\u6280\u672f\u5b9e\u8df5\uff0c\u56e0\u6b64\u4e0d\u4f1a\u505a\u592a\u591a\u7684\u4e1a\u52a1\u5806\u780c\uff0c\u4e1a\u52a1\u4ee3\u7801\u8fd8\u662f\u5728\u516c\u53f8\u5b66\u4e60\u6bd4\u8f83\u597d\u3002\u73b0\u5728\u6b63\u5728\u505a\u6280\u672f\u7684\u9009\u578b\u4e0e\u50a8\u5907\uff0c\u50cf\u6bd4\u8f83\u4e3b\u6d41\u7684\uff0c<code>\u9879\u76ee\u524d\u540e\u7aef\u5206\u79bb<\/code>\u3001<code>\u5fae\u670d\u52a1<\/code>\u3001<code>Springboot<\/code>\u3001<code>Springcloud<\/code> \u7b49\u90fd\u4f1a\u5e94\u7528\u5230\u9879\u76ee\u4e2d\uff0c\u5176\u5b9e\u5f88\u591a\u6280\u672f\u6211\u4e5f\u4e0d\u4f1a\uff0c\u4e5f\u662f\u5728\u53cd\u590d\u7684\u67e5\u9605\u8d44\u6599\u6c42\u8bc1\uff0c\u63a2\u7d22\u7684\u8fc7\u7a0b\u6280\u672f\u63d0\u5347\u771f\u7684\u8981\u6bd4\u5de5\u4f5c\u4e2d\u5feb\u5f88\u591a\uff0c\u6bd5\u7adf\u4e3b\u52a8\u4e0e\u88ab\u52a8\u5b66\u4e60\u662f\u6709\u672c\u8d28\u533a\u522b\u7684\u3002<\/p>\n<p>\u8fd9\u51e0\u5929\u6253\u7b97\u5148\u628a\u9879\u76ee\u7684\u524d\u540e\u7aef\u5206\u79bb\u67b6\u6784\u642d\u5efa\u5b8c\u6210\uff0c\u65e2\u7136\u662f\u524d\u540e\u7aef\u5206\u79bb\u9879\u76ee\u5c31\u514d\u4e0d\u4e86\u505a\u9274\u6743\uff0c \u6240\u4ee5 <code>oauth2.0<\/code> \u662f\u4e00\u4e2a\u6211\u4eec\u4e0d\u5f97\u4e0d\u4e86\u89e3\u7684\u77e5\u8bc6\u70b9\u3002<\/p>\n<h2>\u4e00\u3001OAuth2.0 \u4e3a\u4f55\u7269<\/h2>\n<p><code>OAuth<\/code> \u7b80\u5355\u7406\u89e3\u5c31\u662f\u4e00\u79cd\u6388\u6743\u673a\u5236\uff0c\u5b83\u662f\u5728\u5ba2\u6237\u7aef\u548c\u8d44\u6e90\u6240\u6709\u8005\u4e4b\u95f4\u7684\u6388\u6743\u5c42\uff0c\u7528\u6765\u5206\u79bb\u4e24\u79cd\u4e0d\u540c\u7684\u89d2\u8272\u3002\u5728\u8d44\u6e90\u6240\u6709\u8005\u540c\u610f\u5e76\u5411\u5ba2\u6237\u7aef\u9881\u53d1\u4ee4\u724c\u540e\uff0c\u5ba2\u6237\u7aef\u643a\u5e26\u4ee4\u724c\u53ef\u4ee5\u8bbf\u95ee\u8d44\u6e90\u6240\u6709\u8005\u7684\u8d44\u6e90\u3002<\/p>\n<p><code>OAuth2.0<\/code> \u662f<code>OAuth<\/code> \u534f\u8bae\u7684\u4e00\u4e2a\u7248\u672c\uff0c\u6709<code>2.0<\/code>\u7248\u672c\u90a3\u5c31\u6709<code>1.0<\/code>\u7248\u672c\uff0c\u6709\u610f\u601d\u7684\u662f<code>OAuth2.0<\/code> \u5374\u4e0d\u5411\u4e0b\u517c\u5bb9<code>OAuth1.0<\/code> \uff0c\u76f8\u5f53\u4e8e\u5e9f\u5f03\u4e86<code>1.0<\/code>\u7248\u672c\u3002<\/p>\n<p><strong>\u4e3e\u4e2a\u5c0f\u6817\u5b50\u89e3\u91ca\u4e00\u4e0b\u4ec0\u4e48\u662f OAuth \u6388\u6743\uff1f<\/strong><\/p>\n<p>\u5728\u5bb6\u809d\u6587\u7ae0\u997f\u4e86\u5b9a\u4e86\u4e00\u4e2a\u5916\u5356\uff0c\u5916\u5356\u5c0f\u54e5 30 \u79d2\u706b\u901f\u5230\u8fbe\u4e86\u6211\u5bb6\u4e0b\uff0c\u5948\u4f55\u6709\u95e8\u7981\u8fdb\u4e0d\u6765\uff0c\u53ef\u4ee5\u8f93\u5165\u5bc6\u7801\u8fdb\u5165\uff0c\u4f46\u51fa\u4e8e\u5b89\u5168\u7684\u8003\u8651\u6211\u5e76\u4e0d\u60f3\u544a\u8bc9\u4ed6\u5bc6\u7801\u3002<\/p>\n<p>\u6b64\u65f6\u5916\u5356\u5c0f\u54e5\u770b\u5230\u95e8\u7981\u6709\u4e00\u4e2a\u9ad8\u7ea7\u6309\u94ae\u201c<code>\u4e00\u952e\u83b7\u53d6\u6388\u6743<\/code>\u201d\uff0c\u53ea\u8981\u6211\u8fd9\u8fb9\u540c\u610f\uff0c\u4ed6\u4f1a\u83b7\u53d6\u5230\u4e00\u4e2a\u6709\u6548\u671f 2 \u5c0f\u65f6\u7684\u4ee4\u724c\uff08<code>token<\/code>\uff09\u6b63\u5e38\u51fa\u5165\u3002<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" referrerpolicy=\"no-referrer\" rel=\"noreferrer\" src=\"http:\/\/4563.org\/wp-content\/uploads\/2020\/12\/20200706163230102.pngpic_center.png\" alt=\"\u5145\u7535\u5145\u7535\uff0c OAuth2.0 \u7684\u56db\u79cd\u6388\u6743\u65b9\u5f0f\" \/><\/p>\n<p>\u4ee4\u724c\uff08<code>token<\/code>\uff09\u548c <code>\u5bc6\u7801<\/code> \u7684\u4f5c\u7528\u867d\u7136\u76f8\u4f3c\u90fd\u53ef\u4ee5\u8fdb\u5165\u7cfb\u7edf\uff0c\u4f46\u8fd8\u6709\u70b9\u4e0d\u540c\u3002<code>token<\/code> \u62e5\u6709\u6743\u9650\u8303\u56f4\uff0c\u6709\u65f6\u6548\u6027\u7684\uff0c\u5230\u671f\u81ea\u52a8\u5931\u6548\uff0c\u800c\u4e14\u65e0\u6548\u4fee\u6539\u3002<\/p>\n<h2>\u4e8c\u3001OAuth2.0 \u6388\u6743\u65b9\u5f0f<\/h2>\n<p><code>OAuth2.0<\/code> \u7684\u6388\u6743\u7b80\u5355\u7406\u89e3\u5176\u5b9e\u5c31\u662f\u83b7\u53d6\u4ee4\u724c\uff08<code>token<\/code>\uff09\u7684\u8fc7\u7a0b\uff0c<code>OAuth<\/code> \u534f\u8bae\u5b9a\u4e49\u4e86\u56db\u79cd\u83b7\u5f97\u4ee4\u724c\u7684\u6388\u6743\u65b9\u5f0f\uff08<code>authorization grant<\/code> \uff09\u5982\u4e0b\uff1a<\/p>\n<ul>\n<li>\u6388\u6743\u7801\uff08<code>authorization-code<\/code>\uff09<\/li>\n<li>\u9690\u85cf\u5f0f\uff08<code>implicit<\/code>\uff09<\/li>\n<li>\u5bc6\u7801\u5f0f\uff08<code>password<\/code>\uff09\uff1a<\/li>\n<li>\u5ba2\u6237\u7aef\u51ed\u8bc1\uff08<code>client credentials<\/code>\uff09<\/li>\n<\/ul>\n<p>\u4f46\u503c\u5f97\u6ce8\u610f\u7684\u662f\uff0c\u4e0d\u7ba1\u6211\u4eec\u4f7f\u7528\u54ea\u4e00\u79cd\u6388\u6743\u65b9\u5f0f\uff0c\u5728\u4e09\u65b9\u5e94\u7528\u7533\u8bf7\u4ee4\u724c\u4e4b\u524d\uff0c\u90fd\u5fc5\u987b\u5728\u7cfb\u7edf\u4e2d\u53bb\u7533\u8bf7\u8eab\u4efd\u552f\u4e00\u6807\u8bc6\uff1a\u5ba2\u6237\u7aef ID \uff08<code>client ID<\/code>\uff09\u548c \u5ba2\u6237\u7aef\u5bc6\u94a5\uff08<code>client secret<\/code>\uff09\u3002\u8fd9\u6837\u505a\u53ef\u4ee5\u4fdd\u8bc1 <code>token<\/code> \u4e0d\u88ab\u6076\u610f\u4f7f\u7528\u3002<\/p>\n<p>\u4e0b\u9762\u6211\u4eec\u4f1a\u5206\u6790\u6bcf\u79cd\u6388\u6743\u65b9\u5f0f\u7684\u539f\u7406\uff0c\u5728\u8fdb\u5165\u6b63\u9898\u524d\uff0c\u5148\u4e86\u89e3 <code>OAuth2.0<\/code> \u6388\u6743\u8fc7\u7a0b\u4e2d\u51e0\u4e2a\u91cd\u8981\u7684\u53c2\u6570\uff1a<\/p>\n<ul>\n<li><code>response_type<\/code>\uff1acode \u8868\u793a\u8981\u6c42\u8fd4\u56de\u6388\u6743\u7801\uff0ctoken \u8868\u793a\u76f4\u63a5\u8fd4\u56de\u4ee4\u724c<\/li>\n<li><code>client_id<\/code>\uff1a\u5ba2\u6237\u7aef\u8eab\u4efd\u6807\u8bc6<\/li>\n<li><code>client_secret<\/code>\uff1a\u5ba2\u6237\u7aef\u5bc6\u94a5<\/li>\n<li><code>redirect_uri<\/code>\uff1a\u91cd\u5b9a\u5411\u5730\u5740<\/li>\n<li><code>scope<\/code>\uff1a\u8868\u793a\u6388\u6743\u7684\u8303\u56f4\uff0c<code>read<\/code>\u53ea\u8bfb\u6743\u9650\uff0c<code>all<\/code>\u8bfb\u5199\u6743\u9650<\/li>\n<li><code>grant_type<\/code>\uff1a\u8868\u793a\u6388\u6743\u7684\u65b9\u5f0f\uff0c<code>AUTHORIZATION_CODE<\/code>\uff08\u6388\u6743\u7801\uff09\u3001<code>password<\/code>\uff08\u5bc6\u7801\uff09\u3001<code>client_credentials<\/code>\uff08\u51ed\u8bc1\u5f0f\uff09\u3001<code>refresh_token<\/code> \u66f4\u65b0\u4ee4\u724c<\/li>\n<li><code>state<\/code>\uff1a\u5e94\u7528\u7a0b\u5e8f\u4f20\u9012\u7684\u4e00\u4e2a\u968f\u673a\u6570\uff0c\u7528\u6765\u9632\u6b62<code>CSRF<\/code>\u653b\u51fb\u3002<\/li>\n<\/ul>\n<h4>1 \u3001\u6388\u6743\u7801<\/h4>\n<p><code>OAuth2.0<\/code>\u56db\u79cd\u6388\u6743\u4e2d\u6388\u6743\u7801\u65b9\u5f0f\u662f\u6700\u4e3a\u590d\u6742\uff0c\u4f46\u4e5f\u662f\u5b89\u5168\u7cfb\u6570\u6700\u9ad8\u7684\uff0c\u6bd4\u8f83\u5e38\u7528\u7684\u4e00\u79cd\u65b9\u5f0f\u3002\u8fd9\u79cd\u65b9\u5f0f\u9002\u7528\u4e8e\u517c\u5177\u524d\u540e\u7aef\u7684<code>Web<\/code>\u9879\u76ee\uff0c\u56e0\u4e3a\u6709\u4e9b\u9879\u76ee\u53ea\u6709\u540e\u7aef\u6216\u53ea\u6709\u524d\u7aef\uff0c\u5e76\u4e0d\u9002\u7528\u6388\u6743\u7801\u6a21\u5f0f\u3002<\/p>\n<p>\u4e0b\u56fe\u6211\u4eec\u4ee5\u7528<code>WX<\/code>\u767b\u5f55\u6398\u91d1\u4e3a\u4f8b\uff0c\u8be6\u7ec6\u770b\u4e00\u4e0b\u6388\u6743\u7801\u65b9\u5f0f\u7684\u6574\u4f53\u6d41\u7a0b\u3002<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" referrerpolicy=\"no-referrer\" rel=\"noreferrer\" src=\"http:\/\/4563.org\/wp-content\/uploads\/2020\/12\/20200706172813832.pngpic_center.png\" alt=\"\u5145\u7535\u5145\u7535\uff0c OAuth2.0 \u7684\u56db\u79cd\u6388\u6743\u65b9\u5f0f\" \/><\/p>\n<p>\u7528\u6237\u9009\u62e9<code>WX<\/code>\u767b\u5f55\u6398\u91d1\uff0c\u6398\u91d1\u4f1a\u5411<code>WX<\/code>\u53d1\u8d77\u6388\u6743\u8bf7\u6c42\uff0c\u63a5\u4e0b\u6765 <code>WX<\/code>\u8be2\u95ee\u7528\u6237\u662f\u5426\u540c\u610f\u6388\u6743\uff08\u5e38\u89c1\u7684\u5f39\u7a97\u6388\u6743\uff09\u3002<code>response_type<\/code> \u4e3a <code>code<\/code> \u8981\u6c42\u8fd4\u56de\u6388\u6743\u7801\uff0c<code>scope<\/code> \u53c2\u6570\u8868\u793a\u672c\u6b21\u6388\u6743\u8303\u56f4\u4e3a\u53ea\u8bfb\u6743\u9650\uff0c<code>redirect_uri<\/code> \u91cd\u5b9a\u5411\u5730\u5740\u3002<\/p>\n<pre><code>https:\/\/wx.com\/oauth\/authorize?   response_type=code&amp;   client_id=CLIENT_ID&amp;   redirect_uri=http:\/\/juejin.im\/callback&amp;   scope=read <\/code><\/pre>\n<p>\u7528\u6237\u540c\u610f\u6388\u6743\u540e\uff0c<code>WX<\/code> \u6839\u636e <code>redirect_uri<\/code>\u91cd\u5b9a\u5411\u5e76\u5e26\u4e0a\u6388\u6743\u7801\u3002<\/p>\n<pre><code>http:\/\/juejin.im\/callback?code=AUTHORIZATION_CODE <\/code><\/pre>\n<p>\u5f53\u6398\u91d1\u62ff\u5230\u6388\u6743\u7801\uff08 code \uff09\u65f6\uff0c\u5e26\u6388\u6743\u7801\u548c\u5bc6\u5319\u7b49\u53c2\u6570\u5411<code>WX<\/code>\u7533\u8bf7\u4ee4\u724c\u3002<code>grant_type<\/code>\u8868\u793a\u672c\u6b21\u6388\u6743\u4e3a\u6388\u6743\u7801\u65b9\u5f0f <code>authorization_code<\/code> \uff0c\u83b7\u53d6\u4ee4\u724c\u8981\u5e26\u4e0a\u5ba2\u6237\u7aef\u5bc6\u5319 <code>client_secret<\/code>\uff0c\u548c\u4e0a\u4e00\u6b65\u5f97\u5230\u7684\u6388\u6743\u7801 <code>code<\/code>\u3002<\/p>\n<pre><code>https:\/\/wx.com\/oauth\/token?  client_id=CLIENT_ID&amp;  client_secret=CLIENT_SECRET&amp;  grant_type=authorization_code&amp;  code=AUTHORIZATION_CODE&amp;  redirect_uri=http:\/\/juejin.im\/callback <\/code><\/pre>\n<p>\u6700\u540e <code>WX<\/code> \u6536\u5230\u8bf7\u6c42\u540e\u5411 <code>redirect_uri<\/code> \u5730\u5740\u53d1\u9001 <code>JSON<\/code> \u6570\u636e\uff0c\u5176\u4e2d\u7684<code>access_token<\/code> \u5c31\u662f\u4ee4\u724c\u3002<\/p>\n<pre><code> {       \"access_token\":\"ACCESS_TOKEN\",   \"token_type\":\"bearer\",   \"expires_in\":2592000,   \"refresh_token\":\"REFRESH_TOKEN\",   \"scope\":\"read\",   ...... } <\/code><\/pre>\n<h3>2 \u3001\u9690\u85cf\u5f0f<\/h3>\n<p>\u4e0a\u8fb9\u63d0\u5230\u6709\u4e00\u4e9b<code>Web<\/code>\u5e94\u7528\u662f\u6ca1\u6709\u540e\u7aef\u7684\uff0c \u5c5e\u4e8e\u7eaf\u524d\u7aef\u5e94\u7528\uff0c\u65e0\u6cd5\u7528\u4e0a\u8fb9\u7684\u6388\u6743\u7801\u6a21\u5f0f\u3002\u4ee4\u724c\u7684\u7533\u8bf7\u4e0e\u5b58\u50a8\u90fd\u9700\u8981\u5728\u524d\u7aef\u5b8c\u6210\uff0c\u8df3\u8fc7\u4e86\u6388\u6743\u7801\u8fd9\u4e00\u6b65\u3002<\/p>\n<p>\u524d\u7aef\u5e94\u7528\u76f4\u63a5\u83b7\u53d6 <code>token<\/code>\uff0c<code>response_type<\/code> \u8bbe\u7f6e\u4e3a <code>token<\/code>\uff0c\u8981\u6c42\u76f4\u63a5\u8fd4\u56de\u4ee4\u724c\uff0c\u8df3\u8fc7\u6388\u6743\u7801\uff0c<code>WX<\/code>\u6388\u6743\u901a\u8fc7\u540e\u91cd\u5b9a\u5411\u5230\u6307\u5b9a <code>redirect_uri<\/code> \u3002<\/p>\n<pre><code>https:\/\/wx.com\/oauth\/authorize?   response_type=token&amp;   client_id=CLIENT_ID&amp;   redirect_uri=http:\/\/juejin.im\/callback&amp;   scope=read <\/code><\/pre>\n<h3>3 \u3001\u5bc6\u7801\u5f0f<\/h3>\n<p>\u5bc6\u7801\u6a21\u5f0f\u6bd4\u8f83\u597d\u7406\u89e3\uff0c\u7528\u6237\u5728\u6398\u91d1\u76f4\u63a5\u8f93\u5165\u81ea\u5df1\u7684<code>WX<\/code>\u7528\u6237\u540d\u548c\u5bc6\u7801\uff0c\u6398\u91d1\u62ff\u7740\u4fe1\u606f\u76f4\u63a5\u53bb<code>WX<\/code>\u7533\u8bf7\u4ee4\u724c\uff0c\u8bf7\u6c42\u54cd\u5e94\u7684 <code>JSON<\/code>\u7ed3\u679c\u4e2d\u8fd4\u56de <code>token<\/code>\u3002<code>grant_type<\/code> \u4e3a <code>password<\/code> \u8868\u793a\u5bc6\u7801\u5f0f\u6388\u6743\u3002<\/p>\n<pre><code>https:\/\/wx.com\/token?   grant_type=password&amp;   username=USERNAME&amp;   password=PASSWORD&amp;   client_id=CLIENT_ID <\/code><\/pre>\n<p>\u8fd9\u79cd\u6388\u6743\u65b9\u5f0f\u7f3a\u70b9\u662f\u663e\u800c\u6613\u89c1\u7684\uff0c\u975e\u5e38\u7684\u5371\u9669\uff0c\u5982\u679c\u91c7\u53d6\u6b64\u65b9\u5f0f\u6388\u6743\uff0c\u8be5\u5e94\u7528\u4e00\u5b9a\u662f\u53ef\u4ee5\u9ad8\u5ea6\u4fe1\u4efb\u7684\u3002<\/p>\n<h3>4 \u3001\u51ed\u8bc1\u5f0f<\/h3>\n<p>\u51ed\u8bc1\u5f0f\u548c\u5bc6\u7801\u5f0f\u5f88\u76f8\u4f3c\uff0c\u4e3b\u8981\u9002\u7528\u4e8e\u90a3\u4e9b\u6ca1\u6709\u524d\u7aef\u7684\u547d\u4ee4\u884c\u5e94\u7528\uff0c\u53ef\u4ee5\u7528\u6700\u7b80\u5355\u7684\u65b9\u5f0f\u83b7\u53d6\u4ee4\u724c\uff0c\u5728\u8bf7\u6c42\u54cd\u5e94\u7684 <code>JSON<\/code> \u7ed3\u679c\u4e2d\u8fd4\u56de <code>token<\/code>\u3002<\/p>\n<p><code>grant_type<\/code> \u4e3a <code>client_credentials<\/code> \u8868\u793a\u51ed\u8bc1\u5f0f\u6388\u6743\uff0c<code>client_id<\/code> \u548c <code>client_secret<\/code> \u7528\u6765\u8bc6\u522b\u8eab\u4efd\u3002<\/p>\n<pre><code>https:\/\/wx.com\/token?   grant_type=client_credentials&amp;   client_id=CLIENT_ID&amp;   client_secret=CLIENT_SECRET <\/code><\/pre>\n<h2>\u4e09\u3001\u4ee4\u724c\u7684\u4f7f\u7528\u4e0e\u66f4\u65b0<\/h2>\n<h3>1 \u3001\u4ee4\u724c\u600e\u4e48\u7528\uff1f<\/h3>\n<p>\u62ff\u5230\u4ee4\u724c\u53ef\u4ee5\u8c03\u7528 <code>WX<\/code> API \u8bf7\u6c42\u6570\u636e\u4e86\uff0c\u90a3\u4ee4\u724c\u8be5\u600e\u4e48\u7528\u5462\uff1f<\/p>\n<p>\u6bcf\u4e2a\u5230\u8fbe<code>WX<\/code>\u7684\u8bf7\u6c42\u90fd\u5fc5\u987b\u5e26\u4e0a <code>token<\/code>\uff0c\u5c06 <code>token<\/code> \u653e\u5728 <code>http<\/code> \u8bf7\u6c42\u5934\u90e8\u7684\u4e00\u4e2a<code>Authorization<\/code>\u5b57\u6bb5\u91cc\u3002<\/p>\n<p>\u5982\u679c\u4f7f\u7528<code>postman<\/code> \u6a21\u62df\u8bf7\u6c42\uff0c\u8981\u5728<code>Authorization<\/code> -&gt; <code>Bearer Token<\/code> \u653e\u5165 <code>token<\/code>\uff0c<strong>\u6ce8\u610f<\/strong>\uff1a\u4f4e\u7248\u672c<code>postman<\/code> \u6ca1\u6709\u8fd9\u4e2a\u9009\u9879\u3002<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" referrerpolicy=\"no-referrer\" rel=\"noreferrer\" src=\"http:\/\/4563.org\/wp-content\/uploads\/2020\/12\/20201205_5fcc18bb2018d.png\" alt=\"\u5145\u7535\u5145\u7535\uff0c OAuth2.0 \u7684\u56db\u79cd\u6388\u6743\u65b9\u5f0f\" \/><\/p>\n<h3>2 \u3001\u4ee4\u724c\u8fc7\u671f\u600e\u4e48\u529e\uff1f<\/h3>\n<p><code>token<\/code>\u662f\u6709\u65f6\u6548\u6027\u7684\uff0c\u4e00\u65e6\u8fc7\u671f\u5c31\u9700\u8981\u91cd\u65b0\u83b7\u53d6\uff0c\u4f46\u662f\u91cd\u8d70\u4e00\u904d\u6388\u6743\u6d41\u7a0b\uff0c\u4e0d\u4ec5\u9ebb\u70e6\u800c\u4e14\u7528\u6237\u4f53\u9a8c\u4e5f\u4e0d\u597d\uff0c\u90a3\u5982\u4f55\u8ba9\u66f4\u65b0\u4ee4\u724c\u53d8\u5f97\u4f18\u96c5\u4e00\u70b9\u5462\uff1f<\/p>\n<p>\u4e00\u822c\u5728\u9881\u53d1\u4ee4\u724c\u65f6\u4f1a\u4e00\u6b21\u53d1\u4e24\u4e2a\u4ee4\u724c\uff0c\u4e00\u4e2a\u4ee4\u724c\u7528\u6765\u8bf7\u6c42<code>API<\/code>\uff0c\u53e6\u4e00\u4e2a\u8d1f\u8d23\u66f4\u65b0\u4ee4\u724c <code>refresh_token<\/code>\u3002<code>grant_type<\/code> \u4e3a <code>refresh_token<\/code> \u8bf7\u6c42\u4e3a\u66f4\u65b0\u4ee4\u724c\uff0c\u53c2\u6570 <code>refresh_token<\/code> \u662f\u7528\u4e8e\u66f4\u65b0\u4ee4\u724c\u7684\u4ee4\u724c\u3002<\/p>\n<pre><code>https:\/\/wx.com\/oauth\/token?   grant_type=refresh_token&amp;   client_id=CLIENT_ID&amp;   client_secret=CLIENT_SECRET&amp;   refresh_token=REFRESH_TOKEN <\/code><\/pre>\n<h2>\u603b\u7ed3<\/h2>\n<p><code>OAuth2.0<\/code> \u6388\u6743\u5176\u5b9e\u5e76\u4e0d\u662f\u5f88\u96be\uff0c\u53ea\u4e0d\u8fc7\u6388\u6743\u6d41\u7a0b\u7a0d\u663e\u9ebb\u70e6\uff0c\u903b\u8f91\u6709\u4e9b\u7ed5\uff0c<code>OAuth2.0<\/code>\u5b83\u662f\u9762\u8bd5\u7ecf\u5e38\u4f1a\u88ab\u95ee\u5230\u7684\u77e5\u8bc6\u70b9\uff0c\u8fd8\u662f\u5e94\u8be5\u591a\u4e86\u89e3\u4e00\u4e0b\u3002\u4e0b\u4e00\u7bc7\u5b9e\u6218 <code>OAuth2.0<\/code>\u56db\u79cd\u6388\u6743\uff0c\u656c\u8bf7\u671f\u5f85\uff0c\u6b22\u8fce\u5173\u6ce8\u54e6~<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" referrerpolicy=\"no-referrer\" rel=\"noreferrer\" src=\"http:\/\/4563.org\/wp-content\/uploads\/2020\/12\/20201205_5fcc18c18276a.png\" alt=\"\u5145\u7535\u5145\u7535\uff0c OAuth2.0 \u7684\u56db\u79cd\u6388\u6743\u65b9\u5f0f\" \/><\/p>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>7<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"4426916\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : wwwtarzan <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u662f\u4e0d\u662f\u53d1\u9519\u4e86\u8282\u70b9\uff1f                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4426917\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : bigyuhao94 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u4e3a\u4ec0\u4e48\u611f\u89c9\u8fd9\u79cd\u5c31\u662f\u7c7b\u4f3c \u8334\u9999\u8c46\u7684\u56db\u79cd\u5199\u6cd5                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4426918\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : shengkai <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u4e2a\u4eba\u89c9\u5f97\u672c\u7ad9\u7684\u7528\u6237\u7fa4\u4f53\u4e0d\u592a\u9002\u5408\u8fd9\u79cd\u300c\u63a8\u5e7f\u300d\u65b9\u5f0f\uff0c\u5177\u4f53\u539f\u56e0\u6211\u89c9\u5f97\u4e3b\u4f5c\u4e3a\u8fd0\u8425\u8005\u9700\u8981\u81ea\u5df1\u5206\u6790\u3002\u60a8\u7684\u8fd9\u79cd\u65b9\u5f0f\u6709\u5f88\u5927\u53ef\u80fd\u5728 V \u7ad9\u8d26\u53f7\u88ab ban\uff0c\u5f97\u4e0d\u507f\u5931\u2026                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4426919\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : hantsy <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u4f5c\u4e3a\u79d1\u666e\u6587\u7ae0\u4e0d\u9519\u3002<\/p>\n<p>\u4e0d\u5f97\u4e0d\u8bf4\uff0c\u9690\u85cf\u5f0f\uff08 implicit \uff09\u548c \u5bc6\u7801\u5f0f\uff08 resource owner password \uff09\u5df2\u7ecf\u6807\u5fd7\u4e3a\u8fc7\u65f6\uff08 Deprecated \uff09\uff0c\u88ab\u8bc1\u660e\u6709\u5b89\u5168\u6f0f\u6d1e\u3002\u6d41\u884c\u7684 Social network Login \u51e0\u4e4e\u90fd\u4e0d\u652f\u6301\u8fd9\u4e24\u79cd\u65b9\u6848\u3002<\/p>\n<p>\u5728 OAuth 2.1 \u4e2d\uff0c\u4e0d\u518d\u6709 implicit \u548c resource owner password\uff0c \u589e\u52a0\u4e86 Device Code\uff0cPKCE \u7b49\u9488\u5bf9\u624b\u673a\uff0cIoT \u8bbe\u5907\u8bbf\u95ee\u7b49\u65b0\u7ec8\u7aef\u7684\u96c6\u6210\u65b9\u6848\u3002                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4426920\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : baoshuo <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u770b\u5230\u8fd9\u79cd\u6807\u9898\u5148\u4e0b\u6765\u627e\u4e8c\u7ef4\u7801\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4426921\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : julyclyde <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @bigyuhao94 \u5176\u5b9e\u8fd8\u771f\u4e0d\u662f\u8334\u9999\u8c46\u7684\u56db\u79cd                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4426922\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : yazoox <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u8bf7\u6559\u4e00\u4e0b\uff0c\u8fd9\u91cc\u7684 client ID and client secret \u662f\u6307\u4ec0\u4e48\uff1f\u80af\u5b9a\u4e0d\u662f user name or id &amp; password                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>\u5145\u7535\u5145\u7535\uff0c OAuth2.0 \u7684\u56db&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/217517"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=217517"}],"version-history":[{"count":1,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/217517\/revisions"}],"predecessor-version":[{"id":217521,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/217517\/revisions\/217521"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=217517"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=217517"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=217517"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}