Skip to content

Commit

Permalink
fix(registry): fix error on direct call to auth/return endpoint witho…
Browse files Browse the repository at this point in the history
…ut session

refactor auth module
add oauth for lde
  • Loading branch information
stas-nc committed May 15, 2024
1 parent 62db0df commit b5e58ca
Show file tree
Hide file tree
Showing 40 changed files with 1,404 additions and 2,081 deletions.
19 changes: 19 additions & 0 deletions registry/lde/oauth-server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { OAuth2Server } from 'oauth2-mock-server';

(async function main() {
try {
const server = new OAuth2Server();
// Generate a new RSA key and add it to the keystore
await server.issuer.keys.generate('RS256');

// Start the server
await server.start(8080, 'localhost');
console.log('Issuer URL:', server.issuer.url); // -> http://localhost:8080

server.service.on('beforeTokenSigning', (token, req) => {
token.payload.unique_name = 'root';
});
} catch (error) {
console.error(error);
}
})();
2,208 changes: 559 additions & 1,649 deletions registry/package-lock.json

Large diffs are not rendered by default.

24 changes: 13 additions & 11 deletions registry/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"scripts": {
"tsc": "tsc",
"compile": "tsc --incremental",
"dev": "nodemon -e ts,json5 --exec \"npx tsc --incremental && dotenv -- npm run start\" ",
"dev": "nodemon -e ts,json5 --exec \"npx tsc --incremental || exit 1 && npm run start | pino-pretty\" ",
"build": "npm run compile && cd ./client && npm run build",
"start": "dotenv -- node -r source-map-support/register ./build/server/index.js",
"start-docker": "npm run migrate && npm start",
Expand Down Expand Up @@ -38,29 +38,31 @@
"@types/express-serve-static-core": "4.17.37",
"@types/express-session": "^1.17.8",
"@types/is-valid-domain": "0.0.2",
"@types/jsonwebtoken": "^9.0.6",
"@types/lodash": "^4.14.199",
"@types/mocha": "^10.0.2",
"@types/newrelic": "^9.14.1",
"@types/node": "^20.8.3",
"@types/passport": "^1.0.13",
"@types/passport-http-bearer": "^1.0.38",
"@types/passport-local": "^1.0.36",
"@types/node": "^20.12.12",
"@types/passport": "^1.0.16",
"@types/passport-http-bearer": "^1.0.41",
"@types/passport-local": "^1.0.38",
"@types/sinon": "^10.0.19",
"@types/supertest": "^2.0.14",
"@types/url-join": "^4.0.1",
"@types/uuid": "^9.0.5",
"chai": "4.3.10",
"cross-env": "7.0.3",
"jsonwebtoken": "^9.0.2",
"mocha": "^10.2.0",
"nock": "^13.3.3",
"nodemon": "^3.0.1",
"nyc": "^15.1.0",
"pino-pretty": "^10.2.3",
"oauth2-mock-server": "^7.1.1",
"pino-pretty": "^11.0.0",
"rimraf": "^5.0.5",
"sinon": "^16.1.0",
"supertest": "6.3.3",
"timekeeper": "^2.3.1",
"ts-node": "^10.9.1",
"ts-node": "^10.9.2",
"typescript": "^4.9.5"
},
"dependencies": {
Expand All @@ -70,12 +72,12 @@
"bcrypt": "^5.1.1",
"body-parser": "^1.20.2",
"config": "^3.3.9",
"connect-session-knex": "^3.0.1",
"connect-session-knex": "^4.0.0",
"deep-equal": "^2.2.2",
"dotenv-cli": "^7.3.0",
"escape-html": "^1.0.3",
"express": "^4.18.2",
"express-session": "^1.17.3",
"express-session": "^1.18.0",
"http-shutdown": "^1.2.2",
"ilc-plugins-sdk": "^2.1.0",
"is-valid-domain": "0.1.6",
Expand All @@ -86,7 +88,7 @@
"newrelic": "^11.1.0",
"node-html-parser": "^6.1.10",
"openid-client": "^5.6.0",
"passport": "^0.6.0",
"passport": "^0.7.0",
"passport-http-bearer": "^1.0.1",
"passport-local": "^1.0.0",
"pg": "^8.11.3",
Expand Down
16 changes: 12 additions & 4 deletions registry/server/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@ import config from 'config';
import express, { Application, RequestHandler } from 'express';
import serveStatic from 'serve-static';

import auth from './auth';
import { useAuth } from './auth';
import errorHandler from './errorHandler';
import { loadPlugins } from './util/pluginManager';
import * as routes from './routes/routes';
import settingsService from './settings/services/SettingsService';
import pong from './util/ping';
import { contextMiddleware } from './middleware/context';
import { logConnectionString } from './util/db';
import { getLogger } from './util/logger';
import { OpenIdService } from './auth/services/OpenIdService';

export default async (withAuth: boolean = true): Promise<Application> => {
loadPlugins();
Expand All @@ -38,9 +40,15 @@ export default async (withAuth: boolean = true): Promise<Application> => {

let authMw: RequestHandler[] = [(req, res, next) => next()];
if (withAuth) {
authMw = await auth(app, settingsService, {
session: { secret: config.get('auth.sessionSecret') },
});
const openIdService = new OpenIdService(settingsService);
authMw = await useAuth(
app,
openIdService,
{
session: { secret: config.get('auth.sessionSecret') },
},
getLogger(),
);
}

app.use('/api/v1/config', routes.config);
Expand Down
Loading

0 comments on commit b5e58ca

Please sign in to comment.