A
A
Archakov Dennis2016-12-23 23:05:15
Node.js
Archakov Dennis, 2016-12-23 23:05:15

How to make authorization on GitHub + NodeJS?

I'm trying to log in to Github (not OAuth), through a simple site authorization form.
To work with HTTP, I use the unirest + cheerio library to parse the token.

var unirest = require('unirest');
var cheerio = require("cheerio");

var login = 'ЛОГИН';
var password = 'ПАРОЛЬ';
var cookies = '';

unirest.get('https://github.com/login')
.headers({
  'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36'
})
.end(function (response) {

  var $ = cheerio.load(response.body);
  var token = $("input[name='authenticity_token']").val();

  var headers = {
    'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36',
    'Content-Type': 'application/x-www-form-urlencoded',
    'Cookie': '_gh_sess='+response.cookies._gh_sess,
  };

  var post_data = {
    'authenticity_token': token,
    'login': login,
    'password': password
  };

  unirest.post('https://github.com/session')
  .headers(headers)
  .send(post_data)
  .end(function (response) {

    console.log(response.cookies);

  });
});

I get an error in response + cookies are empty. Although I'm testing through Paw (or any other software for working with HTTP request testing and there are norms).
The response from the server should be something like this:
619cd66fb8114f65a9cfe16898a12ee0.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
pecmapm, 2016-12-28
@archakov06

Perhaps it will help.
How to login Amazon using PhantomJS – Working example
How to login to Amazon using CasperJS – Working example

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question