#LinkedIn #OAUTH Login using #PhantomJS
Say you wanted to authenticate yourself against a website that used LinkedIn OAuth for authentication, tricky ?, well, not too bad if you are using PhantomJS.
I’ve elided a bit of information below (in bold), since I’m not going to put my LinkedIn password up on this blog 🙂
var page = require(‘webpage’).create();
page.open(‘https://www.linkedin.com/uas/oauth2/authorization?redirect_uri=http://othersite.com&client_id=THEIR CLIENT ID&scope=r_emailaddress%20r_basicprofile&response_type=code&state=THEIR STATE‘, function (status) {
console.log(“opened linkedin page”);
page.evaluate(function() {
var usernameField = “session_key-oauth2SAuthorizeForm”;
var elUsername = document.getElementById(usernameField);
elUsername.value = ‘XXXXX@gmail.com‘
var passwordField = “session_password-oauth2SAuthorizeForm”;
var elPassword = document.getElementById(passwordField);
elPassword.value=”XXXXXX“;
var elForm = document.querySelector(“form”);
elForm.submit();
});
page.onLoadFinished = function(){
console.log(“Logged in”);
page.render(“linkedin-2.png”);
step2();
};
});