Skip to content

Commit 94454d1

Browse files
committed
standard issues
1 parent 23f2403 commit 94454d1

File tree

4 files changed

+38
-24
lines changed

4 files changed

+38
-24
lines changed

lib/api/authn/webid-oidc.mjs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@ const { AuthCallbackRequest } = oidcAuthManager.handlers
3030
export function initialize (app, argv) {
3131
const oidc = fromServerConfig(argv)
3232
app.locals.oidc = oidc
33-
oidc.initialize()
33+
34+
// Initialize OIDC provider (async)
35+
// Store the promise so the server can await it before listening
36+
app.locals.initPromise = oidc.initialize()
3437

3538
// Attach the OIDC API
3639
app.use('/', middleware(oidc))

lib/create-app.mjs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ import aclCheck from '@solid/acl-check'
1111
import fs from 'fs'
1212
import { fileURLToPath } from 'url'
1313

14-
import acceptEventsModule from 'express-accept-events'
15-
import negotiateEventsModule from 'express-negotiate-events'
16-
import eventIDModule from 'express-prep/event-id'
17-
import prepModule from 'express-prep'
14+
import acceptEvents from 'express-accept-events'
15+
import events from 'express-negotiate-events'
16+
import eventID from 'express-prep/event-id'
17+
import prep from 'express-prep'
1818

1919
// Complex internal modules - keep as CommonJS for now except where ESM available
2020
import LDP from './ldp.mjs'
@@ -43,12 +43,6 @@ const __dirname = dirname(__filename)
4343
// Read package.json synchronously to avoid using require() for JSON
4444
const { version } = JSON.parse(fs.readFileSync(path.join(__dirname, '../package.json'), 'utf8'))
4545

46-
// Extract default exports from ESM modules
47-
const acceptEvents = acceptEventsModule.default
48-
const events = negotiateEventsModule.default
49-
const eventID = eventIDModule.default
50-
const prep = prepModule.default
51-
5246
const corsSettings = cors({
5347
methods: [
5448
'OPTIONS', 'HEAD', 'GET', 'PATCH', 'POST', 'PUT', 'DELETE'

lib/create-server.mjs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import debug from './debug.mjs'
88
import createApp from './create-app.mjs'
99

1010
function createServer (argv, app) {
11-
console.log('Creating server with options:', argv)
1211
argv = argv || {}
1312
app = app || express()
1413
const ldpApp = createApp(argv)
@@ -101,6 +100,24 @@ function createServer (argv, app) {
101100
ldpApp.locals.ldp.live = solidWs.publish.bind(solidWs)
102101
}
103102

103+
// Wrap server.listen() to ensure async initialization completes first
104+
const originalListen = server.listen.bind(server)
105+
server.listen = function (...args) {
106+
if (ldpApp.locals.initPromise) {
107+
const initPromise = ldpApp.locals.initPromise
108+
delete ldpApp.locals.initPromise
109+
110+
// Wait for initialization, then start listening
111+
initPromise
112+
.then(() => originalListen(...args))
113+
.catch(err => server.emit('error', err))
114+
} else {
115+
originalListen(...args)
116+
}
117+
118+
return server
119+
}
120+
104121
return server
105122
}
106123

test/integration/authentication-oidc-test.mjs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -59,16 +59,16 @@ describe('Authentication API (OIDC)', () => {
5959
const bobRootPath = path.normalize(path.join(__dirname, '../resources/accounts-scenario/bob'))
6060
let alicePod
6161
let bobPod
62-
63-
async function createPods() {
62+
63+
async function createPods () {
6464
alicePod = await ldnode.createServer(
6565
Object.assign({
6666
root: aliceRootPath,
6767
serverUri: aliceServerUri,
6868
dbPath: aliceDbPath
6969
}, serverConfig)
7070
)
71-
71+
7272
bobPod = await ldnode.createServer(
7373
Object.assign({
7474
root: bobRootPath,
@@ -84,12 +84,12 @@ describe('Authentication API (OIDC)', () => {
8484
console.error(`Server on port ${port} error:`, err)
8585
reject(err)
8686
})
87-
87+
8888
const server = pod.listen(port, () => {
8989
console.log(`Server started on port ${port}`)
9090
resolve()
9191
})
92-
92+
9393
server.on('error', (err) => {
9494
console.error(`Server listen error on port ${port}:`, err)
9595
reject(err)
@@ -99,31 +99,31 @@ describe('Authentication API (OIDC)', () => {
9999

100100
before(async function () {
101101
this.timeout(60000) // 60 second timeout for server startup with OIDC initialization
102-
102+
103103
// Clean and recreate OIDC database directories to ensure fresh state
104104
const aliceOidcPath = path.join(aliceDbPath, 'oidc')
105105
const bobOidcPath = path.join(bobDbPath, 'oidc')
106-
106+
107107
// Remove any existing OIDC data to prevent corruption
108108
console.log('Cleaning OIDC directories...')
109109
fs.removeSync(aliceOidcPath)
110110
fs.removeSync(bobOidcPath)
111-
111+
112112
// Create fresh directory structure
113113
fs.ensureDirSync(path.join(aliceOidcPath, 'op/clients'))
114114
fs.ensureDirSync(path.join(aliceOidcPath, 'op/tokens'))
115115
fs.ensureDirSync(path.join(aliceOidcPath, 'op/codes'))
116116
fs.ensureDirSync(path.join(aliceOidcPath, 'users'))
117117
fs.ensureDirSync(path.join(aliceOidcPath, 'rp/clients'))
118-
118+
119119
fs.ensureDirSync(path.join(bobOidcPath, 'op/clients'))
120120
fs.ensureDirSync(path.join(bobOidcPath, 'op/tokens'))
121121
fs.ensureDirSync(path.join(bobOidcPath, 'op/codes'))
122122
fs.ensureDirSync(path.join(bobOidcPath, 'users'))
123123
fs.ensureDirSync(path.join(bobOidcPath, 'rp/clients'))
124-
124+
125125
await createPods()
126-
126+
127127
await Promise.all([
128128
startServer(alicePod, 7000),
129129
startServer(bobPod, 7001)
@@ -584,7 +584,7 @@ describe('Authentication API (OIDC)', () => {
584584

585585
before(function () {
586586
this.timeout(50000) // Long timeout for OIDC initialization
587-
587+
588588
auth = new SolidAuthOIDC({ store: localStorage, window: { location: {} } })
589589
const appOptions = {
590590
redirectUri: 'https://app.example.com/callback'

0 commit comments

Comments
 (0)