Git Product home page Git Product logo

headless2fa's Introduction

Headless 2FA

  • install modules using NPM $ npm install
  • run debug $ node debug.js
  • follow the instructions

Motivation

Sometimes you need to run headless tasks into some webservices or websites with 2FA authentication, like SMS or e-mail. Thus you feel stucked at some point how to run this routines into headless, this tiny snnipet allow you to do it.

If you are recurrent visitor on my repositories you will realize i always use TotalJS for structure my codes, and develop what i want as an module of this, that way it's easy to import on another project.

Check that routine into:

> /modules/headless2FA.js
//EMBEDED LIBRARIES
const readline = require("readline");
const puppeteer = require('puppeteer');
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});

/*
Waiting all TotalJS configurations be ready 
*/
ON('ready', function() { 

	/*
	Function to askToken from user
	*/
	function askToken(questionText) {
		console.log("[Token] - Asking token from user input");
	  	return new Promise((resolve, reject) => {
	    	rl.question("\nWhat is the token received?", (input) => {
	    		rl.close();
	    		resolve(input);
	    	});
	  	});
	}

	/*
	Lauching Puppeter to get page and send Token
	*/
	puppeteer.launch({headless : false}).then(async browser => {
	  	const page = await browser.newPage();
		console.log("[Browser] - Opening");
	  	await page.goto('https://www.google.com');
	  	await page.setViewport({width: 800, height: 600});
		console.log("[Browser] - Page is open and start operations to take token");
	  	const token = await askToken();
		console.log("\n[Token] - configured token is: "+token);
		console.log("[Browser] - KeepGoing with alredy configured token");
		/*
			USE HERE YOUR ALREDY CONFIGURED GLOBAL TOKEN TO CONTINUE
			YOUR CODE EXECUTION
		*/
		console.log("[Browser] - Closing");
	  	await browser.close();
	});

});

headless2fa's People

Contributors

joaomirandas avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.