Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions jitar.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"source": "./dist",
"target": "./dist"
}
954 changes: 417 additions & 537 deletions package-lock.json

Large diffs are not rendered by default.

28 changes: 15 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
"scripts": {
"dev": "vite --host",
"copy-assets": "cpx src/assets/**/* dist/assets",
"build": "vite build && tsc -p tsconfig.build.json && tsc-alias -p tsconfig.build.json && npm run copy-assets",
"build": "npm run build-domain && npm run build-webui",
"build-domain": "rm -rf dist && tsc -p tsconfig.jitar.json && tsc-alias -p tsconfig.jitar.json && jitar build && npm run copy-assets",
"build-webui": "vite build",
"compile": "tsc -p tsconfig.compile.json",
"clean": "rm -rf dist",
"docker-up": "docker compose --env-file development.env up",
Expand All @@ -19,16 +21,16 @@
"changelog-debug": "auto-changelog --template changelog.hbs -p --template json --output changelog-data.json",
"review": "npm run compile && npm run lint && npm run test",
"rebuild": "npm run clean && npm run build && npm run standalone",
"standalone": "node --experimental-network-imports --env-file=development.env dist/jitar.js --config=services/standalone.json --bodylimit=512000",
"proxy": "node --experimental-network-imports --env-file=development.env dist/jitar.js --config=services/proxy.json --bodylimit=512000",
"repository": "node --experimental-network-imports --env-file=development.env dist/jitar.js --config=services/repository.json --bodylimit=512000",
"gateway": "node --experimental-network-imports --env-file=development.env dist/jitar.js --config=services/gateway.json --bodylimit=512000",
"bff": "node --experimental-network-imports --env-file=development.env dist/jitar.js --config=services/bff.json --bodylimit=512000",
"notification": "node --experimental-network-imports --env-file=development.env dist/jitar.js --config=services/notification.json --bodylimit=512000",
"notification2": "node --experimental-network-imports --env-file=development.env dist/jitar.js --config=services/notification2.json --bodylimit=512000",
"reads": "node --experimental-network-imports --env-file=development.env dist/jitar.js --config=services/reads.json --bodylimit=512000",
"writes": "node --experimental-network-imports --env-file=development.env dist/jitar.js --config=services/writes.json --bodylimit=512000"

"standalone": "jitar start --env-file=development.env --service=services/standalone.json --http-body-limit=512000",
"repository": "jitar start --env-file=development.env --service=services/repository.json",
"proxy": "jitar start --env-file=development.env --service=services/proxy.json --http-body-limit=512000",
"gateway": "jitar start --env-file=development.env --service=services/gateway.json --http-body-limit=512000",
"bff": "jitar start --env-file=development.env --service=services/bff.json --http-body-limit=512000",
"notification": "jitar start --env-file=development.env --service=services/notification.json --http-body-limit=512000",
"notification2": "jitar start --env-file=development.env --service=services/notification2.json --http-body-limit=512000",
"reads": "jitar start --env-file=development.env --service=services/reads.json --http-body-limit=512000",
"writes": "jitar start --env-file=development.env --service=services/writes.json --http-body-limit=512000"
},
"files": [
"CHANGELOG.md",
Expand All @@ -37,7 +39,7 @@
],
"dependencies": {
"dayjs": "^1.11.13",
"jitar": "^0.7.6",
"jitar": "^0.8.2",
"minio": "^8.0.1",
"mongodb": "^6.9.0",
"openid-client": "^5.7.0",
Expand All @@ -49,7 +51,7 @@
"zod": "^3.23.8"
},
"devDependencies": {
"@jitar/plugin-vite": "^0.7.6",
"@jitar/plugin-vite": "^0.8.2",
"@types/node": "20.14.9",
"@types/react": "^18.3.8",
"@types/react-dom": "^18.3.0",
Expand Down
1 change: 0 additions & 1 deletion services/bff.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
],
"worker":
{
"repository": "http://127.0.0.1:1000",
"gateway": "http://127.0.0.1:2000",
"trustKey": "${JITAR_TRUST_KEY}",
"segments": ["bff"]
Expand Down
9 changes: 4 additions & 5 deletions services/gateway.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@
"tearDown": [
"./integrations/runtime/tearDownGateway"
],
"middleware": [
"./integrations/runtime/authenticationMiddleware"
],
"gateway":
{
"repository": "http://127.0.0.1:1000",
"trustKey": "${JITAR_TRUST_KEY}",
"middlewares": [
"./integrations/runtime/authenticationMiddleware"
]
"trustKey": "${JITAR_TRUST_KEY}"
}
}
1 change: 0 additions & 1 deletion services/notification.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
],
"worker":
{
"repository": "http://127.0.0.1:1000",
"gateway": "http://127.0.0.1:2000",
"trustKey": "${JITAR_TRUST_KEY}",
"segments": ["notification"]
Expand Down
1 change: 0 additions & 1 deletion services/notification2.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
],
"worker":
{
"repository": "http://127.0.0.1:1000",
"gateway": "http://127.0.0.1:2000",
"trustKey": "${JITAR_TRUST_KEY}",
"segments": ["notification"]
Expand Down
1 change: 0 additions & 1 deletion services/reads.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
],
"worker":
{
"repository": "http://127.0.0.1:1000",
"gateway": "http://127.0.0.1:2000",
"trustKey": "${JITAR_TRUST_KEY}",
"segments": ["reads"]
Expand Down
12 changes: 6 additions & 6 deletions services/standalone.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@
"./integrations/runtime/fileStoreHealthCheck",
"./integrations/runtime/databaseHealthCheck"
],
"middleware": [
"./integrations/runtime/authenticationMiddleware"
],
"standalone":
{
"trustKey": "${JITAR_TRUST_KEY}",
"serveIndexOnNotFound": true,
"assets": ["index.html", "main.js", "assets/**/*", "webui/**/*"],
"segments": ["bff"],
"middlewares": [
"./integrations/runtime/authenticationMiddleware"
]

"serveIndexOnNotFound": true,
"assets": ["index.html", "main.js", "assets/**/*", "webui/**/*"]
}
}
1 change: 0 additions & 1 deletion services/writes.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
],
"worker":
{
"repository": "http://127.0.0.1:1000",
"gateway": "http://127.0.0.1:2000",
"trustKey": "${JITAR_TRUST_KEY}",
"segments": ["writes"]
Expand Down
98 changes: 50 additions & 48 deletions src/integrations/runtime/middlewares/AuthenticationMiddleware.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@

import { Middleware, NextHandler, Request, Response, Unauthorized } from 'jitar';
import { Middleware, NextHandler, Request, Response } from 'jitar';

import { IdentityProvider, Session } from '^/integrations/authentication/module';
import { generateKey } from '^/integrations/utilities/crypto';

import Unauthorized from '../errors/Unauthorized';

type AuthProcedures = {
loginUrl: string;
login: string;
Expand Down Expand Up @@ -47,6 +49,52 @@ export default class AuthenticationMiddleware implements Middleware
}
}

async #getLoginUrl(): Promise<Response>
{
const url = await this.#identityProvider.getLoginUrl();

return new Response(200, url);
}

async #createSession(request: Request, next: NextHandler): Promise<Response>
{
const data = Object.fromEntries(request.args);
const session = await this.#identityProvider.login(data);

request.args.clear();
request.setArgument(IDENTITY_PARAMETER, session.identity);

const response = await next();

session.key = generateKey();
session.requester = response.result;

sessions.set(session.key, session);

this.#setAuthorizationHeader(response, session);
this.#setRedirectHeader(response, session.key);

return response;
}

async #destroySession(request: Request, next: NextHandler): Promise<Response>
{
const key = this.#extractAuthorizationKey(request);

if (key === undefined)
{
throw new Unauthorized('Invalid authorization key');
}

const session = this.#getSession(key);

await this.#identityProvider.logout(session);

sessions.delete(key);

return next();
}

async #handleRequest(request: Request, next: NextHandler): Promise<Response>
{
const storedSession = this.#authorize(request);
Expand Down Expand Up @@ -88,42 +136,14 @@ export default class AuthenticationMiddleware implements Middleware
return;
}

throw new Unauthorized('Unauthorized');
throw new Unauthorized('Not a public resource');
}

#authorizeProtected(key: string): Session
{
return this.#getSession(key);
}

async #getLoginUrl(): Promise<Response>
{
const url = await this.#identityProvider.getLoginUrl();

return new Response(url);
}

async #createSession(request: Request, next: NextHandler): Promise<Response>
{
const data = Object.fromEntries(request.args);
const session = await this.#identityProvider.login(data);

request.args.clear();
request.setArgument(IDENTITY_PARAMETER, session.identity);

const response = await next();

session.key = generateKey();
session.requester = response.result;

sessions.set(session.key, session);

this.#setAuthorizationHeader(response, session);
this.#setRedirectHeader(response, session.key);

return response;
}

#getSession(key: string): Session
{
const session = sessions.get(key);
Expand Down Expand Up @@ -162,24 +182,6 @@ export default class AuthenticationMiddleware implements Middleware
}
}

async #destroySession(request: Request, next: NextHandler): Promise<Response>
{
const key = this.#extractAuthorizationKey(request);

if (key === undefined)
{
throw new Unauthorized('Invalid authorization key');
}

const session = this.#getSession(key);

await this.#identityProvider.logout(session);

sessions.delete(key);

return next();
}

#extractAuthorizationKey(request: Request): string | undefined
{
const authorization = this.#getAuthorizationHeader(request);
Expand Down
9 changes: 0 additions & 9 deletions src/jitar.ts

This file was deleted.

File renamed without changes.
23 changes: 14 additions & 9 deletions vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import jitar from '@jitar/plugin-vite';
import jitar, { JitarConfig } from '@jitar/plugin-vite';
import react from '@vitejs/plugin-react';
import { defineConfig } from 'vite';
import tsconfigPaths from 'vite-tsconfig-paths';
Expand All @@ -7,19 +7,24 @@ const JITAR_URL = 'http://localhost:3000';
const JITAR_SEGMENTS = [];
const JITAR_MIDDLEWARES = ['./integrations/runtime/requesterMiddleware'];

const jitarConfig: JitarConfig = {
sourceDir: 'src',
targetDir: 'dist',
jitarDir: 'domain',
jitarUrl: JITAR_URL,
segments: JITAR_SEGMENTS,
middleware: JITAR_MIDDLEWARES
};

export default defineConfig({
publicDir: 'src/webui/public',
build: {
assetsDir: 'webui'
},
server: {
proxy: {
'/assets': JITAR_URL
}
assetsDir: 'webui',
emptyOutDir: false
},
plugins: [
react(),
jitar('src', 'domain', JITAR_URL, JITAR_SEGMENTS, JITAR_MIDDLEWARES),
tsconfigPaths()
tsconfigPaths(),
jitar(jitarConfig)
]
});
Loading