feat: add routes and config opts for more complete stubs

This commit is contained in:
2026-09-04 11:22:43 +02:00
parent 97d68ca8b1
commit c32569317a
6 changed files with 881 additions and 1189 deletions
+59
View File
@@ -0,0 +1,59 @@
/**
* The configuration interface for the SDK
*/
export interface SDKConfig {
/**
* Service configuration
*/
'service': ServiceConfig;
/**
* The URL of the frontend. Leave empty if none. Will be concatenated with redirectURL
*/
'frontendURL'?: string;
/**
* If running in prod or not
*/
'prod': boolean;
/**
* The verification type the advanced verification function should use
*/
'advancedVerification': VerificationType;
/**
* The type of session store you are using
*/
'sessionType': SessionType;
/**
* The CORS whitelist for which base URLs to allow CORS from
*/
'corsWhitelist': string[];
/**
* The path to the logout store. Leave empty to not store on disk
*/
'toBeLoggedOutStorePath'?: string;
/**
* Primarily used for testing. If left empty, will use default
*/
'accountServiceURL'?: string;
/**
* Set the URL to redirect to on login if none is specified. If left empty, defaults to /account
*/
'defaultRedirectURL'?: string;
/**
* The number of seconds until on the advancedLoginCheck middleware, a full check is executed again
*/
'recheckTimeout': number;
/**
* The user-agent to verify against when checking authentication. Set to * to disable check
*/
'user-agent': string;
}
+9 -1
View File
@@ -1,6 +1,12 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
import {
SDKConfig
} from './config';
import express from 'express';
import expressSession from 'express-session';
import {
routes
} from './routes';
import token from './token';
declare module 'express-session' {
@@ -14,12 +20,14 @@ declare module 'express-session' {
// │ Functions │
// ╰───────────────────────────────────────────────╯
// ───────────────────────────────────────────────────────────────────
const setUp = ( app: express.Application ) => {
const setUp = ( configuration: SDKConfig, app: express.Application ) => {
app.use( expressSession( {
'secret': token.generateToken( 60 ),
'resave': false,
'saveUninitialized': true
} ) );
routes( app, configuration );
};
/**
+26
View File
@@ -0,0 +1,26 @@
import {
SDKConfig
} from './config';
import express from 'express';
export const routes = ( app: express.Application, configuration: SDKConfig ) => {
app.get( '/jhid/v2/verify/full/sdk', ( _request: express.Request, response: express.Response ) => {
response.send( 'ok' );
} );
app.get( '/jhid/v2/verify/simple', ( _request: express.Request, response: express.Response ) => {
response.send( 'ok' );
} );
app.get( '/jhid/v2/login', ( _request: express.Request, response: express.Response ) => {
response.redirect( ( configuration.frontendURL ?? '' ) + ( configuration.defaultRedirectURL ?? '/account' ) );
} );
app.get( '/jhid/v2/logout', ( _request: express.Request, response: express.Response ) => {
response.redirect( configuration.frontendURL ?? '/' );
} );
app.get( '/jhid/v2/check/cors', ( request: express.Request, response: express.Response ) => {
response.send( 'ok' );
} );
};