DaWasaBi
DaWasaBi

Reputation: 1

GitHub OAuth last step issue

If I paste the following Url into Safari:

https://github.com/login/oauth/access_token?client_id=abf35093bb766b063810&client_secret=XYZ&code=XYZ

-> I get a 200 response and a stream with the text of "error=incorrect_client_credentials", which is what I expect.

If I run the following Node.js code (which I wrote to do the same thing), I get a 400 response and an error page. I can't figure out what can go wrong... Please help...

var options = {
  hostname: 'github.com',
  port: 443,
  path: 'login/oauth/access_token?client_id=abf35093bb766b063810&client_secret=XYZ&code=XYZ',
  method: 'GET',
  headers: {'user-agent': 'node.js'},
  Accept: '*/*'
};

var req = https.request(options, function(res) {

  res.setEncoding('utf-8');
  var responseString = '';

  res.on('data', function(data) {
    responseString += data;
  });

  res.on('end', function() {
    console.log(responseString);
    console.log('Response ' + res.statusCode);      
  });
});

req.end();

Upvotes: 0

Views: 72

Answers (1)

DaWasaBi
DaWasaBi

Reputation: 1

OK, got to the bottom of it.

2 errors:

  1. In the path, I should start the Url with a /
  2. The Accept goes to the headers

It's working now...

Upvotes: 0

Related Questions