mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-01-07 02:58:50 +01:00
feat: Enhance OpenID flow with state parameter handling
This commit is contained in:
parent
45e4e70986
commit
ac2e1b1586
2 changed files with 14 additions and 0 deletions
|
|
@ -1,6 +1,7 @@
|
|||
// file deepcode ignore NoRateLimitingForLogin: Rate limiting is handled by the `loginLimiter` middleware
|
||||
const express = require('express');
|
||||
const passport = require('passport');
|
||||
const client = require('openid-client');
|
||||
const {
|
||||
checkBan,
|
||||
logHeaders,
|
||||
|
|
@ -107,6 +108,7 @@ router.get(
|
|||
'/openid',
|
||||
passport.authenticate('openid', {
|
||||
session: false,
|
||||
state: client.randomState(),
|
||||
}),
|
||||
);
|
||||
|
||||
|
|
@ -115,6 +117,7 @@ router.get(
|
|||
passport.authenticate('openid', {
|
||||
failureRedirect: `${domains.client}/oauth/error`,
|
||||
failureMessage: true,
|
||||
state: client.randomState(),
|
||||
session: false,
|
||||
}),
|
||||
setBalanceConfig,
|
||||
|
|
|
|||
|
|
@ -28,6 +28,17 @@ class CustomOpenIDStrategy extends OpenIDStrategy {
|
|||
const hostAndProtocol = process.env.DOMAIN_SERVER;
|
||||
return new URL(`${hostAndProtocol}${req.originalUrl ?? req.url}`);
|
||||
}
|
||||
|
||||
/**
|
||||
* Override to ensure proper authorization request parameters
|
||||
*/
|
||||
authorizationRequestParams(req, options) {
|
||||
const params = super.authorizationRequestParams?.(req, options) || {};
|
||||
if (options?.state != null && options.state && !params.has('state')) {
|
||||
params.set('state', options.state);
|
||||
}
|
||||
return params;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue