mirror of
https://github.com/open-webui/open-webui.git
synced 2026-11-14 09:21:22 +00:00
Fix Feishu OAuth env aliases
This commit is contained in:
parent
4e2240aada
commit
540e37a04a
3 changed files with 70 additions and 4 deletions
|
|
@ -37,6 +37,7 @@ from open_webui.env import (
|
|||
log,
|
||||
)
|
||||
from open_webui.internal.db import Base, get_db, get_async_db
|
||||
from open_webui.utils.env_vars import get_env_with_aliases
|
||||
from open_webui.utils.redis import get_redis_connection
|
||||
|
||||
|
||||
|
|
@ -624,15 +625,19 @@ FEISHU_CLIENT_SECRET = PersistentConfig(
|
|||
)
|
||||
|
||||
FEISHU_OAUTH_SCOPE = PersistentConfig(
|
||||
'FEISHU_OAUTH_SCOPE',
|
||||
'FEISHU_CLIENT_SCOPE',
|
||||
'oauth.feishu.scope',
|
||||
os.environ.get('FEISHU_OAUTH_SCOPE', 'contact:user.base:readonly'),
|
||||
get_env_with_aliases(
|
||||
'FEISHU_CLIENT_SCOPE',
|
||||
'FEISHU_OAUTH_SCOPE',
|
||||
default='contact:user.base:readonly',
|
||||
),
|
||||
)
|
||||
|
||||
FEISHU_REDIRECT_URI = PersistentConfig(
|
||||
'FEISHU_REDIRECT_URI',
|
||||
'FEISHU_CLIENT_REDIRECT_URI',
|
||||
'oauth.feishu.redirect_uri',
|
||||
os.environ.get('FEISHU_REDIRECT_URI', ''),
|
||||
get_env_with_aliases('FEISHU_CLIENT_REDIRECT_URI', 'FEISHU_REDIRECT_URI'),
|
||||
)
|
||||
|
||||
ENABLE_OAUTH_ROLE_MANAGEMENT = PersistentConfig(
|
||||
|
|
|
|||
43
backend/open_webui/test/utils/test_env_vars.py
Normal file
43
backend/open_webui/test/utils/test_env_vars.py
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
from open_webui.utils.env_vars import get_env_with_aliases
|
||||
|
||||
|
||||
def test_get_env_with_aliases_prefers_documented_env_name():
|
||||
environ = {
|
||||
'FEISHU_CLIENT_REDIRECT_URI': 'https://example.test/oauth/feishu/callback',
|
||||
'FEISHU_REDIRECT_URI': 'https://legacy.example.test/oauth/feishu/callback',
|
||||
}
|
||||
|
||||
assert (
|
||||
get_env_with_aliases(
|
||||
'FEISHU_CLIENT_REDIRECT_URI',
|
||||
'FEISHU_REDIRECT_URI',
|
||||
environ=environ,
|
||||
)
|
||||
== 'https://example.test/oauth/feishu/callback'
|
||||
)
|
||||
|
||||
|
||||
def test_get_env_with_aliases_falls_back_to_legacy_alias():
|
||||
environ = {'FEISHU_OAUTH_SCOPE': 'contact:user.email:readonly'}
|
||||
|
||||
assert (
|
||||
get_env_with_aliases(
|
||||
'FEISHU_CLIENT_SCOPE',
|
||||
'FEISHU_OAUTH_SCOPE',
|
||||
default='contact:user.base:readonly',
|
||||
environ=environ,
|
||||
)
|
||||
== 'contact:user.email:readonly'
|
||||
)
|
||||
|
||||
|
||||
def test_get_env_with_aliases_returns_default_when_missing():
|
||||
assert (
|
||||
get_env_with_aliases(
|
||||
'FEISHU_CLIENT_SCOPE',
|
||||
'FEISHU_OAUTH_SCOPE',
|
||||
default='contact:user.base:readonly',
|
||||
environ={},
|
||||
)
|
||||
== 'contact:user.base:readonly'
|
||||
)
|
||||
18
backend/open_webui/utils/env_vars.py
Normal file
18
backend/open_webui/utils/env_vars.py
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
import os
|
||||
from collections.abc import Mapping
|
||||
|
||||
|
||||
def get_env_with_aliases(
|
||||
env_name: str,
|
||||
*aliases: str,
|
||||
default: str = '',
|
||||
environ: Mapping[str, str] | None = None,
|
||||
) -> str:
|
||||
values = os.environ if environ is None else environ
|
||||
|
||||
for name in (env_name, *aliases):
|
||||
value = values.get(name)
|
||||
if value is not None:
|
||||
return value
|
||||
|
||||
return default
|
||||
Loading…
Add table
Reference in a new issue