You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
56 lines
1.6 KiB
TypeScript
56 lines
1.6 KiB
TypeScript
import { LoadDictElement } from 'di-why';
|
|
import { Express } from 'express';
|
|
import { createOidcStandardRoutes } from '../oidc/OIDCStandardRoutes';
|
|
import { buildOidcConfig } from '../oidc/oidcConfigBuilder';
|
|
|
|
/**
|
|
* OIDC Standard Routes as a Middleware Attacher
|
|
* Compatible with express-knifey's middleware system
|
|
*/
|
|
const loadDictElement: LoadDictElement<(path: string | '*') => void> = {
|
|
before: async ({ serviceLocator, deps }) => {
|
|
if (serviceLocator.couldLoad('oidcUserRegistrar')) {
|
|
const onUserAuthenticated = await serviceLocator.get('oidcUserRegistrar');
|
|
return { ...deps, onUserAuthenticated };
|
|
}
|
|
return deps;
|
|
},
|
|
factory: ({
|
|
app,
|
|
logger,
|
|
sessionService,
|
|
appConfig,
|
|
redisClient,
|
|
onUserAuthenticated
|
|
}) => {
|
|
// Build configuration using shared builder
|
|
const baseConfig = buildOidcConfig(appConfig, redisClient);
|
|
const config = {
|
|
logger,
|
|
sessionService,
|
|
...baseConfig,
|
|
...(onUserAuthenticated ? { onUserAuthenticated } : {})
|
|
};
|
|
|
|
const router = createOidcStandardRoutes(config);
|
|
|
|
// Return a MiddlewareAttacher function
|
|
// The path parameter is ignored since OIDC routes define their own paths
|
|
return (path: string | '*') => {
|
|
// Mount the OIDC routes on the Express app
|
|
(app as Express).use(router);
|
|
|
|
logger.log('OIDC Standard Routes mounted via middleware system - /login, POST /oidc/callback, /auth/status, /auth/logout');
|
|
};
|
|
},
|
|
locateDeps: {
|
|
app: 'app',
|
|
logger: 'logger',
|
|
sessionService: 'sessionService',
|
|
appConfig: 'appConfig',
|
|
redisClient: 'redisClient'
|
|
}
|
|
};
|
|
|
|
export default loadDictElement;
|