mirror of
https://github.com/Stirling-Tools/Stirling-PDF.git
synced 2025-06-22 23:45:02 +00:00
Environment Config
This commit is contained in:
parent
09a3d83dc5
commit
c19bc8d07a
@ -1,2 +1,7 @@
|
|||||||
|
JOBS_ENABLED=True
|
||||||
JOBS_DIR="./jobs"
|
JOBS_DIR="./jobs"
|
||||||
SESSION_SECRET="default-secret"
|
|
||||||
|
AUTH_ENABLED=True
|
||||||
|
AUTH_SESSION_SECRET="default-secret"
|
||||||
|
|
||||||
|
SEQUELIZE_LOGGING=False
|
22
server-node/src/auth/auth-controller.ts.ts
Normal file
22
server-node/src/auth/auth-controller.ts.ts
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
import passport from "passport";
|
||||||
|
import session from "express-session";
|
||||||
|
import { initialize } from "./passport-config";
|
||||||
|
import auth from "../routes/auth/auth-controller";
|
||||||
|
import { Express } from "express";
|
||||||
|
|
||||||
|
export function connect(app: Express) {
|
||||||
|
app.use(session({
|
||||||
|
secret: process.env.SESSION_SECRET || "default-secret",
|
||||||
|
resave: false,
|
||||||
|
saveUninitialized: false
|
||||||
|
}));
|
||||||
|
|
||||||
|
app.use(passport.initialize());
|
||||||
|
app.use(passport.authenticate(['headerapikey', 'session'], {
|
||||||
|
session: false, // Only set a session on the login request.
|
||||||
|
}));
|
||||||
|
|
||||||
|
initialize(passport);
|
||||||
|
|
||||||
|
app.use("/auth", auth);
|
||||||
|
}
|
@ -38,7 +38,7 @@ export function initialize(passport: typeof import("passport")) {
|
|||||||
));
|
));
|
||||||
|
|
||||||
passport.serializeUser((user, done) => {
|
passport.serializeUser((user, done) => {
|
||||||
done(null, user.id) //TODO: Extend Express.User to include id wich is set by passport
|
done(null, user.id)
|
||||||
});
|
});
|
||||||
|
|
||||||
passport.deserializeUser((id: number, done) => {
|
passport.deserializeUser((id: number, done) => {
|
||||||
|
@ -33,13 +33,13 @@ export async function verifyPassword(user: User, password: string): Promise<bool
|
|||||||
if(!passwordRecord) {
|
if(!passwordRecord) {
|
||||||
throw new Error("This user does not have a password set!");
|
throw new Error("This user does not have a password set!");
|
||||||
}
|
}
|
||||||
return passwordRecord.password == password;
|
return passwordRecord.password == password; // TODO: Replace with web-crypto
|
||||||
}
|
}
|
||||||
|
|
||||||
export function createUser(params: { username: string, password: string }, cb: (err: SequelizeError | null, user: User | null) => void ) {
|
export function createUser(params: { username: string, password: string }, cb: (err: SequelizeError | null, user: User | null) => void ) {
|
||||||
User.create({ username: params.username, authenticationMethod: "password" }).then(async user => {
|
User.create({ username: params.username, authenticationMethod: "password" }).then(async user => {
|
||||||
user.setPassword(await Password.create({
|
user.setPassword(await Password.create({
|
||||||
password: params.password,
|
password: params.password, // TODO: Replace with web-crypto
|
||||||
})).then(password => {
|
})).then(password => {
|
||||||
cb(null, user as any as User)
|
cb(null, user as any as User)
|
||||||
}).catch(e =>
|
}).catch(e =>
|
||||||
|
@ -1,7 +1,11 @@
|
|||||||
|
import 'dotenv/config';
|
||||||
|
|
||||||
import { Sequelize, DataTypes } from "sequelize";
|
import { Sequelize, DataTypes } from "sequelize";
|
||||||
|
|
||||||
//TODO: Make this configurable
|
//TODO: Make this configurable
|
||||||
const sequelize = new Sequelize("sqlite::memory:");
|
const sequelize = new Sequelize("sqlite::memory:", {
|
||||||
|
logging: process.env.SEQUELIZE_LOGGING === "True" ? console.log : false
|
||||||
|
});
|
||||||
|
|
||||||
import { User, AccessRule, APIKey, Password } from "../auth/user/user-model";
|
import { User, AccessRule, APIKey, Password } from "../auth/user/user-model";
|
||||||
|
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
import 'dotenv/config';
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* translation
|
* translation
|
||||||
*/
|
*/
|
||||||
@ -25,13 +27,15 @@ console.log("Available Modules: ", listOperatorNames());
|
|||||||
* jobs
|
* jobs
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import "./jobs/jobs-controller";
|
if(process.env.JOBS_ENABLED === "True")
|
||||||
|
import("./jobs/jobs-controller");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* database
|
* database
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import "./data/sequelize-relations";
|
if(process.env.AUTH_ENABLED === "True")
|
||||||
|
import("./data/sequelize-relations");
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* EXPRESS
|
* EXPRESS
|
||||||
@ -45,25 +49,8 @@ const PORT = 8000;
|
|||||||
* auth
|
* auth
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import passport from "passport";
|
if(process.env.AUTH_ENABLED === "True")
|
||||||
import session from "express-session";
|
import("./auth/auth-controller.ts").then(router => router.connect(app));
|
||||||
import { initialize } from "./auth/passport-config";
|
|
||||||
import auth from "./routes/auth/auth-controller";
|
|
||||||
|
|
||||||
app.use(session({
|
|
||||||
secret: process.env.SESSION_SECRET || "default-secret",
|
|
||||||
resave: false,
|
|
||||||
saveUninitialized: false
|
|
||||||
}));
|
|
||||||
|
|
||||||
app.use(passport.initialize());
|
|
||||||
app.use(passport.authenticate(['headerapikey', 'session'], {
|
|
||||||
session: false, // Only set a session on the login request.
|
|
||||||
}));
|
|
||||||
|
|
||||||
initialize(passport);
|
|
||||||
|
|
||||||
app.use("/auth", auth);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* api
|
* api
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
import { traverseOperations } from '@stirling-pdf/shared-operations/src/workflow/traverseOperations';
|
import { traverseOperations } from '@stirling-pdf/shared-operations/src/workflow/traverseOperations';
|
||||||
import { PdfFile, RepresentationType } from '@stirling-pdf/shared-operations/src/wrappers/PdfFile';
|
import { PdfFile, RepresentationType } from '@stirling-pdf/shared-operations/src/wrappers/PdfFile';
|
||||||
import { JoiPDFFileSchema } from '@stirling-pdf/shared-operations/src/wrappers/PdfFileJoi';
|
|
||||||
import 'dotenv/config';
|
import 'dotenv/config';
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
import path from "path";
|
import path from "path";
|
||||||
|
Loading…
x
Reference in New Issue
Block a user