refac
Co-Authored-By: Zaid Marji <91486926+zaid-marji@users.noreply.github.com>
This commit is contained in:
co-authored by
Zaid Marji
parent
346dab3d8f
commit
d64ef1803d
@@ -3448,6 +3448,12 @@ ENABLE_OAUTH_SIGNUP = ConfigVar(
|
|||||||
os.getenv('ENABLE_OAUTH_SIGNUP', 'False').lower() == 'true',
|
os.getenv('ENABLE_OAUTH_SIGNUP', 'False').lower() == 'true',
|
||||||
)
|
)
|
||||||
|
|
||||||
|
OAUTH_AUTO_REDIRECT = ConfigVar(
|
||||||
|
'OAUTH_AUTO_REDIRECT',
|
||||||
|
'oauth.auto_redirect',
|
||||||
|
os.getenv('OAUTH_AUTO_REDIRECT', 'False').lower() == 'true',
|
||||||
|
)
|
||||||
|
|
||||||
OAUTH_REFRESH_TOKEN_INCLUDE_SCOPE = ConfigVar(
|
OAUTH_REFRESH_TOKEN_INCLUDE_SCOPE = ConfigVar(
|
||||||
'OAUTH_REFRESH_TOKEN_INCLUDE_SCOPE',
|
'OAUTH_REFRESH_TOKEN_INCLUDE_SCOPE',
|
||||||
'oauth.refresh_token_include_scope',
|
'oauth.refresh_token_include_scope',
|
||||||
|
|||||||
@@ -289,6 +289,7 @@ from open_webui.config import (
|
|||||||
MOJEEK_SEARCH_API_KEY,
|
MOJEEK_SEARCH_API_KEY,
|
||||||
OAUTH_ADMIN_ROLES,
|
OAUTH_ADMIN_ROLES,
|
||||||
OAUTH_ALLOWED_ROLES,
|
OAUTH_ALLOWED_ROLES,
|
||||||
|
OAUTH_AUTO_REDIRECT,
|
||||||
OAUTH_EMAIL_CLAIM,
|
OAUTH_EMAIL_CLAIM,
|
||||||
OAUTH_PICTURE_CLAIM,
|
OAUTH_PICTURE_CLAIM,
|
||||||
OAUTH_PROVIDERS,
|
OAUTH_PROVIDERS,
|
||||||
@@ -864,6 +865,7 @@ app.state.BASE_MODELS = []
|
|||||||
app.state.config.WEBUI_URL = WEBUI_URL
|
app.state.config.WEBUI_URL = WEBUI_URL
|
||||||
app.state.config.ENABLE_SIGNUP = ENABLE_SIGNUP
|
app.state.config.ENABLE_SIGNUP = ENABLE_SIGNUP
|
||||||
app.state.config.ENABLE_LOGIN_FORM = ENABLE_LOGIN_FORM
|
app.state.config.ENABLE_LOGIN_FORM = ENABLE_LOGIN_FORM
|
||||||
|
app.state.config.OAUTH_AUTO_REDIRECT = OAUTH_AUTO_REDIRECT
|
||||||
app.state.config.ENABLE_PASSWORD_CHANGE_FORM = ENABLE_PASSWORD_CHANGE_FORM
|
app.state.config.ENABLE_PASSWORD_CHANGE_FORM = ENABLE_PASSWORD_CHANGE_FORM
|
||||||
|
|
||||||
app.state.config.ENABLE_API_KEYS = ENABLE_API_KEYS
|
app.state.config.ENABLE_API_KEYS = ENABLE_API_KEYS
|
||||||
@@ -2357,7 +2359,10 @@ async def get_app_config(request: Request):
|
|||||||
'name': app.state.WEBUI_NAME,
|
'name': app.state.WEBUI_NAME,
|
||||||
'version': VERSION,
|
'version': VERSION,
|
||||||
'default_locale': str(DEFAULT_LOCALE),
|
'default_locale': str(DEFAULT_LOCALE),
|
||||||
'oauth': {'providers': {name: config.get('name', name) for name, config in OAUTH_PROVIDERS.items()}},
|
'oauth': {
|
||||||
|
'providers': {name: config.get('name', name) for name, config in OAUTH_PROVIDERS.items()},
|
||||||
|
'auto_redirect': app.state.config.OAUTH_AUTO_REDIRECT,
|
||||||
|
},
|
||||||
'features': {
|
'features': {
|
||||||
# --- Public: required by login/signup page pre-auth ---
|
# --- Public: required by login/signup page pre-auth ---
|
||||||
'auth': WEBUI_AUTH,
|
'auth': WEBUI_AUTH,
|
||||||
|
|||||||
@@ -307,6 +307,7 @@ type Config = {
|
|||||||
providers: {
|
providers: {
|
||||||
[key: string]: string;
|
[key: string]: string;
|
||||||
};
|
};
|
||||||
|
auto_redirect?: boolean;
|
||||||
};
|
};
|
||||||
ui?: {
|
ui?: {
|
||||||
pending_user_overlay_title?: string;
|
pending_user_overlay_title?: string;
|
||||||
|
|||||||
@@ -183,10 +183,31 @@
|
|||||||
await oauthCallbackHandler();
|
await oauthCallbackHandler();
|
||||||
form = $page.url.searchParams.get('form');
|
form = $page.url.searchParams.get('form');
|
||||||
|
|
||||||
|
// Auto-redirect to SSO when OAUTH_AUTO_REDIRECT is enabled and the
|
||||||
|
// deployment is unambiguously SSO-only (single provider, no login form,
|
||||||
|
// no LDAP). Suppressed by ?form=, ?error=, onboarding, trusted-header
|
||||||
|
// auth, or an existing session/token.
|
||||||
|
if ($config?.oauth?.auto_redirect && !form && !error) {
|
||||||
|
const providers = Object.keys($config?.oauth?.providers ?? {});
|
||||||
|
if (
|
||||||
|
providers.length === 1 &&
|
||||||
|
$config?.features?.auth !== false &&
|
||||||
|
$config?.features?.enable_login_form === false &&
|
||||||
|
!$config?.features?.enable_ldap &&
|
||||||
|
!$config?.features?.auth_trusted_header &&
|
||||||
|
!$config?.onboarding &&
|
||||||
|
!localStorage.token &&
|
||||||
|
!document.cookie.split('; ').some((c) => c.startsWith('token='))
|
||||||
|
) {
|
||||||
|
window.location.href = `${WEBUI_BASE_URL}/oauth/${providers[0]}/login`;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
loaded = true;
|
loaded = true;
|
||||||
setLogoImage();
|
setLogoImage();
|
||||||
|
|
||||||
if (($config?.features.auth_trusted_header ?? false) || $config?.features.auth === false) {
|
if (($config?.features?.auth_trusted_header ?? false) || $config?.features?.auth === false) {
|
||||||
await signInHandler();
|
await signInHandler();
|
||||||
} else {
|
} else {
|
||||||
onboarding = $config?.onboarding ?? false;
|
onboarding = $config?.onboarding ?? false;
|
||||||
|
|||||||
Reference in New Issue
Block a user