Answer the question
In order to leave comments, you need to log in
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);
});
});
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question