{"id":48651,"date":"2024-12-02T13:05:01","date_gmt":"2024-12-02T05:05:01","guid":{"rendered":"https:\/\/fwq.ai\/blog\/48651\/"},"modified":"2024-12-02T13:05:01","modified_gmt":"2024-12-02T05:05:01","slug":"authorization-%e8%af%b7%e6%b1%82%e5%a4%b4%e5%a6%82%e4%bd%95%e6%ad%a3%e7%a1%ae%e7%9a%84%e8%ae%be%e7%bd%ae-access-token%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/48651\/","title":{"rendered":"Authorization \u8bf7\u6c42\u5934\u5982\u4f55\u6b63\u786e\u7684\u8bbe\u7f6e Access Token\uff1f"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>Authorization \u8bf7\u6c42\u5934\u5982\u4f55\u6b63\u786e\u7684\u8bbe\u7f6e Access Token\uff1f<\/h1>\n<p><span style=\"cursor: pointer\"><i><\/i>\u6536\u85cf<\/span> <\/p>\n<p>\u4ece\u73b0\u5728\u5f00\u59cb\uff0c\u6211\u4eec\u8981\u52aa\u529b\u5b66\u4e60\u5566\uff01\u4eca\u5929\u6211\u7ed9\u5927\u5bb6\u5e26\u6765<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300aAuthorization \u8bf7\u6c42\u5934\u5982\u4f55\u6b63\u786e\u7684\u8bbe\u7f6e Access Token\uff1f\u300b<\/span>\uff0c\u611f\u5174\u8da3\u7684\u670b\u53cb\u8bf7\u7ee7\u7eed\u770b\u4e0b\u53bb\u5427\uff01\u4e0b\u6587\u4e2d\u7684\u5185\u5bb9\u6211\u4eec\u4e3b\u8981\u4f1a\u6d89\u53ca\u5230<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\u7b49\u7b49\u77e5\u8bc6\u70b9\uff0c\u5982\u679c\u5728\u9605\u8bfb\u672c\u6587\u8fc7\u7a0b\u4e2d\u6709\u9047\u5230\u4e0d\u6e05\u695a\u7684\u5730\u65b9\uff0c\u6b22\u8fce\u7559\u8a00\u5440\uff01\u6211\u4eec\u4e00\u8d77\u8ba8\u8bba\uff0c\u4e00\u8d77\u5b66\u4e60\uff01<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241029\/173019029567209bd7b97a2.jpg\" class=\"aligncenter\" title=\"Authorization \u8bf7\u6c42\u5934\u5982\u4f55\u6b63\u786e\u7684\u8bbe\u7f6e Access Token\uff1f\u63d2\u56fe\" alt=\"Authorization \u8bf7\u6c42\u5934\u5982\u4f55\u6b63\u786e\u7684\u8bbe\u7f6e Access Token\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>github \u4e09\u65b9\u6388\u6743\u767b\u5f55 access token \u4f7f\u7528<\/strong><\/p>\n<p>\u5728\u8fdb\u884c github \u4e09\u65b9\u6388\u6743\u767b\u5f55\u65f6\uff0c\u7528\u6237\u9700\u8981\u63d0\u4f9b\u6765\u81ea github \u7684 access token\u3002access token \u5e94\u8be5\u88ab\u653e\u7f6e\u5728\u8bf7\u6c42\u5934\u7684 authorization \u5b57\u6bb5\u4e2d\uff0c\u6b63\u786e\u683c\u5f0f\u5982\u4e0b\uff1a<\/p>\n<pre>authorization: bearer eyjhbgcioijsuzi1niisinr5cci6ikpxvcj9.eyjzdwiioiixmjm0nty3odkwiiwibmftzsi6ikpvag4grg9liiwiawf0ijoxnte2mjm5mdiylcjlehaioje1mtyyndi2mjj9.pxofpu1c-a2wnp1bwkdm7gkks_ldyznpq388cjrdahh5u5g7p40tm137dy28utc7iv2o1wd9dg-x6efudic45ge04vcnrfatljati0j909sg6pmwhaxqvn-3p-1z008nskonwrwh7zn51wbkk9sgfh74phrb6za3izicfbtzwy<\/pre>\n<p>\u4ece\u4ee3\u7801\u793a\u4f8b\u4e2d\u53ef\u4ee5\u770b\u5230\uff0c\u4f7f\u7528\u4e86\u9519\u8bef\u7684\u683c\u5f0f\uff1a<\/p>\n<pre>private async getgithubuserinfo(accesstoken) {\n    const {ctx} = this;\n    \/\/ \u4f7f\u7528accesstoken\u53bb\u83b7\u53d6\u8d44\u6e90  get https:\/\/api.github.com\/user\n    const baseurl = 'https:\/\/api.github.com\/user';\n    let res = await ctx.curl(baseurl, {\n      method: 'get',\n      headers: {\n        'authorization': accesstoken\n      }\n    })\n    console.log(res);\n  }<\/pre>\n<p>\u6b63\u786e\u7684\u683c\u5f0f\u5e94\u8be5\u662f\uff1a<\/p>\n<pre>private async getGithubUserInfo(accessToken) {\n    const {ctx} = this;\n    \/\/ \u4f7f\u7528accessToken\u53bb\u83b7\u53d6\u8d44\u6e90  GET https:\/\/api.github.com\/user\n    const baseURL = 'https:\/\/api.github.com\/user';\n    let res = await ctx.curl(baseURL, {\n      method: 'GET',\n      headers: {\n        'Authorization': \"Bearer \" + accessToken\n      }\n    })\n    console.log(res);\n  }<\/pre>\n<p>\u4ee5\u4e0a\u5c31\u662f\u672c\u6587\u7684\u5168\u90e8\u5185\u5bb9\u4e86\uff0c\u662f\u5426\u6709\u987a\u5229\u5e2e\u52a9\u4f60\u89e3\u51b3\u95ee\u9898\uff1f\u82e5\u662f\u80fd\u7ed9\u4f60\u5e26\u6765\u5b66\u4e60\u4e0a\u7684\u5e2e\u52a9\uff0c\u8bf7\u5927\u5bb6\u591a\u591a\u652f\u6301\u7c73\u4e91\uff01\u66f4\u591a\u5173\u4e8e\u6587\u7ae0\u7684\u76f8\u5173\u77e5\u8bc6\uff0c\u4e5f\u53ef\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\u3002<\/p>\n<p> \u7248\u672c\u58f0\u660e \u672c\u6587\u8f6c\u8f7d\u4e8e\uff1aphp \u5982\u6709\u4fb5\u72af\uff0c\u8bf7\u8054\u7cfb \u5220\u9664<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Authorization \u8bf7\u6c42\u5934\u5982\u4f55\u6b63\u786e\u7684\u8bbe\u7f6e Access Token\uff1f \u6536\u85cf \u4ece\u73b0\u5728\u5f00\u59cb\uff0c\u6211\u4eec\u8981\u52aa\u529b\u5b66\u4e60\u5566\uff01\u4eca\u5929\u6211\u7ed9\u5927\u5bb6\u5e26\u6765\u300aAuthorization \u8bf7\u6c42\u5934\u5982\u4f55\u6b63\u786e\u7684\u8bbe\u7f6e Access Token\uff1f\u300b\uff0c\u611f\u5174\u8da3\u7684\u670b\u53cb\u8bf7\u7ee7\u7eed\u770b\u4e0b\u53bb\u5427\uff01\u4e0b\u6587\u4e2d\u7684\u5185\u5bb9\u6211\u4eec\u4e3b\u8981\u4f1a\u6d89\u53ca\u5230\u7b49\u7b49\u77e5\u8bc6\u70b9\uff0c\u5982\u679c\u5728\u9605\u8bfb\u672c\u6587\u8fc7\u7a0b\u4e2d\u6709\u9047\u5230\u4e0d\u6e05\u695a\u7684\u5730\u65b9\uff0c\u6b22\u8fce\u7559\u8a00\u5440\uff01\u6211\u4eec\u4e00\u8d77\u8ba8\u8bba\uff0c\u4e00\u8d77\u5b66\u4e60\uff01 github \u4e09\u65b9\u6388\u6743\u767b\u5f55 access token \u4f7f\u7528 \u5728\u8fdb\u884c github \u4e09\u65b9\u6388\u6743\u767b\u5f55\u65f6\uff0c\u7528\u6237\u9700\u8981\u63d0\u4f9b\u6765\u81ea github \u7684 access token\u3002access token \u5e94\u8be5\u88ab\u653e\u7f6e\u5728\u8bf7\u6c42\u5934\u7684 authorization \u5b57\u6bb5\u4e2d\uff0c\u6b63\u786e\u683c\u5f0f\u5982\u4e0b\uff1a authorization: bearer eyjhbgcioijsuzi1niisinr5cci6ikpxvcj9.eyjzdwiioiixmjm0nty3odkwiiwibmftzsi6ikpvag4grg9liiwiawf0ijoxnte2mjm5mdiylcjlehaioje1mtyyndi2mjj9.pxofpu1c-a2wnp1bwkdm7gkks_ldyznpq388cjrdahh5u5g7p40tm137dy28utc7iv2o1wd9dg-x6efudic45ge04vcnrfatljati0j909sg6pmwhaxqvn-3p-1z008nskonwrwh7zn51wbkk9sgfh74phrb6za3izicfbtzwy \u4ece\u4ee3\u7801\u793a\u4f8b\u4e2d\u53ef\u4ee5\u770b\u5230\uff0c\u4f7f\u7528\u4e86\u9519\u8bef\u7684\u683c\u5f0f\uff1a private async getgithubuserinfo(accesstoken) { const {ctx} = this; \/\/ \u4f7f\u7528accesstoken\u53bb\u83b7\u53d6\u8d44\u6e90 get https:\/\/api.github.com\/user const baseurl = &#8216;https:\/\/api.github.com\/user&#8217;; let res = await ctx.curl(baseurl, { method: &#8216;get&#8217;, headers: { [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-48651","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/48651","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=48651"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/48651\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=48651"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=48651"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=48651"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}