Skip to content

Commit b6b1952

Browse files
committed
web: Add a stubbed login option for local dev
This adds a configuration option, ``NULL_AUTH``. When set to ``True``, it enables a development/debug mode where all attempts to authenticate succeed. This bypasses the need for CalNet credentials (and TLS) on a local development system. Implements: AP-506
1 parent ba19e5f commit b6b1952

File tree

3 files changed

+24
-12
lines changed

3 files changed

+24
-12
lines changed

README.rst

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ The following keys are available for configuration in the ``.env`` file:
226226
``LANGFUSE_PROMPT``, ``LANGFUSE_PROMPT_LABEL``
227227
The prompt name defined in langfuse for the prompt to be used. The label is the label
228228
created for the named prompt in Langfuse. The default values are
229-
LANGFUSE_PROMPT=default and LANGFUSE_PROMPT_LABEL=production
229+
``LANGFUSE_PROMPT=default`` and ``LANGFUSE_PROMPT_LABEL=production``.
230230

231231
If these values are not supplied or not defined in Langfuse a fallback prompt which is
232232
defined in ``config/__init__.py`` will be used.
@@ -238,5 +238,9 @@ The following keys are available for configuration in the ``.env`` file:
238238
``K_VALUE``
239239
Int. The k value used for retrieving context from the vector_store. The default is 4
240240

241+
``NULL_AUTH``
242+
Boolean. Whether to allow anyone to login with any name and password. Defaults to ``False``.
243+
Never ever set this unless you know what you're doing!
244+
241245
``ETL_TRACING``
242246
Boolean. Whether to trace embedding calls in Langfuse. Defaults to ``False``.

willa/config/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,14 @@
4545
'EXTRA_VERSION': '',
4646
'DEPLOYMENT_ID': 'default',
4747
'K_VALUE': '4',
48+
'NULL_AUTH': 'False',
4849
'ETL_TRACING': 'False'
4950
}
5051
"""The defaults for configuration variables not set in the .env file."""
5152

5253

5354
VALID_VARS: set[str] = {'TIND_API_KEY', 'TIND_API_URL', 'DEFAULT_STORAGE_DIR', 'ETL_TRACING',
54-
'OLLAMA_URL', 'CHAT_MODEL', 'CHAT_TEMPERATURE', 'CALNET_ENV',
55+
'OLLAMA_URL', 'CHAT_MODEL', 'CHAT_TEMPERATURE', 'CALNET_ENV', 'NULL_AUTH',
5556
'CALNET_OIDC_CLIENT_ID', 'CALNET_OIDC_CLIENT_SECRET', 'LANCEDB_URI',
5657
'CHAT_BACKEND', 'EMBED_BACKEND', 'LANGFUSE_HOST', 'LANGFUSE_PUBLIC_KEY',
5758
'LANGFUSE_SECRET_KEY', 'LANGFUSE_PROMPT', 'LANGFUSE_PROMPT_LABEL',

willa/web/app.py

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from chainlit.types import ThreadDict, CommandDict
77

88
from willa.chatbot import Chatbot
9+
from willa.config import CONFIG
910
from willa.web.cas_provider import CASProvider
1011
from willa.web.inject_custom_auth import add_custom_oauth_provider
1112

@@ -14,8 +15,6 @@
1415
"""The Chatbot instances associated with each thread."""
1516

1617

17-
add_custom_oauth_provider('cas', CASProvider())
18-
1918
COMMANDS: list[CommandDict] = [
2019
{
2120
"id": "Copy Transcript",
@@ -97,12 +96,20 @@ async def chat(message: cl.Message) -> None:
9796
content=reply['no_results']).send()
9897

9998

100-
# Chainlit erroneously defines the callback as taking an `id_token` param that is never passed.
101-
@cl.oauth_callback # type: ignore[arg-type]
102-
async def oauth_callback(provider_id: str, _token: str, _raw_user_data: dict[str, str],
103-
default_user: cl.User) -> cl.User | None:
104-
"""Handle OAuth authentication."""
105-
if provider_id != 'cas':
106-
return None
99+
if CONFIG['NULL_AUTH'].lower() == 'true':
100+
@cl.password_auth_callback
101+
async def password_auth_callback(username: str, _password: str) -> cl.User:
102+
"""Handle password authentication (null; all login attempts will succeed)."""
103+
return cl.User(identifier=username, metadata={'role': 'admin', 'provider': 'null'})
104+
else:
105+
add_custom_oauth_provider('cas', CASProvider())
106+
107+
# Chainlit erroneously defines the callback as taking an `id_token` param that is never passed.
108+
@cl.oauth_callback # type: ignore[arg-type]
109+
async def oauth_callback(provider_id: str, _token: str, _raw_user_data: dict[str, str],
110+
default_user: cl.User) -> cl.User | None:
111+
"""Handle OAuth authentication."""
112+
if provider_id != 'cas':
113+
return None
107114

108-
return default_user
115+
return default_user

0 commit comments

Comments
 (0)