We're setting up the Okta oidc-middleware for our web app.
What works is when we're not logged in, we get redirected to Okta, and then we're redirected back to our callback handler after providing valid credentials. When testing locally, the callback receives the auth code and we're redirected to the after callback path.
However on our deployed staging server, the callback receives the code but returns a 401.
Here's a similar issue that's currently open: https://github.com/okta/okta-oidc-js/issues/207
May or may not be related to that, the situation described isn't exactly the same, though the error message is the same.
Does anyone have thoughts on what the issue might be or how to bump up the verbosity level of the logging?
I don't think it's due to misconfiguration of the Login redirect URIs. We've added the requisite paths.
The Okta config in our Express settings are something like this:
const MemoryStore = require('memorystore')(session);
app.use(
session({
store: new MemoryStore({
checkPeriod: 86400000,
}),
secret: process.env.OKTA_SESSION_SECRET,
resave: true,
saveUninitialized: false,
cookie: {
maxAge: 30 * 60 * 1000,
httpOnly: false,
},
})
);
const orgUrl = process.env.OKTA_ORG_URL;
const oidc = new ExpressOIDC({
appBaseUrl: process.env.OKTA_APP_BASE_URL,
issuer: `${orgUrl}/oauth2/default`,
client_id: process.env.OKTA_CLIENT_ID,
client_secret: process.env.OKTA_CLIENT_SECRET,
scope: 'openid profile',
routes: {
login: {
path: `${APP_ROOT}/login`,
},
loginCallback: {
path: `${APP_ROOT}/authorization-callback`,
afterCallback: APP_ROOT,
},
},
});
app.use(oidc.router);
Here is the error that pops up in server logs:
Error: state mismatch, could not find a state in the session, this is likely an environment setup issue, loaded session: undefined
at callback.then.catch (/usr/src/app/node_modules/openid-client/lib/passport_strategy.js:169:20)
at <anonymous>
at runMicrotasksCallback (internal/process/next_tick.js:121:5)
at _combinedTickCallback (internal/process/next_tick.js:131:7)
at process._tickDomainCallback (internal/process/next_tick.js:218:9)