Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ut-auth-utils

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ut-auth-utils - npm Package Compare versions

Comparing version 1.1.5 to 2.0.0

19

dist/auth-utils.d.ts

@@ -1,4 +0,6 @@

import * as puppeteer from 'puppeteer-core';
export declare const UT_DIRECT_URL = "https://utdirect.utexas.edu/";
export declare const UT_CANVAS_URL = "https://utexas.instructure.com/";
import * as puppeteer from 'puppeteer';
export declare const UTAustinDestinations: {
UT_DIRECT_URL: string;
UT_CANVAS_URL: string;
};
/**

@@ -8,8 +10,7 @@ * Login graphically with Google Chrome.

*/
export declare function chromeGUIAuthentication(relay_url: string): Promise<puppeteer.Protocol.Network.Cookie[]>;
/**
* Login programmatically with Google Chrome.
* Note: Duo 2FA will still require user input.
*/
export declare function chromeProgrammaticAuthentication(username: string, password: string, relay_url: string): Promise<puppeteer.Protocol.Network.Cookie[]>;
export declare function chromeGUIAuthentication(relay_url: string, cookies?: {
name: string;
value: string;
[k: string]: any;
}[]): Promise<puppeteer.Protocol.Network.Cookie[]>;
//# sourceMappingURL=auth-utils.d.ts.map

@@ -12,7 +12,9 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.chromeProgrammaticAuthentication = exports.chromeGUIAuthentication = exports.UT_CANVAS_URL = exports.UT_DIRECT_URL = void 0;
const puppeteer = require("puppeteer-core");
exports.chromeGUIAuthentication = exports.UTAustinDestinations = void 0;
const puppeteer = require("puppeteer");
const url_1 = require("url");
exports.UT_DIRECT_URL = 'https://utdirect.utexas.edu/';
exports.UT_CANVAS_URL = 'https://utexas.instructure.com/';
exports.UTAustinDestinations = {
UT_DIRECT_URL: 'https://utdirect.utexas.edu/',
UT_CANVAS_URL: 'https://utexas.instructure.com/'
};
/**

@@ -22,10 +24,11 @@ * Login graphically with Google Chrome.

*/
function chromeGUIAuthentication(relay_url) {
function chromeGUIAuthentication(relay_url, cookies) {
return __awaiter(this, void 0, void 0, function* () {
let chrome = yield puppeteer.launch({
channel: 'chrome',
headless: false,
defaultViewport: null
headless: false
});
let page = yield chrome.newPage();
if (cookies) {
page.setCookie(...cookies);
}
yield page.goto(relay_url);

@@ -36,36 +39,2 @@ return _waitForCookies(page, chrome, relay_url);

exports.chromeGUIAuthentication = chromeGUIAuthentication;
/**
* Login programmatically with Google Chrome.
* Note: Duo 2FA will still require user input.
*/
function chromeProgrammaticAuthentication(username, password, relay_url) {
return __awaiter(this, void 0, void 0, function* () {
let chrome = yield puppeteer.launch({
channel: 'chrome',
});
let page = yield chrome.newPage();
yield page.goto(relay_url);
yield page.waitForNavigation();
yield page.waitForSelector('.loginForm');
yield page.type('#username', username);
yield page.type('#password', password);
yield page.click('input[type=submit]');
// form error watchdog
let err_watch = ((() => __awaiter(this, void 0, void 0, function* () {
let err_element = yield page.waitForSelector('.form-error');
let err_text = yield err_element.evaluate(el => el.textContent, err_element);
throw new Error('Login failed. Maybe invalid credentials?\n\tUT Direct Error Message: \'' + err_text + '\'\n\n');
}))());
yield page.waitForFrame((f) => __awaiter(this, void 0, void 0, function* () {
return f.url().match(/https:\/\/.+\.duosecurity\.com\/frame\/prompt/) != null;
}));
err_watch.catch((r) => { }); // prevent from throwing, we're past the login page so it should not throw
let duoframe = page.frames()[1];
yield duoframe.$eval('#auth_methods > fieldset:nth-child(1) > div.row-label.push-label > button', (el) => {
el.click();
});
return _waitForCookies(page, chrome, relay_url);
});
}
exports.chromeProgrammaticAuthentication = chromeProgrammaticAuthentication;
function _waitForCookies(page, chrome, final_destination) {

@@ -72,0 +41,0 @@ return __awaiter(this, void 0, void 0, function* () {

{
"devDependencies": {
"@types/node": "^17.0.8"
},
"dependencies": {
"puppeteer-core": "^13.0.1"
},
"name": "ut-auth-utils",
"description": "Authenticate into UT Austin applications and retreive session cookies so you can make your own programatic API requests.",
"version": "1.1.5",
"version": "2.0.0",
"main": "dist/auth-utils.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"prepare": "rm -rf dist && tsc --build tsconfig.json"
"prepare": "rm -rf dist && npx tsc --build tsconfig.json"
},

@@ -25,3 +19,9 @@ "repository": {

},
"homepage": "https://github.com/An-GG/ut-auth-utils#readme"
"homepage": "https://github.com/An-GG/ut-auth-utils#readme",
"dependencies": {
"@types/jsdom": "^21.1.0",
"jsdom": "^21.1.0",
"puppeteer": "^19.7.1",
"typescript": "^4.9.5"
}
}
# ut-auth-utils
Authenticate into UT Austin applications and retreive session cookies so you can make your own programatic API requests.
Authenticate into UT Austin applications and retrieve session cookies so you can make your own programmatic API requests.
> **Note:** Google Chrome must be installed.
> **Warning:** Chromium is installed as a required dependency as part of the puppeteer module.
A local copy of Chrome is not installed to keep things lean.
**TODO**: Optionally allow installation of local Chrome binary.
## Install

@@ -20,8 +16,6 @@

```ts
import { chromeProgrammaticAuthentication, UT_DIRECT_URL } from 'ut-auth-utils'
import { chromeGUIAuthentication, UT_DIRECT_URL } from 'ut-auth-utils'
let cookies = await chromeProgrammaticAuthentication('UT EID', 'password', UT_DIRECT_URL);
// You will get 2FA request. Programmatic auth always picks 'Duo Push' as factor
let cookies = await chromeGUIAuthentication(UT_DIRECT_URL);
// Now you can use the cookies to make your own API calls.

@@ -34,11 +28,4 @@ import fetch from 'node-fetch';

Alternatively, you can also authenticate graphically from a Chrome window. This method is simpler and more secure, as your node script never has to handle raw user credentials.
A previous version of this module offered `chromeProgrammaticAuthentication` for headless, automated login. This has been removed in favor of GUI authentication for improved security and robustness.
```ts
...
let cookies = await chromeGUIAuthentication(UT_DIRECT_URL);
```
To avoid having to enter your credentials every time you perform `chromeGUIAuthentication`, use the optional `cookies` parameter to preload cookies from a past, recent session.

@@ -1,9 +0,13 @@

import * as puppeteer from 'puppeteer-core';
import * as puppeteer from 'puppeteer';
import * as repl from 'repl';
import * as proc from 'process';
import { URL } from 'url';
import { JSDOM } from 'jsdom'
export const UTAustinDestinations = {
UT_DIRECT_URL:'https://utdirect.utexas.edu/',
UT_CANVAS_URL:'https://utexas.instructure.com/'
}
export const UT_DIRECT_URL = 'https://utdirect.utexas.edu/';
export const UT_CANVAS_URL = 'https://utexas.instructure.com/';
/**

@@ -13,9 +17,8 @@ * Login graphically with Google Chrome.

*/
export async function chromeGUIAuthentication(relay_url: string) {
export async function chromeGUIAuthentication(relay_url: string, cookies?: {name:string, value:string, [k:string]:any}[]) {
let chrome = await puppeteer.launch({
channel: 'chrome',
headless: false,
defaultViewport: null
headless: false
});
let page = await chrome.newPage();
if (cookies) { page.setCookie(...cookies); }
await page.goto(relay_url);

@@ -26,39 +29,2 @@

/**
* Login programmatically with Google Chrome.
* Note: Duo 2FA will still require user input.
*/
export async function chromeProgrammaticAuthentication(username: string, password: string, relay_url: string) {
let chrome = await puppeteer.launch({
channel: 'chrome',
});
let page = await chrome.newPage();
await page.goto(relay_url);
await page.waitForNavigation();
await page.waitForSelector('.loginForm');
await page.type('#username', username);
await page.type('#password', password);
await page.click('input[type=submit]');
// form error watchdog
let err_watch = ((async () => {
let err_element = await page.waitForSelector('.form-error');
let err_text = await err_element.evaluate(el => el.textContent, err_element);
throw new Error('Login failed. Maybe invalid credentials?\n\tUT Direct Error Message: \'' + err_text + '\'\n\n');
})());
await page.waitForFrame(async (f) => {
return f.url().match(/https:\/\/.+\.duosecurity\.com\/frame\/prompt/) != null;
});
err_watch.catch((r)=>{}); // prevent from throwing, we're past the login page so it should not throw
let duoframe = page.frames()[1];
await duoframe.$eval('#auth_methods > fieldset:nth-child(1) > div.row-label.push-label > button', (el) => {
(el as HTMLButtonElement).click();
});
return _waitForCookies(page, chrome, relay_url);
}
async function _waitForCookies(page: puppeteer.Page, chrome: puppeteer.Browser, final_destination: string) {

@@ -75,1 +41,2 @@ return new Promise<puppeteer.Protocol.Network.Cookie[]>(async (resolve, reject) => {

}

@@ -13,7 +13,10 @@ {

"allowSyntheticDefaultImports": false,
"resolveJsonModule": false
"resolveJsonModule": false,
"skipLibCheck": true,
"lib": ["ESNext", "DOM"]
},
"include": [
"src/**/*"
"src/*.ts",
"src/tests/*.ts"
]
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc