Introduction
In this article, we will discuss how to make an MSA (Microsoft Account) account launch browser using Edge or Chrome with IIS (Internet Information Services) and Windows Authentication through Puppeteer.
Prerequisites
- Node.js and NPM installed
- Puppeteer package installed
- IIS with Windows Authentication enabled
Setting up the Project
Create a new directory for your project and initialize it with npm. Install Puppeteer as a dependency.
mkdir puppeteer-msa-auth
cd puppeteer-msa-auth
npm init -y
npm install puppeteer
Creating a simple Express server
Create a new file named 'server.js' and set up a simple Express server that will handle the Windows Authentication and launch the browser using Puppeteer.
const express = require('express'); const app = express(); const port = process.env.PORT || 3000;app.get('/', (req, res) => { if (req.isAuthenticated()) { const { user, password } = req.user; (async () => { const browser = await puppeteer.launch({ headless: false }); const page = await browser.newPage(); await page.goto('https://msa.example.com'); await page.type('#username', user); await page.type('#password', password); await page.click('#login-button'); await browser.close(); })(); } else { res.redirect('/login'); } });
app.get('/login', (req, res) => { res.sendFile('login.html'); });
app.listen(port, () => { console.log(Server running at http://localhost:${port}); });
Setting up IIS
Configure IIS to use the Node.js Express server as the application.
Creating a login page
Create a new file named 'login.html' and set up a simple login page that will be used to authenticate the user with Windows Authentication.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Login</title>
</head>
<body>
<form action="/login" method="get">
<input type="hidden" name="_wauthenticator" value="true" />
<input type="submit" value="Login" />
</form>
</body>
</html>
Running the Application
Start the Express server by running 'node server.js'.
Testing the Application
Open your browser and visit 'http://localhost:3000'. You will be redirected to the login page. Log in with your MSA account credentials. The browser will launch and log in to 'https://msa.example.com' using the provided credentials.
In this article, we learned how to make an MSA account launch browser using Edge or Chrome with IIS and Windows Authentication through Puppeteer. We created a simple Express server that handles the Windows Authentication and launches the browser using Puppeteer.