first commit
This commit is contained in:
parent
4e09e8762b
commit
b9b04c5b02
@ -181,7 +181,16 @@ export async function authLogin(req, res) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const authUrl = getAuthorizationUrl(req);
|
const authUrl = getAuthorizationUrl(req);
|
||||||
res.redirect(authUrl);
|
|
||||||
|
// Save session before redirecting to Keycloak
|
||||||
|
req.session.save((err) => {
|
||||||
|
if (err) {
|
||||||
|
console.error('Session save error:', err);
|
||||||
|
return res.status(500).send('Session save failed');
|
||||||
|
}
|
||||||
|
console.log('Session saved, redirecting to Keycloak:', authUrl.substring(0, 80) + '...');
|
||||||
|
res.redirect(authUrl);
|
||||||
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Login error:', error);
|
console.error('Login error:', error);
|
||||||
res.status(500).send('Authentication failed');
|
res.status(500).send('Authentication failed');
|
||||||
|
|||||||
@ -47,9 +47,14 @@ export function getAuthorizationUrl(req) {
|
|||||||
const client = getOIDCClient();
|
const client = getOIDCClient();
|
||||||
const nonce = Math.random().toString(36).substring(7);
|
const nonce = Math.random().toString(36).substring(7);
|
||||||
const state = Math.random().toString(36).substring(7);
|
const state = Math.random().toString(36).substring(7);
|
||||||
|
|
||||||
|
// Store in session AND ensure session is saved
|
||||||
req.session.nonce = nonce;
|
req.session.nonce = nonce;
|
||||||
req.session.state = state;
|
req.session.state = state;
|
||||||
|
|
||||||
|
// Force session save before redirect
|
||||||
|
console.log('Storing in session - nonce:', nonce, 'state:', state);
|
||||||
|
|
||||||
return client.authorizationUrl({
|
return client.authorizationUrl({
|
||||||
scope: 'openid profile email',
|
scope: 'openid profile email',
|
||||||
response_mode: 'form_post',
|
response_mode: 'form_post',
|
||||||
|
|||||||
@ -78,11 +78,11 @@ app.use(
|
|||||||
store: new FileStoreSession({ path: './sessions' }),
|
store: new FileStoreSession({ path: './sessions' }),
|
||||||
secret: config.sessionSecret,
|
secret: config.sessionSecret,
|
||||||
resave: false,
|
resave: false,
|
||||||
saveUninitialized: false,
|
saveUninitialized: true, // Changed to true for OAuth flow
|
||||||
cookie: {
|
cookie: {
|
||||||
secure: config.nodeEnv === 'production',
|
secure: config.nodeEnv === 'production',
|
||||||
httpOnly: true,
|
httpOnly: true,
|
||||||
sameSite: 'strict',
|
sameSite: 'lax', // Changed from 'strict' to 'lax' to allow cross-site callbacks
|
||||||
maxAge: 24 * 60 * 60 * 1000, // 24 hours
|
maxAge: 24 * 60 * 60 * 1000, // 24 hours
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user