{"id":807,"date":"2024-11-07T12:48:54","date_gmt":"2024-11-07T04:48:54","guid":{"rendered":"https:\/\/fwq.ai\/blog\/807\/"},"modified":"2024-11-07T12:48:54","modified_gmt":"2024-11-07T04:48:54","slug":"%e4%bd%bf%e7%94%a8-github-%e4%b8%89%e6%96%b9%e6%8e%88%e6%9d%83%e7%99%bb%e5%bd%95%e6%97%b6-authorization-%e5%ad%97%e6%ae%b5%e7%9a%84%e6%ad%a3%e7%a1%ae%e6%a0%bc%e5%bc%8f%e6%98%af%e4%bb%80%e4%b9%88","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/807\/","title":{"rendered":"\u4f7f\u7528 Github \u4e09\u65b9\u6388\u6743\u767b\u5f55\u65f6 Authorization \u5b57\u6bb5\u7684\u6b63\u786e\u683c\u5f0f\u662f\u4ec0\u4e48\uff1f"},"content":{"rendered":"<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1097\" src=\"https:\/\/fwq.ai\/blog\/wp-content\/uploads\/2024\/11\/172976461926199.jpg\" width=\"720\" height=\"288\" srcset=\"https:\/\/fwq.ai\/blog\/wp-content\/uploads\/2024\/11\/172976461926199.jpg 720w, https:\/\/fwq.ai\/blog\/wp-content\/uploads\/2024\/11\/172976461926199-300x120.jpg 300w, https:\/\/fwq.ai\/blog\/wp-content\/uploads\/2024\/11\/172976461926199-670x268.jpg 670w\" sizes=\"auto, (max-width: 720px) 100vw, 720px\" title=\"\u4f7f\u7528 Github \u4e09\u65b9\u6388\u6743\u767b\u5f55\u65f6 Authorization \u5b57\u6bb5\u7684\u6b63\u786e\u683c\u5f0f\u662f\u4ec0\u4e48\uff1f\u63d2\u56fe\" alt=\"\u4f7f\u7528 Github \u4e09\u65b9\u6388\u6743\u767b\u5f55\u65f6 Authorization \u5b57\u6bb5\u7684\u6b63\u786e\u683c\u5f0f\u662f\u4ec0\u4e48\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>github \u4e09\u65b9\u6388\u6743\u767b\u5f55 access_token \u4f7f\u7528\u95ee\u9898<\/strong><\/p>\n<p>\u5728\u4f7f\u7528 github \u8fdb\u884c\u4e09\u65b9\u767b\u5f55\u65f6\uff0c\u5c06 access token \u653e\u5165\u8bf7\u6c42\u5934\u7684 authorization \u5b57\u6bb5\u5374\u4e00\u76f4\u672a\u6210\u529f\u83b7\u53d6\u5230\u7528\u6237\u7684\u4ee4\u724c\u3002<\/p>\n<p><strong>\u95ee\u9898\u4ee3\u7801<\/strong><\/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> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u89e3\u51b3\u65b9\u6cd5<\/strong><\/p>\n<p>authorization \u5b57\u6bb5\u7684\u683c\u5f0f\u5e94\u4e3a &#8220;bearer &#8221; + accesstoken\uff0c\u6b63\u786e\u7684\u683c\u5f0f\u5982\u4e0b\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> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u4f7f\u7528 Github \u4e09\u65b9\u6388\u6743\u767b\u5f55\u65f6 Authorization \u5b57\u6bb5\u7684\u6b63\u786e\u683c\u5f0f\u662f\u4ec0\u4e48\uff1f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>github \u4e09\u65b9\u6388\u6743\u767b\u5f55 access_token \u4f7f\u7528\u95ee\u9898 \u5728\u4f7f\u7528 github \u8fdb\u884c\u4e09\u65b9\u767b\u5f55\u65f6\uff0c\u5c06 access token \u653e\u5165\u8bf7\u6c42\u5934\u7684 authorization \u5b57\u6bb5\u5374\u4e00\u76f4\u672a\u6210\u529f\u83b7\u53d6\u5230\u7528\u6237\u7684\u4ee4\u724c\u3002 \u95ee\u9898\u4ee3\u7801 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: { &#8216;authorization&#8217;: accesstoken } }) console.log(res); } \u767b\u5f55\u540e\u590d\u5236 \u89e3\u51b3\u65b9\u6cd5 authorization \u5b57\u6bb5\u7684\u683c\u5f0f\u5e94\u4e3a &#8220;bearer &#8221; + accesstoken\uff0c\u6b63\u786e\u7684\u683c\u5f0f\u5982\u4e0b\uff1a private async [&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-807","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/807","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=807"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/807\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=807"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=807"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=807"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}