Skip to content

Instantly share code, notes, and snippets.

@Zirak
Last active August 29, 2015 13:55
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Zirak/8729829 to your computer and use it in GitHub Desktop.
Save Zirak/8729829 to your computer and use it in GitHub Desktop.
"use strict";
var req = require('request' ),
opts = require('./config.json');
twoStepLogin(
'https://openid.stackexchange.com/account/login',
'https://openid.stackexchange.com/account/login/submit');
function twoStepLogin (loginUrl, submitUrl, next) {
//TODO replace horrible regex with an actual DOM lookup.
var fkeyRe = /"fkey"\s+value="([^"]+?)"/;
req.get(loginUrl, loginPageLoaded);
function loginPageLoaded (err, resp, body) {
if (err) {
//fuck.
throw err;
//should probably improve this...
}
var fkey = fkeyRe.exec(body);
submit(fkey);
}
function submit (fkey) {
var outStream = require('fs' ).createWriteStream('out.html');
req.post(submitUrl, submitPageLoaded ).form({
email : opts.username,
password : opts.password,
fkey : fkey
}).pipe(outStream);
}
function submitPageLoaded (err, resp, body) {
//I hate me.
if (err) {
throw err;
}
console.log(resp.headers);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment