commit 15ae3a5a5de4b24f73f206bcac6d2485f2de238d Author: Simon Vieille Date: Thu Aug 25 12:30:10 2022 +0200 init diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2b7d8ef --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/node_modules +/login diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..aec1fab --- /dev/null +++ b/Makefile @@ -0,0 +1,3 @@ +setup: + npm i -D @playwright/test + npm i playwright diff --git a/README.md b/README.md new file mode 100644 index 0000000..6727157 --- /dev/null +++ b/README.md @@ -0,0 +1,31 @@ +Office365 OAuth2 authenticator +============================== + +This project retrieves cookies used to authenticate an user on Sharepoint Online. + +## Requirements + +Tested with NodeJS 16+. + +## Installation + +``` +$ git clone https://gitnet.fr/deblan/office365-oauth2-authenticator-2.git +$ cd office365-oauth2-authenticator +$ make setup +``` + +## Configuration + +``` +$ cp login.example login +$ chmod +x login +``` + +Edit `login` and replace values of: + +* MS_OFFICE365_SITE +* MS_OFFICE365_LOGIN +* MS_OFFICE365_PASSWORD + +Then run `./login`. diff --git a/index.js b/index.js new file mode 100644 index 0000000..f7e251f --- /dev/null +++ b/index.js @@ -0,0 +1,43 @@ +const playwright = require('playwright'); + +const site = process.env.MS_OFFICE365_SITE; +const password = process.env.MS_OFFICE365_PASSWORD; +const login = process.env.MS_OFFICE365_LOGIN; + +(async () => { + const browser = await playwright.chromium.launch(); + const context = await browser.newContext(); + const page = await context.newPage(); + + await page.goto(site); + + // fill username + await page.locator('input[name="loginfmt"]').fill(login); + await page.locator('input[type="submit"]').click(); + // fill password + await page.locator('input[name="passwd"]').fill(password); + await page.locator('input[type="submit"]').click(); + // submit remember + await page.locator('input[type="submit"]').click(); + await page.waitForNavigation(); + + const cookies = await page.context().cookies(); + await browser.close(); + + let output = { + rtFa: null, + FedAuth: null, + }; + + for (let cookie of cookies) { + if (cookie.name === 'rtFa') { + output.rtFa = cookie.value; + } + if (cookie.name === 'FedAuth') { + output.FedAuth = cookie.value; + } + } + + console.log(JSON.stringify(output, 2)); + +})(); diff --git a/login.example b/login.example new file mode 100755 index 0000000..07d015a --- /dev/null +++ b/login.example @@ -0,0 +1,7 @@ +#!/bin/sh + +export MS_OFFICE365_SITE="https://foo.sharepoint.com/" +export MS_OFFICE365_LOGIN="user@example.com" +export MS_OFFICE365_PASSWORD="5eCrEt" + +node ./index.js diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..e19d75f --- /dev/null +++ b/package-lock.json @@ -0,0 +1,94 @@ +{ + "name": "office365-oauth2-authenticator-2", + "lockfileVersion": 2, + "requires": true, + "packages": { + "": { + "dependencies": { + "playwright": "^1.25.1" + }, + "devDependencies": { + "@playwright/test": "^1.25.1" + } + }, + "node_modules/@playwright/test": { + "version": "1.25.1", + "resolved": "https://registry.npmjs.org/@playwright/test/-/test-1.25.1.tgz", + "integrity": "sha512-IJ4X0yOakXtwkhbnNzKkaIgXe6df7u3H3FnuhI9Jqh+CdO0e/lYQlDLYiyI9cnXK8E7UAppAWP+VqAv6VX7HQg==", + "dev": true, + "dependencies": { + "@types/node": "*", + "playwright-core": "1.25.1" + }, + "bin": { + "playwright": "cli.js" + }, + "engines": { + "node": ">=14" + } + }, + "node_modules/@types/node": { + "version": "18.7.13", + "resolved": "https://registry.npmjs.org/@types/node/-/node-18.7.13.tgz", + "integrity": "sha512-46yIhxSe5xEaJZXWdIBP7GU4HDTG8/eo0qd9atdiL+lFpA03y8KS+lkTN834TWJj5767GbWv4n/P6efyTFt1Dw==", + "dev": true + }, + "node_modules/playwright": { + "version": "1.25.1", + "resolved": "https://registry.npmjs.org/playwright/-/playwright-1.25.1.tgz", + "integrity": "sha512-kOlW7mllnQ70ALTwAor73q/FhdH9EEXLUqjdzqioYLcSVC4n4NBfDqeCikGuayFZrLECLkU6Hcbziy/szqTXSA==", + "hasInstallScript": true, + "dependencies": { + "playwright-core": "1.25.1" + }, + "bin": { + "playwright": "cli.js" + }, + "engines": { + "node": ">=14" + } + }, + "node_modules/playwright-core": { + "version": "1.25.1", + "resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.25.1.tgz", + "integrity": "sha512-lSvPCmA2n7LawD2Hw7gSCLScZ+vYRkhU8xH0AapMyzwN+ojoDqhkH/KIEUxwNu2PjPoE/fcE0wLAksdOhJ2O5g==", + "bin": { + "playwright": "cli.js" + }, + "engines": { + "node": ">=14" + } + } + }, + "dependencies": { + "@playwright/test": { + "version": "1.25.1", + "resolved": "https://registry.npmjs.org/@playwright/test/-/test-1.25.1.tgz", + "integrity": "sha512-IJ4X0yOakXtwkhbnNzKkaIgXe6df7u3H3FnuhI9Jqh+CdO0e/lYQlDLYiyI9cnXK8E7UAppAWP+VqAv6VX7HQg==", + "dev": true, + "requires": { + "@types/node": "*", + "playwright-core": "1.25.1" + } + }, + "@types/node": { + "version": "18.7.13", + "resolved": "https://registry.npmjs.org/@types/node/-/node-18.7.13.tgz", + "integrity": "sha512-46yIhxSe5xEaJZXWdIBP7GU4HDTG8/eo0qd9atdiL+lFpA03y8KS+lkTN834TWJj5767GbWv4n/P6efyTFt1Dw==", + "dev": true + }, + "playwright": { + "version": "1.25.1", + "resolved": "https://registry.npmjs.org/playwright/-/playwright-1.25.1.tgz", + "integrity": "sha512-kOlW7mllnQ70ALTwAor73q/FhdH9EEXLUqjdzqioYLcSVC4n4NBfDqeCikGuayFZrLECLkU6Hcbziy/szqTXSA==", + "requires": { + "playwright-core": "1.25.1" + } + }, + "playwright-core": { + "version": "1.25.1", + "resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.25.1.tgz", + "integrity": "sha512-lSvPCmA2n7LawD2Hw7gSCLScZ+vYRkhU8xH0AapMyzwN+ojoDqhkH/KIEUxwNu2PjPoE/fcE0wLAksdOhJ2O5g==" + } + } +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..c5c01aa --- /dev/null +++ b/package.json @@ -0,0 +1,8 @@ +{ + "devDependencies": { + "@playwright/test": "^1.25.1" + }, + "dependencies": { + "playwright": "^1.25.1" + } +}