mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-01-06 10:38:50 +01:00
added feature for oidc auto redirection
This commit is contained in:
parent
e14df5956a
commit
caaadf2fdb
5 changed files with 30 additions and 0 deletions
|
|
@ -431,6 +431,9 @@ OPENID_NAME_CLAIM=
|
||||||
|
|
||||||
OPENID_BUTTON_LABEL=
|
OPENID_BUTTON_LABEL=
|
||||||
OPENID_IMAGE_URL=
|
OPENID_IMAGE_URL=
|
||||||
|
# Set to true to automatically redirect to the OpenID provider when a user visits the login page
|
||||||
|
# This will bypass the login form completely for users, only use this if OpenID is your only authentication method
|
||||||
|
OPENID_AUTO_REDIRECT=false
|
||||||
|
|
||||||
# LDAP
|
# LDAP
|
||||||
LDAP_URL=
|
LDAP_URL=
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@ afterEach(() => {
|
||||||
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.OPENID_BUTTON_LABEL;
|
delete process.env.OPENID_BUTTON_LABEL;
|
||||||
|
delete process.env.OPENID_AUTO_REDIRECT;
|
||||||
delete process.env.OPENID_AUTH_URL;
|
delete process.env.OPENID_AUTH_URL;
|
||||||
delete process.env.GITHUB_CLIENT_ID;
|
delete process.env.GITHUB_CLIENT_ID;
|
||||||
delete process.env.GITHUB_CLIENT_SECRET;
|
delete process.env.GITHUB_CLIENT_SECRET;
|
||||||
|
|
|
||||||
|
|
@ -58,6 +58,7 @@ router.get('/', async function (req, res) {
|
||||||
!!process.env.OPENID_SESSION_SECRET,
|
!!process.env.OPENID_SESSION_SECRET,
|
||||||
openidLabel: process.env.OPENID_BUTTON_LABEL || 'Continue with OpenID',
|
openidLabel: process.env.OPENID_BUTTON_LABEL || 'Continue with OpenID',
|
||||||
openidImageUrl: process.env.OPENID_IMAGE_URL,
|
openidImageUrl: process.env.OPENID_IMAGE_URL,
|
||||||
|
openidAutoRedirect: isEnabled(process.env.OPENID_AUTO_REDIRECT),
|
||||||
serverDomain: process.env.DOMAIN_SERVER || 'http://localhost:3080',
|
serverDomain: process.env.DOMAIN_SERVER || 'http://localhost:3080',
|
||||||
emailLoginEnabled,
|
emailLoginEnabled,
|
||||||
registrationEnabled: !ldap?.enabled && isEnabled(process.env.ALLOW_REGISTRATION),
|
registrationEnabled: !ldap?.enabled && isEnabled(process.env.ALLOW_REGISTRATION),
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
import { useOutletContext } from 'react-router-dom';
|
import { useOutletContext } from 'react-router-dom';
|
||||||
|
import { useEffect, useRef } from 'react';
|
||||||
import { useAuthContext } from '~/hooks/AuthContext';
|
import { useAuthContext } from '~/hooks/AuthContext';
|
||||||
import type { TLoginLayoutContext } from '~/common';
|
import type { TLoginLayoutContext } from '~/common';
|
||||||
import { ErrorMessage } from '~/components/Auth/ErrorMessage';
|
import { ErrorMessage } from '~/components/Auth/ErrorMessage';
|
||||||
|
|
@ -10,6 +11,29 @@ function Login() {
|
||||||
const localize = useLocalize();
|
const localize = useLocalize();
|
||||||
const { error, setError, login } = useAuthContext();
|
const { error, setError, login } = useAuthContext();
|
||||||
const { startupConfig } = useOutletContext<TLoginLayoutContext>();
|
const { startupConfig } = useOutletContext<TLoginLayoutContext>();
|
||||||
|
const redirectAttemptedRef = useRef(false);
|
||||||
|
|
||||||
|
// Auto-redirect to OpenID provider if enabled
|
||||||
|
// This is controlled by the OPENID_AUTO_REDIRECT environment variable
|
||||||
|
// When enabled, users will be automatically redirected to the OpenID provider
|
||||||
|
// without seeing the login form at all
|
||||||
|
useEffect(() => {
|
||||||
|
// Simple check if redirect is needed and not yet attempted
|
||||||
|
if (
|
||||||
|
!redirectAttemptedRef.current &&
|
||||||
|
startupConfig?.openidLoginEnabled &&
|
||||||
|
startupConfig?.openidAutoRedirect &&
|
||||||
|
startupConfig?.serverDomain
|
||||||
|
) {
|
||||||
|
// Mark that we've attempted to redirect
|
||||||
|
redirectAttemptedRef.current = true;
|
||||||
|
|
||||||
|
// Log and redirect
|
||||||
|
console.log('Auto-redirecting to OpenID provider...');
|
||||||
|
window.location.href = `${startupConfig.serverDomain}/oauth/openid`;
|
||||||
|
}
|
||||||
|
}, [startupConfig]);
|
||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
|
|
||||||
|
|
@ -487,6 +487,7 @@ export type TStartupConfig = {
|
||||||
appleLoginEnabled: boolean;
|
appleLoginEnabled: boolean;
|
||||||
openidLabel: string;
|
openidLabel: string;
|
||||||
openidImageUrl: string;
|
openidImageUrl: string;
|
||||||
|
openidAutoRedirect: boolean;
|
||||||
/** LDAP Auth Configuration */
|
/** LDAP Auth Configuration */
|
||||||
ldap?: {
|
ldap?: {
|
||||||
/** LDAP enabled */
|
/** LDAP enabled */
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue