Home > Uncategorized > Google #OAuth Login using #PhantomJS

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.open(‘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);
var passwordId = “Passwd”;
var elPassword = document.getElementById(passwordId);
elPassword.value = “xxxxxxx”;
var btnNext = document.getElementById(“signIn”);
page.onLoadFinished = function(){
var btnAllow = “submit_approve_access”;
var elAllow = document.getElementById(btnAllow);

page.onLoadFinished = function(){
// Now you can continue processing.

Categories: Uncategorized
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: