Skip to content

Commit f7c920a

Browse files
authored
feat(ui): initial auth plugin (#763)
1 parent 67fbd71 commit f7c920a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+937
-207
lines changed

examples/chat/authenticated_chat.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ def get_auth_backend() -> ListAuthenticationBackend:
195195
"""Factory function to create the preferred authentication backend."""
196196
users = [
197197
{
198+
"user_id": "8e6c5871-3817-4d62-828f-ef6789de31b9",
198199
"username": "admin",
199200
"password": "admin123",
200201
"email": "[email protected]",
@@ -203,6 +204,7 @@ def get_auth_backend() -> ListAuthenticationBackend:
203204
"metadata": {"department": "IT", "clearance_level": "high"},
204205
},
205206
{
207+
"user_id": "d3afde97-35fb-41d0-9aa6-6a1c822db63e",
206208
"username": "moderator",
207209
"password": "mod123",
208210
"email": "[email protected]",
@@ -211,6 +213,7 @@ def get_auth_backend() -> ListAuthenticationBackend:
211213
"metadata": {"department": "Community", "shift": "day"},
212214
},
213215
{
216+
"user_id": "7ef3d9d5-cdad-405a-a919-3d3ee5e1c34d",
214217
"username": "alice",
215218
"password": "alice123",
216219
"email": "[email protected]",
@@ -219,6 +222,7 @@ def get_auth_backend() -> ListAuthenticationBackend:
219222
"metadata": {"department": "Marketing", "join_date": "2024-01-15"},
220223
},
221224
{
225+
"user_id": "acac16db-37f0-43cb-b18f-b005c3c3de88",
222226
"username": "bob",
223227
"password": "bob123",
224228
"email": "[email protected]",

packages/ragbits-chat/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# CHANGELOG
22

33
## Unreleased
4+
- Add authentication handling in the UI (#763)
45
- Add backend authentication (#761)
56

67
- Autogenerate typescript types based on backend typing (#727)

packages/ragbits-chat/src/ragbits/chat/api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@ async def _handle_login(self, request: LoginRequest) -> JSONResponse:
478478
return JSONResponse(
479479
content=LoginResponse(
480480
success=True,
481-
user=auth_result.user.model_dump() if auth_result.user else None,
481+
user=auth_result.user if auth_result.user else None,
482482
error_message=None,
483483
jwt_token=auth_result.jwt_token,
484484
).model_dump()

packages/ragbits-chat/src/ragbits/chat/auth/types.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class LoginResponse(BaseModel):
6060
"""
6161

6262
success: bool = Field(..., description="Whether login was successful")
63-
user: dict | None = Field(None, description="User information")
63+
user: User | None = Field(None, description="User information")
6464
error_message: str | None = Field(None, description="Error message if login failed")
6565
jwt_token: JWTToken | None = Field(..., description="Access jwt_token")
6666

packages/ragbits-chat/src/ragbits/chat/providers/model_provider.py

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
from pydantic import BaseModel
1212

13+
from ragbits.chat.interface.types import AuthType
14+
1315

1416
class RagbitsChatModelProvider:
1517
"""
@@ -37,8 +39,17 @@ def get_models(self) -> dict[str, type[BaseModel | Enum]]:
3739
return self._models_cache
3840

3941
try:
42+
from ragbits.chat.auth.types import (
43+
CredentialsLoginRequest,
44+
JWTToken,
45+
LoginRequest,
46+
LoginResponse,
47+
LogoutRequest,
48+
User,
49+
)
4050
from ragbits.chat.interface.forms import UserSettings
4151
from ragbits.chat.interface.types import (
52+
AuthenticationConfig,
4253
ChatContext,
4354
ChatMessageRequest,
4455
ChatResponseType,
@@ -90,6 +101,15 @@ def get_models(self) -> dict[str, type[BaseModel | Enum]]:
90101
# API request models
91102
"ChatRequest": ChatMessageRequest,
92103
"FeedbackRequest": FeedbackRequest,
104+
# Auth
105+
"AuthType": AuthType,
106+
"AuthenticationConfig": AuthenticationConfig,
107+
"CredentialsLoginRequest": CredentialsLoginRequest,
108+
"JWTToken": JWTToken,
109+
"LoginRequest": LoginRequest,
110+
"LoginResponse": LoginResponse,
111+
"LogoutRequest": LogoutRequest,
112+
"User": User,
93113
}
94114

95115
return self._models_cache
@@ -111,7 +131,9 @@ def get_categories(self) -> dict[str, list[str]]:
111131
return self._categories_cache
112132

113133
self._categories_cache = {
114-
"enums": ["ChatResponseType", "FeedbackType", "LiveUpdateType", "MessageRole"],
134+
"enums": [model_name for model_name, model in self._models_cache.items() if issubclass(model, Enum)]
135+
if self._models_cache
136+
else [],
115137
"core_data": [
116138
"ChatContext",
117139
"LiveUpdate",
@@ -121,10 +143,28 @@ def get_categories(self) -> dict[str, list[str]]:
121143
"ServerState",
122144
"FeedbackItem",
123145
"Image",
146+
"JWTToken",
147+
"User",
148+
],
149+
"configuration": [
150+
"HeaderCustomization",
151+
"UICustomization",
152+
"UserSettings",
153+
"FeedbackConfig",
154+
"AuthenticationConfig",
155+
],
156+
"responses": [
157+
"FeedbackResponse",
158+
"ConfigResponse",
159+
"LoginResponse",
160+
],
161+
"requests": [
162+
"ChatRequest",
163+
"FeedbackRequest",
164+
"CredentialsLoginRequest",
165+
"LoginRequest",
166+
"LogoutRequest",
124167
],
125-
"configuration": ["HeaderCustomization", "UICustomization", "UserSettings", "FeedbackConfig"],
126-
"responses": ["FeedbackResponse", "ConfigResponse"],
127-
"requests": ["ChatRequest", "FeedbackRequest"],
128168
}
129169

130170
return self._categories_cache

packages/ragbits-chat/src/ragbits/chat/ui-build/assets/AuthGuard-C_MUoo-o.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/ragbits-chat/src/ragbits/chat/ui-build/assets/ChatHistory-Ctlh-0af.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/ragbits-chat/src/ragbits/chat/ui-build/assets/ChatHistory-DuDSKeVe.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

packages/ragbits-chat/src/ragbits/chat/ui-build/assets/ChatOptionsForm-p4X4E2d0.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

packages/ragbits-chat/src/ragbits/chat/ui-build/assets/ChatOptionsForm-v2JnxfkR.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)