Node.js package for managing authentication and cookies for FCSE's services.
Currently supports the following services:
You can add the package to your NPM project by running npm i finki-auth.
import {
CasAuthentication,
Service,
isCookieValid,
isCookieHeaderValid,
} from "finki-auth";
const credentials = {
username: "example",
password: "secret_password",
};
const auth = new CasAuthentication(credentials);
await auth.authenticate(Service.COURSES);
// Get array of cookie objects
const cookies = await auth.getCookie(Service.COURSES);
// Get cookie header directly for sending requests
const cookieHeader = await auth.buildCookieHeader(Service.COURSES);
// Check if the cookie is still valid, and if not, call `authenticate` again
const valid = await auth.isCookieValid(Service.COURSES);
if (!valid) await auth.authenticate(Service.COURSES);
// There are also some utility functions available:
const isCookieValidStandalone = await isCookieValid({
service: Service.COURSES,
cookies,
});
const isCookieHeaderValidStandalone = await isCookieHeaderValid({
service: Service.COURSES,
cookieHeader,
});Authentication state is isolated per service. Re-authenticating a service clears its previous session before starting, including when the new attempt fails; sessions for other services are unaffected. GitLab performs one extra validation request to its protected profile endpoint before publishing the new session. Other services keep their existing login flow and do not perform an additional mandatory validation request.
This project is licensed under the terms of the MIT license.