mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-17 00:40:14 +01:00
* fix: #546 issue with closing registration * refactor: change casing of controller files for consistency * fix: ensure registrationEnabled is sending a boolean value * refactor: modifications to openId code
This commit is contained in:
parent
fdc5265f48
commit
25211d6f23
16 changed files with 44356 additions and 44376 deletions
|
|
@ -200,8 +200,8 @@ OPENID_SESSION_SECRET=
|
||||||
OPENID_SCOPE="openid profile email"
|
OPENID_SCOPE="openid profile email"
|
||||||
OPENID_CALLBACK_URL=/oauth/openid/callback
|
OPENID_CALLBACK_URL=/oauth/openid/callback
|
||||||
# If LABEL and URL are left empty, then the default OpenID label and logo are used.
|
# If LABEL and URL are left empty, then the default OpenID label and logo are used.
|
||||||
VITE_OPENID_LABEL=
|
OPENID_BUTTON_LABEL=
|
||||||
VITE_OPENID_URL=
|
OPENID_AUTH_URL=
|
||||||
|
|
||||||
# Set the expiration delay for the secure cookie with the JWT token
|
# Set the expiration delay for the secure cookie with the JWT token
|
||||||
# Delay is in millisecond e.g. 7 days is 1000*60*60*24*7
|
# Delay is in millisecond e.g. 7 days is 1000*60*60*24*7
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ const indexSync = require('../lib/db/indexSync');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const cors = require('cors');
|
const cors = require('cors');
|
||||||
const routes = require('./routes');
|
const routes = require('./routes');
|
||||||
const errorController = require('./controllers/error.controller');
|
const errorController = require('./controllers/ErrorController');
|
||||||
const passport = require('passport');
|
const passport = require('passport');
|
||||||
const port = process.env.PORT || 3080;
|
const port = process.env.PORT || 3080;
|
||||||
const host = process.env.HOST || 'localhost';
|
const host = process.env.HOST || 'localhost';
|
||||||
|
|
|
||||||
|
|
@ -12,8 +12,8 @@ afterEach(() => {
|
||||||
delete process.env.OPENID_CLIENT_SECRET;
|
delete process.env.OPENID_CLIENT_SECRET;
|
||||||
delete process.env.OPENID_ISSUER;
|
delete process.env.OPENID_ISSUER;
|
||||||
delete process.env.OPENID_SESSION_SECRET;
|
delete process.env.OPENID_SESSION_SECRET;
|
||||||
delete process.env.VITE_OPENID_LABEL;
|
delete process.env.OPENID_BUTTON_LABEL;
|
||||||
delete process.env.VITE_OPENID_URL;
|
delete process.env.OPENID_AUTH_URL;
|
||||||
delete process.env.DOMAIN_SERVER;
|
delete process.env.DOMAIN_SERVER;
|
||||||
delete process.env.ALLOW_REGISTRATION;
|
delete process.env.ALLOW_REGISTRATION;
|
||||||
});
|
});
|
||||||
|
|
@ -30,8 +30,8 @@ describe.skip('GET /', () => {
|
||||||
process.env.OPENID_CLIENT_SECRET= 'Test OpenID Secret';
|
process.env.OPENID_CLIENT_SECRET= 'Test OpenID Secret';
|
||||||
process.env.OPENID_ISSUER= 'Test OpenID Issuer';
|
process.env.OPENID_ISSUER= 'Test OpenID Issuer';
|
||||||
process.env.OPENID_SESSION_SECRET= 'Test Secret';
|
process.env.OPENID_SESSION_SECRET= 'Test Secret';
|
||||||
process.env.VITE_OPENID_LABEL= 'Test OpenID';
|
process.env.OPENID_BUTTON_LABEL= 'Test OpenID';
|
||||||
process.env.VITE_OPENID_URL= 'http://test-server.com';
|
process.env.OPENID_AUTH_URL= 'http://test-server.com';
|
||||||
process.env.DOMAIN_SERVER = 'http://test-server.com';
|
process.env.DOMAIN_SERVER = 'http://test-server.com';
|
||||||
process.env.ALLOW_REGISTRATION = 'true';
|
process.env.ALLOW_REGISTRATION = 'true';
|
||||||
|
|
||||||
|
|
@ -43,7 +43,7 @@ describe.skip('GET /', () => {
|
||||||
googleLoginEnabled: true,
|
googleLoginEnabled: true,
|
||||||
openidLoginEnabled: true,
|
openidLoginEnabled: true,
|
||||||
openidLabel: 'Test OpenID',
|
openidLabel: 'Test OpenID',
|
||||||
openidUrl: 'http://test-server.com',
|
openidImageUrl: 'http://test-server.com',
|
||||||
serverDomain: 'http://test-server.com',
|
serverDomain: 'http://test-server.com',
|
||||||
registrationEnabled: 'true',
|
registrationEnabled: 'true',
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -4,9 +4,9 @@ const {
|
||||||
resetPasswordController,
|
resetPasswordController,
|
||||||
// refreshController,
|
// refreshController,
|
||||||
registrationController
|
registrationController
|
||||||
} = require('../controllers/auth.controller');
|
} = require('../controllers/AuthController');
|
||||||
const { loginController } = require('../controllers/auth/login.controller');
|
const { loginController } = require('../controllers/auth/LoginController');
|
||||||
const { logoutController } = require('../controllers/auth/logout.controller');
|
const { logoutController } = require('../controllers/auth/LogoutController');
|
||||||
const requireJwtAuth = require('../../middleware/requireJwtAuth');
|
const requireJwtAuth = require('../../middleware/requireJwtAuth');
|
||||||
const requireLocalAuth = require('../../middleware/requireLocalAuth');
|
const requireLocalAuth = require('../../middleware/requireLocalAuth');
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,13 +5,16 @@ router.get('/', async function (req, res) {
|
||||||
try {
|
try {
|
||||||
const appTitle = process.env.APP_TITLE || 'LibreChat';
|
const appTitle = process.env.APP_TITLE || 'LibreChat';
|
||||||
const googleLoginEnabled = !!process.env.GOOGLE_CLIENT_ID && !!process.env.GOOGLE_CLIENT_SECRET;
|
const googleLoginEnabled = !!process.env.GOOGLE_CLIENT_ID && !!process.env.GOOGLE_CLIENT_SECRET;
|
||||||
const openidLoginEnabled = !!process.env.OPENID_CLIENT_ID && !!process.env.OPENID_CLIENT_SECRET && !!process.env.OPENID_ISSUER && !!process.env.OPENID_SESSION_SECRET;
|
const openidLoginEnabled = !!process.env.OPENID_CLIENT_ID
|
||||||
const openidLabel = process.env.VITE_OPENID_LABEL || 'Login with OpenID';
|
&& !!process.env.OPENID_CLIENT_SECRET
|
||||||
const openidUrl = process.env.VITE_OPENID_URL;
|
&& !!process.env.OPENID_ISSUER
|
||||||
|
&& !!process.env.OPENID_SESSION_SECRET;
|
||||||
|
const openidLabel = process.env.OPENID_BUTTON_LABEL || 'Login with OpenID';
|
||||||
|
const openidImageUrl = process.env.OPENID_IMAGE_URL;
|
||||||
const serverDomain = process.env.DOMAIN_SERVER || 'http://localhost:3080';
|
const serverDomain = process.env.DOMAIN_SERVER || 'http://localhost:3080';
|
||||||
const registrationEnabled = process.env.ALLOW_REGISTRATION || true;
|
const registrationEnabled = process.env.ALLOW_REGISTRATION === 'true';
|
||||||
|
|
||||||
return res.status(200).send({appTitle, googleLoginEnabled, openidLoginEnabled, openidLabel, openidUrl, serverDomain, registrationEnabled});
|
return res.status(200).send({appTitle, googleLoginEnabled, openidLoginEnabled, openidLabel, openidImageUrl, serverDomain, registrationEnabled});
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
return res.status(500).send({error: err.message});
|
return res.status(500).send({error: err.message});
|
||||||
|
|
|
||||||
15
client/env.d.ts
vendored
15
client/env.d.ts
vendored
|
|
@ -1,15 +0,0 @@
|
||||||
/// <reference types="vite/client" />
|
|
||||||
interface ImportMetaEnv {
|
|
||||||
readonly VITE_SERVER_URL_DEV: string;
|
|
||||||
readonly VITE_SERVER_URL_PROD: string;
|
|
||||||
readonly VITE_SHOW_GOOGLE_LOGIN_OPTION: string;
|
|
||||||
readonly ALLOW_OPENID: string;
|
|
||||||
readonly VITE_OPENID_LABEL: string;
|
|
||||||
readonly VITE_OPENID_URL: string;
|
|
||||||
readonly VITE_CLIENT_URL_DEV: string;
|
|
||||||
readonly VITE_CLIENT_URL_PROD: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface ImportMeta {
|
|
||||||
readonly env: ImportMetaEnv;
|
|
||||||
}
|
|
||||||
|
|
@ -15,7 +15,6 @@ function Login() {
|
||||||
navigate('/chat/new');
|
navigate('/chat/new');
|
||||||
}
|
}
|
||||||
}, [isAuthenticated, navigate]);
|
}, [isAuthenticated, navigate]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex min-h-screen flex-col items-center justify-center bg-white pt-6 sm:pt-0">
|
<div className="flex min-h-screen flex-col items-center justify-center bg-white pt-6 sm:pt-0">
|
||||||
<div className="mt-6 w-96 overflow-hidden bg-white px-6 py-4 sm:max-w-md sm:rounded-lg">
|
<div className="mt-6 w-96 overflow-hidden bg-white px-6 py-4 sm:max-w-md sm:rounded-lg">
|
||||||
|
|
@ -80,30 +79,25 @@ function Login() {
|
||||||
)}
|
)}
|
||||||
{startupConfig?.openidLoginEnabled && (
|
{startupConfig?.openidLoginEnabled && (
|
||||||
<>
|
<>
|
||||||
<div className="relative mt-6 flex w-full items-center justify-center border border-t uppercase">
|
|
||||||
<div className="absolute bg-white px-3 text-xs">Or</div>
|
|
||||||
</div>
|
|
||||||
<div className="mt-4 flex gap-x-2">
|
<div className="mt-4 flex gap-x-2">
|
||||||
<a
|
<a
|
||||||
aria-label="Login with OpenID"
|
aria-label="Login with OpenID"
|
||||||
className="justify-left flex w-full items-center space-x-3 rounded-md border border-gray-300 px-5 py-3 hover:bg-gray-50 focus:ring-2 focus:ring-violet-600 focus:ring-offset-1"
|
className="justify-left flex w-full items-center space-x-3 rounded-md border border-gray-300 px-5 py-3 hover:bg-gray-50 focus:ring-2 focus:ring-violet-600 focus:ring-offset-1"
|
||||||
href={`${startupConfig.serverDomain}/oauth/openid`}
|
href={`${startupConfig.serverDomain}/oauth/openid`}
|
||||||
>
|
>
|
||||||
{startupConfig.openidUrl ? (
|
{startupConfig.openidImageUrl ? (
|
||||||
<img src={startupConfig.openidUrl} alt="OpenID Logo" className="h-5 w-5"/>
|
<img src={startupConfig.openidImageUrl} alt="OpenID Logo" className="h-5 w-5" />
|
||||||
) : (
|
) : (
|
||||||
<svg
|
<svg
|
||||||
xmlns="http://www.w3.org/2000/svg"
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
viewBox="0 0 448 512"
|
viewBox="0 0 448 512"
|
||||||
id="openid"
|
id="openid"
|
||||||
className="h-5 w-5"
|
className="h-5 w-5"
|
||||||
>
|
>
|
||||||
<path
|
<path d="M271.5 432l-68 32C88.5 453.7 0 392.5 0 318.2c0-71.5 82.5-131 191.7-144.3v43c-71.5 12.5-124 53-124 101.3 0 51 58.5 93.3 135.7 103v-340l68-33.2v384zM448 291l-131.3-28.5 36.8-20.7c-19.5-11.5-43.5-20-70-24.8v-43c46.2 5.5 87.7 19.5 120.3 39.3l35-19.8L448 291z"></path>
|
||||||
d="M271.5 432l-68 32C88.5 453.7 0 392.5 0 318.2c0-71.5 82.5-131 191.7-144.3v43c-71.5 12.5-124 53-124 101.3 0 51 58.5 93.3 135.7 103v-340l68-33.2v384zM448 291l-131.3-28.5 36.8-20.7c-19.5-11.5-43.5-20-70-24.8v-43c46.2 5.5 87.7 19.5 120.3 39.3l35-19.8L448 291z"
|
</svg>
|
||||||
></path>
|
)}
|
||||||
</svg>
|
<p>{startupConfig.openidLabel}</p>
|
||||||
)}
|
|
||||||
<p>{startupConfig.openidLabel}</p>
|
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
</>
|
</>
|
||||||
|
|
|
||||||
|
|
@ -323,21 +323,19 @@ function Registration() {
|
||||||
className="justify-left flex w-full items-center space-x-3 rounded-md border border-gray-300 px-5 py-3 hover:bg-gray-50 focus:ring-2 focus:ring-violet-600 focus:ring-offset-1"
|
className="justify-left flex w-full items-center space-x-3 rounded-md border border-gray-300 px-5 py-3 hover:bg-gray-50 focus:ring-2 focus:ring-violet-600 focus:ring-offset-1"
|
||||||
href={`${startupConfig.serverDomain}/oauth/openid`}
|
href={`${startupConfig.serverDomain}/oauth/openid`}
|
||||||
>
|
>
|
||||||
{startupConfig.openidUrl ? (
|
{startupConfig.openidImageUrl ? (
|
||||||
<img src={startupConfig.openidUrl} alt="OpenID Logo" className="h-5 w-5"/>
|
<img src={startupConfig.openidImageUrl} alt="OpenID Logo" className="h-5 w-5" />
|
||||||
) : (
|
) : (
|
||||||
<svg
|
<svg
|
||||||
xmlns="http://www.w3.org/2000/svg"
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
viewBox="0 0 448 512"
|
viewBox="0 0 448 512"
|
||||||
id="openid"
|
id="openid"
|
||||||
className="h-5 w-5"
|
className="h-5 w-5"
|
||||||
>
|
>
|
||||||
<path
|
<path d="M271.5 432l-68 32C88.5 453.7 0 392.5 0 318.2c0-71.5 82.5-131 191.7-144.3v43c-71.5 12.5-124 53-124 101.3 0 51 58.5 93.3 135.7 103v-340l68-33.2v384zM448 291l-131.3-28.5 36.8-20.7c-19.5-11.5-43.5-20-70-24.8v-43c46.2 5.5 87.7 19.5 120.3 39.3l35-19.8L448 291z"></path>
|
||||||
d="M271.5 432l-68 32C88.5 453.7 0 392.5 0 318.2c0-71.5 82.5-131 191.7-144.3v43c-71.5 12.5-124 53-124 101.3 0 51 58.5 93.3 135.7 103v-340l68-33.2v384zM448 291l-131.3-28.5 36.8-20.7c-19.5-11.5-43.5-20-70-24.8v-43c46.2 5.5 87.7 19.5 120.3 39.3l35-19.8L448 291z"
|
</svg>
|
||||||
></path>
|
)}
|
||||||
</svg>
|
<p>{startupConfig.openidLabel}</p>
|
||||||
)}
|
|
||||||
<p>{startupConfig.openidLabel}</p>
|
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
</>
|
</>
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ const setup = ({
|
||||||
googleLoginEnabled: true,
|
googleLoginEnabled: true,
|
||||||
openidLoginEnabled: true,
|
openidLoginEnabled: true,
|
||||||
openidLabel: 'Test OpenID',
|
openidLabel: 'Test OpenID',
|
||||||
openidUrl: 'http://test-server.com',
|
openidImageUrl: 'http://test-server.com',
|
||||||
registrationEnabled: true,
|
registrationEnabled: true,
|
||||||
serverDomain: 'mock-server'
|
serverDomain: 'mock-server'
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ const setup = ({
|
||||||
googleLoginEnabled: true,
|
googleLoginEnabled: true,
|
||||||
openidLoginEnabled: true,
|
openidLoginEnabled: true,
|
||||||
openidLabel: 'Test OpenID',
|
openidLabel: 'Test OpenID',
|
||||||
openidUrl: 'http://test-server.com',
|
openidImageUrl: 'http://test-server.com',
|
||||||
registrationEnabled: true,
|
registrationEnabled: true,
|
||||||
serverDomain: 'mock-server'
|
serverDomain: 'mock-server'
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -239,7 +239,7 @@ export type TStartupConfig = {
|
||||||
googleLoginEnabled: boolean;
|
googleLoginEnabled: boolean;
|
||||||
openidLoginEnabled: boolean;
|
openidLoginEnabled: boolean;
|
||||||
openidLabel: string;
|
openidLabel: string;
|
||||||
openidUrl: string;
|
openidImageUrl: string;
|
||||||
serverDomain: string;
|
serverDomain: string;
|
||||||
registrationEnabled: boolean;
|
registrationEnabled: boolean;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
88616
package-lock.json
generated
88616
package-lock.json
generated
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue