Configure multiple API's for the same client

Hi

I am using express-openid-connect and am trying to have different middleware config based on the protected API server I want to call. Trying to do that gives me an Error: req[appSession] is already set, did you run this middleware twice?
The code is as below

const config = {
  authRequired: false,
  routes: { login: false },
  auth0Logout: true,
  baseURL: 'https://localhost/',
  clientID: '....',
  clientSecret: '....',
  issuerBaseURL: '...',
  secret: 'LONG_RANDOM_STRING',
};

app.use('/', auth(config));

app.use(
  '/proxy/api',
  auth({
    ...config,
    authorizationParams: {
      response_type: 'code',
      audience: '....',
      scope: 'openid profile email',
      prompt: 'consent',
    },
    session: { cookie: { path: '/' } },
  })
);

Any help would be appreciated.

Thanks!

Any response to this? I have the same question.

One workaround that I found was to pass in a different value for session.name. This is what determines the name of the cookie. This will avoid the conflict and resolve the error above.

1 Like

Teamwork makes the dreamwork!