aboutsummaryrefslogtreecommitdiffstats
path: root/src/routes
diff options
context:
space:
mode:
Diffstat (limited to 'src/routes')
-rw-r--r--src/routes/api.ts (renamed from src/routes/pendulum.ts)8
-rw-r--r--src/routes/middleware/saml.ts13
2 files changed, 17 insertions, 4 deletions
diff --git a/src/routes/pendulum.ts b/src/routes/api.ts
index 66ad594..6cb804c 100644
--- a/src/routes/pendulum.ts
+++ b/src/routes/api.ts
@@ -222,13 +222,13 @@ api
/**
* Verify that the file exists and is a regular file so it can be sent to the user
- * @param file The path to the file
- * @param res The Express response object, used if the file is not accessible
- * @returns `true` if the file exists and is a regular file,`false` otherwise
+ * @param {string} file The path to the file
+ * @param {Response} res The Express response object, used if the file is not accessible
+ * @returns {Promise<boolean>} `true` if the file exists and is a regular file,`false` otherwise
*
* `AFTER THIS POINT, THE API HAS ALREADY SENT A RESPONSE, SO THE FUNCTION THAT CALLED IT SHOULD NOT RETURN ANOTHER RESPONSE `
*/
-async function verifyFile(file: string, res: Response) {
+async function verifyFile(file: string, res: Response): Promise<boolean> {
// Make sure the file being requested to run exists
try {
await access(file);
diff --git a/src/routes/middleware/saml.ts b/src/routes/middleware/saml.ts
new file mode 100644
index 0000000..ad9d50d
--- /dev/null
+++ b/src/routes/middleware/saml.ts
@@ -0,0 +1,13 @@
+import BasicAuthenticator from 'umn-shib-nodejs';
+import { Request, Response, NextFunction } from 'express';
+
+const saml = function (req: Request, res: Response, next: NextFunction): void {
+ const authenticator = new BasicAuthenticator(req, res);
+ if (!authenticator.hasSession()) {
+ authenticator.redirectToLogin();
+ next();
+ }
+ next();
+};
+
+export default saml;