Last active
August 29, 2015 13:55
-
-
Save Zirak/8729829 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"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