Norway


Home
> Uncategorized > #OAuth Login using #

Google #OAuth Login using #PhantomJS

articleocw-5860f28ac5f1c  - articleocw 5860f28ac5f1c - Google #OAuth Login using #PhantomJS

So here’s some handy code to use PhantomJS to perform a Google OAuth Login in a headless browser. The exact login url and username/password have been omitted from this example;

page.(‘https://accounts.google.com/o/oauth2/auth?redirect_uri=http://……’, function (status) {

page.evaluate(function() {
var usernameField = “Email”;
var elUsername = document.getElementById(usernameField);
elUsername.value = ‘xxxx@gmail.com’;
var buttonId = “next”;
var elNext = document.getElementById(buttonId);
elNext.click();
setTimeout(function(){
var passwordId = “Passwd”;
var elPassword = document.getElementById(passwordId);
elPassword.value = “xxxxxxx”;
var btnNext = document.getElementById(“signIn”);
btnNext.click();
},2000);
});
page.onLoadFinished = function(){
page.evaluate(function(){
setTimeout(function(){
var btnAllow = “submit_approve_access”;
var elAllow = document.getElementById(btnAllow);
elAllow.click();

},2000);
});
page.onLoadFinished = function(){
// Now you can continue processing.
};
};
});



Source link

LEAVE A REPLY

Please enter your comment!
Please enter your name here