mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-16 08:20: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_CALLBACK_URL=/oauth/openid/callback
|
||||
# If LABEL and URL are left empty, then the default OpenID label and logo are used.
|
||||
VITE_OPENID_LABEL=
|
||||
VITE_OPENID_URL=
|
||||
OPENID_BUTTON_LABEL=
|
||||
OPENID_AUTH_URL=
|
||||
|
||||
# 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
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ const indexSync = require('../lib/db/indexSync');
|
|||
const path = require('path');
|
||||
const cors = require('cors');
|
||||
const routes = require('./routes');
|
||||
const errorController = require('./controllers/error.controller');
|
||||
const errorController = require('./controllers/ErrorController');
|
||||
const passport = require('passport');
|
||||
const port = process.env.PORT || 3080;
|
||||
const host = process.env.HOST || 'localhost';
|
||||
|
|
|
|||
|
|
@ -12,8 +12,8 @@ afterEach(() => {
|
|||
delete process.env.OPENID_CLIENT_SECRET;
|
||||
delete process.env.OPENID_ISSUER;
|
||||
delete process.env.OPENID_SESSION_SECRET;
|
||||
delete process.env.VITE_OPENID_LABEL;
|
||||
delete process.env.VITE_OPENID_URL;
|
||||
delete process.env.OPENID_BUTTON_LABEL;
|
||||
delete process.env.OPENID_AUTH_URL;
|
||||
delete process.env.DOMAIN_SERVER;
|
||||
delete process.env.ALLOW_REGISTRATION;
|
||||
});
|
||||
|
|
@ -30,8 +30,8 @@ describe.skip('GET /', () => {
|
|||
process.env.OPENID_CLIENT_SECRET= 'Test OpenID Secret';
|
||||
process.env.OPENID_ISSUER= 'Test OpenID Issuer';
|
||||
process.env.OPENID_SESSION_SECRET= 'Test Secret';
|
||||
process.env.VITE_OPENID_LABEL= 'Test OpenID';
|
||||
process.env.VITE_OPENID_URL= 'http://test-server.com';
|
||||
process.env.OPENID_BUTTON_LABEL= 'Test OpenID';
|
||||
process.env.OPENID_AUTH_URL= 'http://test-server.com';
|
||||
process.env.DOMAIN_SERVER = 'http://test-server.com';
|
||||
process.env.ALLOW_REGISTRATION = 'true';
|
||||
|
||||
|
|
@ -43,7 +43,7 @@ describe.skip('GET /', () => {
|
|||
googleLoginEnabled: true,
|
||||
openidLoginEnabled: true,
|
||||
openidLabel: 'Test OpenID',
|
||||
openidUrl: 'http://test-server.com',
|
||||
openidImageUrl: 'http://test-server.com',
|
||||
serverDomain: 'http://test-server.com',
|
||||
registrationEnabled: 'true',
|
||||
});
|
||||
|
|
|
|||
|
|
@ -4,9 +4,9 @@ const {
|
|||
resetPasswordController,
|
||||
// refreshController,
|
||||
registrationController
|
||||
} = require('../controllers/auth.controller');
|
||||
const { loginController } = require('../controllers/auth/login.controller');
|
||||
const { logoutController } = require('../controllers/auth/logout.controller');
|
||||
} = require('../controllers/AuthController');
|
||||
const { loginController } = require('../controllers/auth/LoginController');
|
||||
const { logoutController } = require('../controllers/auth/LogoutController');
|
||||
const requireJwtAuth = require('../../middleware/requireJwtAuth');
|
||||
const requireLocalAuth = require('../../middleware/requireLocalAuth');
|
||||
|
||||
|
|
|
|||
|
|
@ -5,13 +5,16 @@ router.get('/', async function (req, res) {
|
|||
try {
|
||||
const appTitle = process.env.APP_TITLE || 'LibreChat';
|
||||
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 openidLabel = process.env.VITE_OPENID_LABEL || 'Login with OpenID';
|
||||
const openidUrl = process.env.VITE_OPENID_URL;
|
||||
const openidLoginEnabled = !!process.env.OPENID_CLIENT_ID
|
||||
&& !!process.env.OPENID_CLIENT_SECRET
|
||||
&& !!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 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) {
|
||||
console.error(err);
|
||||
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');
|
||||
}
|
||||
}, [isAuthenticated, navigate]);
|
||||
|
||||
return (
|
||||
<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">
|
||||
|
|
@ -80,30 +79,25 @@ function Login() {
|
|||
)}
|
||||
{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">
|
||||
<a
|
||||
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"
|
||||
href={`${startupConfig.serverDomain}/oauth/openid`}
|
||||
>
|
||||
{startupConfig.openidUrl ? (
|
||||
<img src={startupConfig.openidUrl} alt="OpenID Logo" className="h-5 w-5"/>
|
||||
) : (
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
viewBox="0 0 448 512"
|
||||
id="openid"
|
||||
className="h-5 w-5"
|
||||
>
|
||||
<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>
|
||||
</svg>
|
||||
)}
|
||||
<p>{startupConfig.openidLabel}</p>
|
||||
{startupConfig.openidImageUrl ? (
|
||||
<img src={startupConfig.openidImageUrl} alt="OpenID Logo" className="h-5 w-5" />
|
||||
) : (
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
viewBox="0 0 448 512"
|
||||
id="openid"
|
||||
className="h-5 w-5"
|
||||
>
|
||||
<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>
|
||||
</svg>
|
||||
)}
|
||||
<p>{startupConfig.openidLabel}</p>
|
||||
</a>
|
||||
</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"
|
||||
href={`${startupConfig.serverDomain}/oauth/openid`}
|
||||
>
|
||||
{startupConfig.openidUrl ? (
|
||||
<img src={startupConfig.openidUrl} alt="OpenID Logo" className="h-5 w-5"/>
|
||||
) : (
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
viewBox="0 0 448 512"
|
||||
id="openid"
|
||||
className="h-5 w-5"
|
||||
>
|
||||
<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>
|
||||
</svg>
|
||||
)}
|
||||
<p>{startupConfig.openidLabel}</p>
|
||||
{startupConfig.openidImageUrl ? (
|
||||
<img src={startupConfig.openidImageUrl} alt="OpenID Logo" className="h-5 w-5" />
|
||||
) : (
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
viewBox="0 0 448 512"
|
||||
id="openid"
|
||||
className="h-5 w-5"
|
||||
>
|
||||
<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>
|
||||
</svg>
|
||||
)}
|
||||
<p>{startupConfig.openidLabel}</p>
|
||||
</a>
|
||||
</div>
|
||||
</>
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ const setup = ({
|
|||
googleLoginEnabled: true,
|
||||
openidLoginEnabled: true,
|
||||
openidLabel: 'Test OpenID',
|
||||
openidUrl: 'http://test-server.com',
|
||||
openidImageUrl: 'http://test-server.com',
|
||||
registrationEnabled: true,
|
||||
serverDomain: 'mock-server'
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ const setup = ({
|
|||
googleLoginEnabled: true,
|
||||
openidLoginEnabled: true,
|
||||
openidLabel: 'Test OpenID',
|
||||
openidUrl: 'http://test-server.com',
|
||||
openidImageUrl: 'http://test-server.com',
|
||||
registrationEnabled: true,
|
||||
serverDomain: 'mock-server'
|
||||
}
|
||||
|
|
|
|||
|
|
@ -239,7 +239,7 @@ export type TStartupConfig = {
|
|||
googleLoginEnabled: boolean;
|
||||
openidLoginEnabled: boolean;
|
||||
openidLabel: string;
|
||||
openidUrl: string;
|
||||
openidImageUrl: string;
|
||||
serverDomain: string;
|
||||
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