通过节点获取Github访问令牌(无浏览器)

时间:2019-09-10 16:28:33

标签: node.js oauth access-token github-api

使用<table> <tr class="top"> <th></th> <th>Monday</th> <th>Tuesday</th> <th class="wed">Wednesday</th> <th>Thursday</th> <th>Friday</th> <th>Saturday</th> </tr> <tr> <td class="noedit" colspan="3"></td> <td class="noedit" id="block-b">Meeting</td> <td class="noedit" colspan="3"></td> </tr> <tr> <th>Period 1</th> <td id="p1d1" tabindex=1>text of p1d1</td> <td id="p1d2" tabindex=2>text of p1d2</td> <td id="p1d3" tabindex=3>text of p1d3</td> <td id="p1d4" tabindex=4>text of p1d4</td> <td id="p1d5" tabindex=5>text of p1d5</td> <td id="p1d6" tabindex=6>text of p1d6</td> </tr> <tr> <th>Period 2</th> <td id="p2d1"></td> <td id="p2d2"></td> <td id="p2d3"></td> <td id="p2d4"></td> <td id="p2d5"></td> <td id="p2d6"></td> </tr> <tr> <th></th> <td class="noedit">Chapel</td> <td class="noedit">Meeting or Advisory</td> <td class="noedit">Advisory</td> <td class="noedit">Class Meeting</td> <td class="noedit">or Advisory</td> <td class="noedit">Break</td> </tr> <tr> <th>Period 3</th> <td id="p3d1"></td> <td id="p3d2"></td> <td id="p3d3"></td> <td id="p3d4"></td> <td id="p3d5"></td> <td id="p3d6"></td> </tr> <tr> <th>Period 4</th> <td id="p4d1"></td> <td id="p4d2"></td> <td id="p4d3"></td> <td id="p4d4"></td> <td id="p4d5"></td> <td id="p4d6"></td> </tr> <tr> <th>Period 5a</th> <td id="p5ad1"></td> <td id="p5ad2"></td> <td class="noedit" rowspan="4"></td> <td id="p5ad4"></td> <td id="p5ad5"></td> </tr> <tr> <th>Period 5b</th> <td id="p5bd1"></td> <td id="p5bd2"></td> <td id="p5bd4"></td> <td id="p5bd5"></td> </tr> <tr> <th>Period 6</th> <td id="p6d1"></td> <td id="p6d2"></td> <td id="p6d4"></td> <td id="p6d5"></td> </tr> <tr> <th>Period 7</th> <td id="p7d1"></td> <td id="p7d2"></td> <td id="p7d4"></td> <td id="p7d5"></td> </tr> </table>https://github.com/login/oauth/authorizeclient_id,我可以通过cURL和浏览器获取访问令牌。

我正在尝试将该过程完全转换为Node.js,但是,我始终无法获得正确的URL来工作:redirect_uri

我目前正在使用node-fetch发出请求,因为我正在尝试学习该过程并推迟使用它的库。

https://github.com/login/oauth/authorize?client_id=<MY_CLIENT_ID>&redirect_uri=http://localhost:3000/some/callback&state=<RANDOM_STRING>

我希望找到一种方法,能够使用访问令牌重定向到我的回调。目前,我正在

const node = require('node-fetch');

let githubURI = `https://github.com/login/oauth/authorize?client_id=${process.env.GITHUB_CLIENT_ID}&redirect_uri=${process.env.GITHUB_REDIRECT_URI}`;

fetch(githubURI, {
    method: 'GET',
    headers: {
      accept: 'application/json'
    }
  })
  .then(response => response)
  .then(data => {
    console.log(data);
  })
  .catch(error => console.error(error));

0 个答案:

没有答案