{"id":811,"date":"2018-07-19T16:48:36","date_gmt":"2018-07-19T08:48:36","guid":{"rendered":"https:\/\/blog.jsjs.org\/?p=811"},"modified":"2018-07-19T16:48:36","modified_gmt":"2018-07-19T08:48:36","slug":"%e5%85%b3%e4%ba%8e-restful-api-%e5%ae%89%e5%85%a8%e8%ae%a4%e8%af%81%e6%96%b9%e5%bc%8f%e7%9a%84%e4%b8%80%e4%ba%9b%e6%80%bb%e7%bb%93","status":"publish","type":"post","link":"https:\/\/blog.jsjs.org\/?p=811","title":{"rendered":"\u5173\u4e8e RESTFUL API \u5b89\u5168\u8ba4\u8bc1\u65b9\u5f0f\u7684\u4e00\u4e9b\u603b\u7ed3"},"content":{"rendered":"<h1>\u5e38\u7528\u8ba4\u8bc1\u65b9\u5f0f<\/h1>\n<p>\u5728\u4e4b\u524d\u7684\u6587\u7ae0<a href=\"http:\/\/www.cnblogs.com\/Irving\/p\/4929722.html\">REST API \u5b89\u5168\u8bbe\u8ba1\u6307\u5357<\/a>\u4e0e<a href=\"http:\/\/www.cnblogs.com\/Irving\/p\/4898117.html\">\u4f7f\u7528 AngularJS &amp; NodeJS \u5b9e\u73b0\u57fa\u4e8e token \u7684\u8ba4\u8bc1\u5e94\u7528<\/a>\u4e24\u7bc7\u6587\u7ae0\u4e2d\uff0c<a href=\"http:\/\/segmentfault.com\/a\/1190000004086946\">[\u8bd1]web\u6743\u9650\u9a8c\u8bc1\u65b9\u6cd5\u8bf4\u660e<\/a>\u4e2d\u4e5f\u8be6\u7ec6\u4ecb\u7ecd\uff0c\u4e00\u822c\u57fa\u4e8eREST API \u5b89\u5168\u8bbe\u8ba1\u5e38\u7528\u65b9\u5f0f\u6709\uff1a<br \/>\n<strong>HTTP Basic<\/strong><\/p>\n<blockquote><p><code>Basic admin:admin<br \/>\nBasic YWRtaW46YWRtaW4=<br \/>\nAuthorization: Basic YWRtaW46YWRtaW4=<\/code><strong><br \/>\n<\/strong>\u7531\u4e8eHTTP\u534f\u8bae\u662f\u65e0\u72b6\u6001\u7684\uff0c\u6240\u6709\u6bcf\u6b21\u8bf7\u6c42\u90fd\u5f97\u5e26\u4e0a\u8eab\u4efd\u4fe1\u606f\uff0c\u57fa\u4e8eHttp basic\u9a8c\u8bc1\u5c31\u662f\u7b80\u5355\u7684\u5c06\u7528\u6237\u540d\u548c\u5bc6\u7801base64\u7f16\u7801\u653e\u5230header\u4e2d\uff0c\u4e00\u822c\u9700\u8981HTTPS,\u5b89\u5168\u6027\u8f83\u4f4e\uff0c\u5b9e\u73b0\u7684\u65b9\u5f0f\u53ef\u4ee5\u57fa\u4e8e\u4ee3\u7801\u5b9e\u73b0\u4e5f\u53ef\u4ee5\u57fa\u4e8eweb\u5bb9\u5668\u914d\u7f6eapache,nginx\u7b49web\u670d\u52a1\u5668\u5373\u53ef\u5b9e\u73b0\u3002<\/p><\/blockquote>\n<p><strong>HTTP Digest<\/strong><\/p>\n<blockquote><p>\u6458\u8981\u8ba4\u8bc1 digest authentication,\u670d\u52a1\u5668\u7aef\u4ee5nonce\u8fdb\u884c\u8d28\u8be2\uff0c\u5ba2\u6237\u7aef\u4ee5\u7528\u6237\u540d\uff0c\u5bc6\u7801\uff0cnonce\uff0cHTTP\u65b9\u6cd5\uff0c\u8bf7\u6c42\u7684URI\u7b49\u4fe1\u606f\u4e3a\u57fa\u7840\u4ea7\u751f\u7684response\u4fe1\u606f\u8fdb\u884c\u8ba4\u8bc1\u7684\u65b9\u5f0f\u3002<br \/>\n\u203b \u4e0d\u5305\u542b\u5bc6\u7801\u7684\u660e\u6587\u4f20\u9012<br \/>\n\u6458\u8981\u8ba4\u8bc1\u6b65\u9aa4\uff1a<br \/>\n1. \u5ba2\u6237\u7aef\u8bbf\u95ee\u4e00\u4e2a\u53d7http\u6458\u8981\u8ba4\u8bc1\u4fdd\u62a4\u7684\u8d44\u6e90\u3002<br \/>\n2. \u670d\u52a1\u5668\u8fd4\u56de401\u72b6\u6001\u4ee5\u53canonce\u7b49\u4fe1\u606f\uff0c\u8981\u6c42\u5ba2\u6237\u7aef\u8fdb\u884c\u8ba4\u8bc1\u3002<br \/>\nHTTP\/1.1 401 Unauthorized<br \/>\nWWW-Authenticate: Digest<br \/>\nrealm=&#8221;testrealm@host.com&#8221;,<br \/>\nqop=&#8221;auth,auth-int&#8221;,<br \/>\nnonce=&#8221;dcd98b7102dd2f0e8b11d0f600bfb0c093&#8243;,<br \/>\nopaque=&#8221;5ccc069c403ebaf9f0171e9517f40e41&#8243;<br \/>\n3. \u5ba2\u6237\u7aef\u5c06\u4ee5\u7528\u6237\u540d\uff0c\u5bc6\u7801\uff0cnonce\u503c\uff0cHTTP\u65b9\u6cd5, \u548c\u88ab\u8bf7\u6c42\u7684URI\u4e3a\u6821\u9a8c\u503c\u57fa\u7840\u800c\u52a0\u5bc6\uff08\u9ed8\u8ba4\u4e3aMD5\u7b97\u6cd5\uff09\u7684\u6458\u8981\u4fe1\u606f\u8fd4\u56de\u7ed9\u670d\u52a1\u5668\u3002<br \/>\n\u8ba4\u8bc1\u5fc5\u987b\u7684\u4e94\u4e2a\u60c5\u62a5\uff1a<br \/>\n\u30fb realm \uff1a \u54cd\u5e94\u4e2d\u5305\u542b\u4fe1\u606f<br \/>\n\u30fb nonce \uff1a \u54cd\u5e94\u4e2d\u5305\u542b\u4fe1\u606f<br \/>\n\u30fb username \uff1a \u7528\u6237\u540d<br \/>\n\u30fb digest-uri \uff1a \u8bf7\u6c42\u7684URI<br \/>\n\u30fb response \uff1a \u4ee5\u4e0a\u9762\u56db\u4e2a\u4fe1\u606f\u52a0\u4e0a\u5bc6\u7801\u4fe1\u606f\uff0c\u4f7f\u7528MD5\u7b97\u6cd5\u5f97\u51fa\u7684\u5b57\u7b26\u4e32\u3002<\/p>\n<p>Authorization: Digest<br \/>\nusername=&#8221;Mufasa&#8221;, \u2190 \u5ba2\u6237\u7aef\u5df2\u77e5\u4fe1\u606f<br \/>\nrealm=&#8221;testrealm@host.com&#8221;, \u2190 \u670d\u52a1\u5668\u7aef\u8d28\u8be2\u54cd\u5e94\u4fe1\u606f<br \/>\nnonce=&#8221;dcd98b7102dd2f0e8b11d0f600bfb0c093&#8243;, \u2190 \u670d\u52a1\u5668\u7aef\u8d28\u8be2\u54cd\u5e94\u4fe1\u606f<br \/>\nuri=&#8221;\/dir\/index.html&#8221;, \u2190 \u5ba2\u6237\u7aef\u5df2\u77e5\u4fe1\u606f<br \/>\nqop=auth, \u2190 \u670d\u52a1\u5668\u7aef\u8d28\u8be2\u54cd\u5e94\u4fe1\u606f<br \/>\nnc=00000001, \u2190 \u5ba2\u6237\u7aef\u8ba1\u7b97\u51fa\u7684\u4fe1\u606f<br \/>\ncnonce=&#8221;0a4f113b&#8221;, \u2190 \u5ba2\u6237\u7aef\u8ba1\u7b97\u51fa\u7684\u5ba2\u6237\u7aefnonce<br \/>\nresponse=&#8221;6629fae49393a05397450978507c4ef1&#8243;, \u2190 \u6700\u7ec8\u7684\u6458\u8981\u4fe1\u606f ha3<br \/>\nopaque=&#8221;5ccc069c403ebaf9f0171e9517f40e41&#8243; \u2190 \u670d\u52a1\u5668\u7aef\u8d28\u8be2\u54cd\u5e94\u4fe1\u606f<br \/>\n4. \u5982\u679c\u8ba4\u8bc1\u6210\u529f\uff0c\u5219\u8fd4\u56de\u76f8\u5e94\u7684\u8d44\u6e90\u3002\u5982\u679c\u8ba4\u8bc1\u5931\u8d25\uff0c\u5219\u4ecd\u8fd4\u56de401\u72b6\u6001\uff0c\u8981\u6c42\u91cd\u65b0\u8fdb\u884c\u8ba4\u8bc1\u3002<\/p>\n<p>\u6ce8\u610f\u4e8b\u9879\uff1a<br \/>\n1. \u907f\u514d\u5c06\u5bc6\u7801\u4f5c\u4e3a\u660e\u6587\u5728\u7f51\u7edc\u4e0a\u4f20\u9012\uff0c\u76f8\u5bf9\u63d0\u9ad8\u4e86HTTP\u8ba4\u8bc1\u7684\u5b89\u5168\u6027\u3002<br \/>\n2. \u5f53\u7528\u6237\u4e3a\u67d0\u4e2arealm\u9996\u6b21\u8bbe\u7f6e\u5bc6\u7801\u65f6\uff0c\u670d\u52a1\u5668\u4fdd\u5b58\u7684\u662f\u4ee5\u7528\u6237\u540d\uff0crealm\uff0c\u5bc6\u7801\u4e3a\u57fa\u7840\u8ba1\u7b97\u51fa\u7684\u54c8\u5e0c\u503c\uff08ha1\uff09\uff0c\u800c\u975e\u5bc6\u7801\u672c\u8eab\u3002<br \/>\n3. \u5982\u679cqop=auth-int\uff0c\u5728\u8ba1\u7b97ha2\u65f6\uff0c\u9664\u4e86\u5305\u62ecHTTP\u65b9\u6cd5\uff0cURI\u8def\u5f84\u5916\uff0c\u8fd8\u5305\u62ec\u8bf7\u6c42\u5b9e\u4f53\u4e3b\u4f53\uff0c\u4ece\u800c\u9632\u6b62PUT\u548cPOST\u8bf7\u6c42\u8868\u793a\u88ab\u4eba\u7be1\u6539\u3002<br \/>\n4. \u4f46\u662f\u56e0\u4e3anonce\u672c\u8eab\u53ef\u4ee5\u88ab\u7528\u6765\u8fdb\u884c\u6458\u8981\u8ba4\u8bc1\uff0c\u6240\u4ee5\u4e5f\u65e0\u6cd5\u786e\u4fdd\u8ba4\u8bc1\u540e\u4f20\u9012\u8fc7\u6765\u7684\u6570\u636e\u7684\u5b89\u5168\u6027\u3002<\/p>\n<p>\u203b nonce\uff1a\u968f\u673a\u5b57\u7b26\u4e32\uff0c\u6bcf\u6b21\u8fd4\u56de401\u54cd\u5e94\u7684\u65f6\u5019\u90fd\u4f1a\u8fd4\u56de\u4e00\u4e2a\u4e0d\u540c\u7684nonce\u3002<br \/>\n\u203b nounce\uff1a\u968f\u673a\u5b57\u7b26\u4e32\uff0c\u6bcf\u4e2a\u8bf7\u6c42\u90fd\u5f97\u5230\u4e00\u4e2a\u4e0d\u540c\u7684nounce\u3002<br \/>\n\u203b MD5(Message Digest algorithm 5\uff0c\u4fe1\u606f\u6458\u8981\u7b97\u6cd5)<br \/>\n1)\u7528\u6237\u540d:realm:\u5bc6\u7801 \u21d2 ha1<br \/>\n2)HTTP\u65b9\u6cd5:URI \u21d2 ha2<br \/>\n3)ha1:nonce:nc:cnonce:qop:ha2 \u21d2 ha3<\/p><\/blockquote>\n<p><strong>WSSE(WS-Security)<\/strong><\/p>\n<blockquote><p>\u00a0\u00a0\u00a0 WSSE UsernameToken<br \/>\n\u670d\u52a1\u5668\u7aef\u4ee5nonce\u8fdb\u884c\u8d28\u8be2\uff0c\u5ba2\u6237\u7aef\u4ee5\u7528\u6237\u540d\uff0c\u5bc6\u7801\uff0cnonce\uff0cHTTP\u65b9\u6cd5\uff0c\u8bf7\u6c42\u7684URI\u7b49\u4fe1\u606f\u4e3a\u57fa\u7840\u4ea7\u751f\u7684response\u4fe1\u606f\u8fdb\u884c\u8ba4\u8bc1\u7684\u65b9\u5f0f\u3002<br \/>\n\u203b \u4e0d\u5305\u542b\u5bc6\u7801\u7684\u660e\u6587\u4f20\u9012<br \/>\nWSSE\u8ba4\u8bc1\u6b65\u9aa4\uff1a<br \/>\n1. \u5ba2\u6237\u7aef\u8bbf\u95ee\u4e00\u4e2a\u53d7WSSE\u8ba4\u8bc1\u4fdd\u62a4\u7684\u8d44\u6e90\u3002<br \/>\n2. \u670d\u52a1\u5668\u8fd4\u56de401\u72b6\u6001\uff0c\u8981\u6c42\u5ba2\u6237\u7aef\u8fdb\u884c\u8ba4\u8bc1\u3002<br \/>\nHTTP\/1.1 401 Unauthorized<br \/>\nWWW-Authenticate: WSSE<br \/>\nrealm=&#8221;testrealm@host.com&#8221;,<br \/>\nprofile=&#8221;UsernameToken&#8221; \u2190 \u670d\u52a1\u5668\u671f\u671b\u4f60\u7528UsernameToken\u89c4\u5219\u751f\u6210\u56de\u5e94<br \/>\n\u203b UsernameToken\u89c4\u5219\uff1a\u5ba2\u6237\u7aef\u751f\u6210\u4e00\u4e2anonce\uff0c\u7136\u540e\u6839\u636e\u8be5nonce\uff0c\u5bc6\u7801\u548c\u5f53\u524d\u65e5\u65f6\u6765\u7b97\u51fa\u54c8\u5e0c\u503c\u3002<br \/>\n3. \u5ba2\u6237\u7aef\u5c06\u751f\u6210\u4e00\u4e2anonce\u503c\uff0c\u5e76\u4ee5\u8be5nonce\u503c\uff0c\u5bc6\u7801\uff0c\u5f53\u524d\u65e5\u65f6\u4e3a\u57fa\u7840\uff0c\u7b97\u51fa\u54c8\u5e0c\u503c\u8fd4\u56de\u7ed9\u670d\u52a1\u5668\u3002<br \/>\nAuthorization: WSSE profile=&#8221;UsernameToken&#8221;<br \/>\nX-WSSE:UsernameToken<br \/>\nusername=&#8221;Mufasa&#8221;,<br \/>\nPasswordDigest=&#8221;Z2Y&#8230;&#8230;&#8221;,<br \/>\nNonce=&#8221;dcd98b7102dd2f0e8b11d0f600bfb0c093&#8243;,<br \/>\nCreated=&#8221;2010-01-01T09:00:00Z&#8221;<br \/>\n4. \u5982\u679c\u8ba4\u8bc1\u6210\u529f\uff0c\u5219\u8fd4\u56de\u76f8\u5e94\u7684\u8d44\u6e90\u3002\u5982\u679c\u8ba4\u8bc1\u5931\u8d25\uff0c\u5219\u4ecd\u8fd4\u56de401\u72b6\u6001\uff0c\u8981\u6c42\u91cd\u65b0\u8fdb\u884c\u8ba4\u8bc1\u3002<\/p><\/blockquote>\n<p><strong>API KEY<\/strong><\/p>\n<blockquote><p>\u4e00\u822c\u4f1a\u5206\u914dapp_key,sign_key\u4e24\u4e2a\u503c,\u5c06\u901a\u77e5\u8fc7\u6765\u7684\u6240\u6709\u53c2\u6570\uff0c\u9664\u53bbsign\u672c\u8eab\uff0c\u4ee5\u53ca\u503c\u662f\u7a7a\u7684\u53c2\u6570\uff0c\u6309\u53c2\u6570\u540d\u5b57\u6bcd\u5347\u5e8f\u6392\u5e8f\uff0c\u7136\u540e\u6309\u53c2\u952e\u503c\u2026\u53c2\u6570n\u503cn\u7684\u65b9\u5f0f\u8fdb\u884c\u8fde\u63a5\uff0c<br \/>\n\u5f97\u5230\u4e00\u4e2a\u5b57\u7b26\u4e32\u7136\u540e\u5728\u8fde\u63a5\u540e\u5f97\u5230\u7684\u5b57\u7b26\u4e32\u524d\u9762\u52a0\u4e0a\u901a\u77e5\u9a8c\u8bc1\u5bc6\u94a5(sign_key, \u4e0d\u540c\u4e8eapp_key)\uff0c\u7136\u540e\u8ba1\u7b97sha1\u503c\uff0c\u8f6c\u6210\u5c0f\u5199<br \/>\n\u6bd4\u5982\u8bf7\u6c42\u7684\u53c2\u6570\u4e3a\uff1a<br \/>\n?sign=9987e6395c239a48ac7f0d185c525ee965e591a7&amp;verifycode=123412341234&amp;app_key=ca2bf41f1910a9c359370ebf87caeafd&amp;poiid=12345&amp;time<br \/>\nstamp=1384333143&amp;poiname= \u6d77\u5e95\u635e(\u671d\u9633\u5e97)&amp;v=1<br \/>\n\u53bb\u6389sign\u53c2\u6570\uff0c\u5176\u4f59\u7684\u6309\u53c2\u6570\u540d\u5347\u5e8f\u6392\u5217\uff1aapp_keyca2bf41f1910a9c359370ebf87caeafdpoiid12345poiname\u6d77\u5e95\u635e(\u671d\u9633\u5e97)timestamp1384333143v<br \/>\n1verifycode123412341234<br \/>\n\u5047\u8bbesign_key\u4e3a21be83530509abc81aa945a02bec37601cf3cc21\uff0c\u6211\u4eec\u628asign_key\u653e\u5728\u4e0a\u9762\u7684\u5b57\u7b26\u4e32\u7684\u524d\u9762\uff1a21be83530509abc81aa945a02bec37601c<br \/>\nf3cc21app_keyca2bf41f1910a9c359370ebf87caeafdpoiid12345poiname\u6d77\u5e95\u635e(\u671d\u9633\u5e97)timestamp1384333143v1verifycode123412341234<br \/>\n\u8ba1\u7b97sha1()\u7ed3\u679c\u4e3a\uff1a9987e6395c239a48ac7f0d185c525ee965e591a7<\/p>\n<p>\u5fae\u4fe1V3\u652f\u4ed8\u4e0e\u7f8e\u56e2\u5238(\u4ee5\u4e0a\u662f\u7f8e\u56e2\u6838\u9500\u5238\u6587\u6863\u6458\u5f55)\u91c7\u7528\u6b64\u79cd\u65b9\u5f0f\uff0c\u5bf9\u5916\u6709\u4e00\u4e2a\u7edf\u4e00\u7684\u670d\u52a1\u7f51\u5173\uff0c\u4e00\u822c\u5982\u679c\u8bbe\u8ba1\u5230\u5b89\u5168\u6027\u91cd\u8981\u7684\u63a5\u53e3\uff0c\u518d\u52a0\u4e0a\u6570\u5b57\u8bc1\u4e66(\u5982\u5fae\u4fe1\u652f\u4ed8\u7684\u9000\u6b3e\u63a5\u53e3)\uff0c\u9002\u7528\u670d\u52a1\u7aef\u5bf9\u670d\u52a1\u7aef\u7684\u5e94\u7528\u3002<\/p><\/blockquote>\n<p><strong>OAUTH 2.0<\/strong><\/p>\n<blockquote><p>OATH2\u8bbe\u8ba1\u66f4\u4fa7\u91cd\u5bf9\u8d44\u6e90\u7684\u6388\u6743\uff0cOAUTH2\u89c4\u8303\u5b9a\u4e49\u4e86Authorization Code,Resource Owner Password Credentials,Client Credentials ,Implicit Grant\u51e0\u79cd\u5b9e\u73b0\u65b9\u5f0f\uff0c\u5177\u4f53\u770b:<a href=\"http:\/\/www.cnblogs.com\/Irving\/p\/4134629.html\">OAuth2.0\u57fa\u7840\u6982\u8ff0<\/a>\u00a0,Authorization Code \u6a21\u5f0f\u4fa7\u91cd\u5bf9\u7b2c\u4e09\u65b9\u7528\u6237\u8d44\u6e90\u7684\u6388\u6743(\u5982QQ\u8054\u5408\u767b\u5f55\uff0c\u5fae\u535a\u5f00\u653e\u5e73\u53f0\u7b49)\uff0cResource Owner Password Credentials \u4fa7\u91cd\u5bf9\u4e2a\u4eba\u7528\u6237\u8d44\u6e90\u6388\u6743(\u5982App\uff09\uff0cClient Credentials \u4fa7\u91cd\u5bf9\u5ba2\u6237\u7aef\u7684\u8d44\u6e90\u6388\u6743\uff0cImplicit Grant \u662f\u4e00\u79cd\u6700\u7b80\u5316\u6a21\u5f0f\uff0c\u5982\u7f51\u9875\u4e2dJS\u4e2d\u8c03\u7528\uff0c\u9002\u7528\u573a\u666f\u6bd4\u8f83\u5c40\u9650\u3002<\/p><\/blockquote>\n<p><strong>HMAC<\/strong><\/p>\n<blockquote><p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/bitoftech.net\/wp-content\/uploads\/2014\/12\/dn781361.Lakshmir_Figure1_hiresen-usMSDN.10.png\" alt=\"ASP.NET Web API Security Filters\" width=\"550\" height=\"532\" \/><\/p>\n<p>1) \u5148\u7531\u5ba2\u6237\u7aef\u5411\u670d\u52a1\u5668\u53d1\u51fa\u4e00\u4e2a\u9a8c\u8bc1\u8bf7\u6c42\u3002<br \/>\n2) \u670d\u52a1\u5668\u63a5\u5230\u6b64\u8bf7\u6c42\u540e\u751f\u6210\u4e00\u4e2a\u968f\u673a\u6570\u5e76\u901a\u8fc7\u7f51\u7edc\u4f20\u8f93\u7ed9\u5ba2\u6237\u7aef\uff08\u6b64\u4e3a\u8d28\u7591\uff09\u3002<br \/>\n3) \u5ba2\u6237\u7aef\u5c06\u6536\u5230\u7684\u968f\u673a\u6570\u63d0\u4f9b\u7ed9ePass\uff0c\u7531ePass\u4f7f\u7528\u8be5\u968f\u673a\u6570\u4e0e\u5b58\u50a8\u5728ePass\u4e2d\u7684\u5bc6\u94a5\u8fdb\u884cHMAC-MD5\u8fd0\u7b97\u5e76\u5f97\u5230\u4e00\u4e2a\u7ed3\u679c\u4f5c\u4e3a\u8ba4\u8bc1\u8bc1\u636e\u4f20\u7ed9\u670d\u52a1\u5668\uff08\u6b64\u4e3a\u54cd\u5e94\uff09\u3002<br \/>\n4) \u4e0e\u6b64\u540c\u65f6\uff0c\u670d\u52a1\u5668\u4e5f\u4f7f\u7528\u8be5\u968f\u673a\u6570\u4e0e\u5b58\u50a8\u5728\u670d\u52a1\u5668\u6570\u636e\u5e93\u4e2d\u7684\u8be5\u5ba2\u6237\u5bc6\u94a5\u8fdb\u884cHMAC-MD5\u8fd0\u7b97\uff0c\u5982\u679c\u670d\u52a1\u5668\u7684\u8fd0\u7b97\u7ed3\u679c\u4e0e\u5ba2\u6237\u7aef\u4f20\u56de\u7684\u54cd\u5e94,\u7ed3\u679c\u76f8\u540c\uff0c\u5219\u8ba4\u4e3a\u5ba2\u6237\u7aef\u662f\u4e00\u4e2a\u5408\u6cd5\u7528\u6237<\/p><\/blockquote>\n<p><strong>JWT<\/strong><\/p>\n<blockquote><p>JWT \u662fJSON Web Token\u7b80\u5199\uff0c\u7528\u4e8e\u53d1\u9001\u901a\u8fc7\u7b7e\u540d\u548c\u8ba4\u8bc1\u7684\u4e1c\u897f\uff0c\u670d\u52a1\u7aef\u53ef\u901a\u8fc7\u89e3\u6790\u8be5\u503c\u6765\u9a8c\u8bc1\u662f\u5426\u6709\u64cd\u4f5c\u6743\u9650\uff0c\u662f\u5426\u8fc7\u671f\u7b49\u5b89\u5168\u6027\u68c0\u67e5\u7b49\u3002<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/blog.nsfocus.net\/wp-content\/uploads\/2015\/10\/jwt.png\" alt=\"3\" \/><\/p><\/blockquote>\n<p><strong>\u6ce8\uff1a<br \/>\n<\/strong>HTTP Digest\u4e0eWSSE\u8ba4\u8bc1\u6765\u6e90\u00a0<a href=\"http:\/\/bbs.csdn.net\/topics\/391065361?page=1\" target=\"_blank\" rel=\"noopener\">http-wsse\u548chttp-digest\u4e24\u79cd\u8ba4\u8bc1\u65b9\u5f0f\u7684\u533a\u522b<\/a><\/p>\n<h1>\u652f\u4ed8\u63a5\u53e3\u5b89\u5168\u6027[\u670d\u52a1\u7aef\u5bf9\u670d\u52a1\u7aef]<\/h1>\n<p>\u652f\u4ed8\u5b9d:\u7edf\u4e00\u63a5\u53e3\u7f51\u5173,RSA\u53cc\u5411\u7b7e\u540d\u9a8c\u8bc1<\/p>\n<p>\u5fae\u4fe1:API KEY\u65b9\u5f0f+\u6570\u5b57\u8bc1\u4e66<\/p>\n<p>\u94f6\u8054:RSA+\u6570\u5b57\u8bc1\u4e66<\/p>\n<h1>App\u9002\u7528\u7684\u6388\u6743\u65b9\u5f0f<\/h1>\n<ul>\n<li>\u8ddf\u7528\u6237\u6ca1\u6709\u5173\u7cfb\u7684\u8d44\u6e90 Client Credentials,HMAC\u6216API KEY\uff0c\u5982\u679cToken\u88ab\u6293\u5305\u6216APIKEY\u88ab\u53cd\u7f16\u8bd1\uff0c\u4e0d\u4fdd\u8bc1\u5b89\u5168\u6027\uff0c\u4f46\u662f\u53ef\u4ee5\u675c\u7edd\u5927\u90e8\u5206\u7684\u5783\u573e\u8bf7\u6c42\u3002<\/li>\n<li>\u8ddf\u7528\u6237\u6709\u5173\u7cfb\u7684\u8d44\u6e90 Resource Owner Password Credentials<\/li>\n<li>\u57fa\u4e8eJWT\u5b9e\u73b0<\/li>\n<li>\u57fa\u4e8eResource Owner Password Credentials \u81ea\u5b9a\u4e49\u5b9e\u73b0\u53d1\u653eToken<\/li>\n<\/ul>\n<h1>ASP.NET WBAPI\u8d44\u6e90\u5b89\u5168\u8bbe\u8ba1<\/h1>\n<p>Securing ASP.NET Web APIs<\/p>\n<p><a href=\"http:\/\/sddconf.com\/brands\/sdd\/library\/Securing_ASPdotNET_web_APIs.pdf\">http:\/\/sddconf.com\/brands\/sdd\/library\/Securing_ASPdotNET_web_APIs.pdf<\/a><\/p>\n<p>Pro ASP.NET Web API Security<\/p>\n<h1>\u670d\u52a1\u8bbe\u8ba1\u53c2\u8003<\/h1>\n<p>Github<br \/>\n<a href=\"https:\/\/developer.github.com\/v3\/\">https:\/\/developer.github.com\/v3\/<\/a><br \/>\nAPI V3 \u4e0a\u7ebf\uff0c\u5b9e\u73b0 OAuth 2 \u8ba4\u8bc1<br \/>\n<a href=\"https:\/\/ruby-china.org\/topics\/25630\">https:\/\/ruby-china.org\/topics\/25630<\/a><br \/>\n\u6709\u8d5e API \u6587\u6863\u3010appkey\u4e0eoauth2\u3011<br \/>\n<a href=\"http:\/\/open.koudaitong.com\/doc\">http:\/\/open.koudaitong.com\/doc<\/a><\/p>\n<blockquote><p>REFER:<br \/>\n[\u8bd1]web\u6743\u9650\u9a8c\u8bc1\u65b9\u6cd5\u8bf4\u660e<br \/>\n<a href=\"http:\/\/segmentfault.com\/a\/1190000004086946\">http:\/\/segmentfault.com\/a\/1190000004086946<\/a><br \/>\n\u5f00\u653e\u63a5\u53e3\u7684\u5b89\u5168\u9a8c\u8bc1\u65b9\u6848(AES+RSA)<br \/>\n<a href=\"http:\/\/wustrive2008.github.io\/2015\/08\/21\/%E5%BC%80%E6%94%BE%E6%8E%A5%E5%8F%A3%E7%9A%84%E5%AE%89%E5%85%A8%E9%AA%8C%E8%AF%81%E6%96%B9%E6%A1%88%28AES+RSA%29\/\">http:\/\/wustrive2008.github.io\/2015\/08\/21\/%E5%BC%80%E6%94%BE%E6%8E%A5%E5%8F%A3%E7%9A%84%E5%AE%89%E5%85%A8%E9%AA%8C%E8%AF%81%E6%96%B9%E6%A1%88%28AES+RSA%29\/<\/a><br \/>\nRESTful Api \u8eab\u4efd\u8ba4\u8bc1\u5b89\u5168\u6027\u8bbe\u8ba1<br \/>\n<a href=\"http:\/\/mengkang.net\/625.html\">http:\/\/mengkang.net\/625.html<\/a><\/p>\n<p>\u5927\u8bdd\u63a5\u53e3\u9690\u79c1\u4e0e\u5b89\u5168<br \/>\nhttps:\/\/blog.thankbabe.com\/2016\/06\/05\/donot-touch-my-url\/<\/p>\n<p>API \u5ba2\u6237\u7aef\u8ba4\u8bc1\u90a3\u4e9b\u4e8b<\/p>\n<p><a href=\"http:\/\/mousycoder.com\/2016\/02\/22\/api-authentication\/\" target=\"_blank\" rel=\"noopener\">http:\/\/mousycoder.com\/2016\/02\/22\/api-authentication\/<\/a><br \/>\nREST API Authentication<br \/>\n<a href=\"http:\/\/stackoverflow.com\/questions\/7999295\/rest-api-authentication\">http:\/\/stackoverflow.com\/questions\/7999295\/rest-api-authentication<\/a><br \/>\nBest Practices for securing a REST API \/ web service<br \/>\n<a href=\"http:\/\/stackoverflow.com\/questions\/7551\/best-practices-for-securing-a-rest-api-web-service\">http:\/\/stackoverflow.com\/questions\/7551\/best-practices-for-securing-a-rest-api-web-service<\/a><br \/>\nBest practices for API versioning<br \/>\n<a href=\"http:\/\/stackoverflow.com\/questions\/389169\/best-practices-for-api-versioning\">http:\/\/stackoverflow.com\/questions\/389169\/best-practices-for-api-versioning<\/a><\/p><\/blockquote>\n<p>&nbsp;<\/p>\n<p>https:\/\/www.cnblogs.com\/Irving\/p\/4964489.html<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5e38\u7528\u8ba4\u8bc1\u65b9\u5f0f \u5728\u4e4b\u524d\u7684\u6587\u7ae0REST API \u5b89\u5168\u8bbe\u8ba1\u6307\u5357\u4e0e\u4f7f\u7528 AngularJS &amp; NodeJS \u5b9e\u73b0\u57fa\u4e8e token \u7684\u8ba4\u8bc1\u5e94\u7528\u4e24\u7bc7\u6587\u7ae0\u4e2d\uff0c[\u8bd1]web\u6743\u9650\u9a8c\u8bc1\u65b9\u6cd5\u8bf4\u660e\u4e2d\u4e5f\u8be6\u7ec6\u4ecb\u7ecd\uff0c\u4e00\u822c\u57fa\u4e8eREST API \u5b89\u5168\u8bbe\u8ba1\u5e38\u7528\u65b9\u5f0f\u6709\uff1a HTTP Basic Basic admin:admin Basic YWRtaW46YWRtaW4= Authorization: Basic [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[1],"tags":[],"class_list":["post-811","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/blog.jsjs.org\/index.php?rest_route=\/wp\/v2\/posts\/811","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.jsjs.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.jsjs.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.jsjs.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.jsjs.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=811"}],"version-history":[{"count":0,"href":"https:\/\/blog.jsjs.org\/index.php?rest_route=\/wp\/v2\/posts\/811\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.jsjs.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=811"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.jsjs.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=811"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.jsjs.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=811"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}