streambricks 0.2.16__tar.gz → 0.2.17__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {streambricks-0.2.16 → streambricks-0.2.17}/.gitignore +1 -0
- {streambricks-0.2.16 → streambricks-0.2.17}/PKG-INFO +1 -1
- {streambricks-0.2.16 → streambricks-0.2.17}/src/streambricks/__init__.py +17 -1
- streambricks-0.2.17/src/streambricks/auth/__init__.py +14 -0
- streambricks-0.2.17/src/streambricks/auth/decorator.py +78 -0
- streambricks-0.2.17/src/streambricks/auth/helpers.py +122 -0
- streambricks-0.2.17/src/streambricks/auth/models.py +105 -0
- {streambricks-0.2.16 → streambricks-0.2.17}/.copier-answers.yml +0 -0
- {streambricks-0.2.16 → streambricks-0.2.17}/.github/FUNDING.yml +0 -0
- {streambricks-0.2.16 → streambricks-0.2.17}/.github/copilot-instructions.md +0 -0
- {streambricks-0.2.16 → streambricks-0.2.17}/.github/dependabot.yml +0 -0
- {streambricks-0.2.16 → streambricks-0.2.17}/.github/workflows/build.yml +0 -0
- {streambricks-0.2.16 → streambricks-0.2.17}/.github/workflows/documentation.yml +0 -0
- {streambricks-0.2.16 → streambricks-0.2.17}/.pre-commit-config.yaml +0 -0
- {streambricks-0.2.16 → streambricks-0.2.17}/LICENSE +0 -0
- {streambricks-0.2.16 → streambricks-0.2.17}/README.md +0 -0
- {streambricks-0.2.16 → streambricks-0.2.17}/docs/.empty +0 -0
- {streambricks-0.2.16 → streambricks-0.2.17}/duties.py +0 -0
- {streambricks-0.2.16 → streambricks-0.2.17}/mkdocs.yml +0 -0
- {streambricks-0.2.16 → streambricks-0.2.17}/overrides/_dummy.txt +0 -0
- {streambricks-0.2.16 → streambricks-0.2.17}/pyproject.toml +0 -0
- {streambricks-0.2.16 → streambricks-0.2.17}/src/streambricks/helpers.py +0 -0
- {streambricks-0.2.16 → streambricks-0.2.17}/src/streambricks/py.typed +0 -0
- {streambricks-0.2.16 → streambricks-0.2.17}/src/streambricks/state.py +0 -0
- {streambricks-0.2.16 → streambricks-0.2.17}/src/streambricks/widgets/__init__.py +0 -0
- {streambricks-0.2.16 → streambricks-0.2.17}/src/streambricks/widgets/bind_kwargs.py +0 -0
- {streambricks-0.2.16 → streambricks-0.2.17}/src/streambricks/widgets/image_capture.py +0 -0
- {streambricks-0.2.16 → streambricks-0.2.17}/src/streambricks/widgets/model_selector.py +0 -0
- {streambricks-0.2.16 → streambricks-0.2.17}/src/streambricks/widgets/model_widget/__init__.py +0 -0
- {streambricks-0.2.16 → streambricks-0.2.17}/src/streambricks/widgets/model_widget/field_metadata_renderers.py +0 -0
- {streambricks-0.2.16 → streambricks-0.2.17}/src/streambricks/widgets/model_widget/main.py +0 -0
- {streambricks-0.2.16 → streambricks-0.2.17}/src/streambricks/widgets/model_widget/type_renderers.py +0 -0
- {streambricks-0.2.16 → streambricks-0.2.17}/src/streambricks/widgets/multi_select.py +0 -0
- {streambricks-0.2.16 → streambricks-0.2.17}/src/streambricks/widgets/sequence.py +0 -0
- {streambricks-0.2.16 → streambricks-0.2.17}/src/streambricks/widgets/type_helpers.py +0 -0
- {streambricks-0.2.16 → streambricks-0.2.17}/tests/__init__.py +0 -0
- {streambricks-0.2.16 → streambricks-0.2.17}/tests/conftest.py +0 -0
- {streambricks-0.2.16 → streambricks-0.2.17}/tests/test_widgets.py +0 -0
|
@@ -1,6 +1,16 @@
|
|
|
1
|
-
|
|
1
|
+
"""StreamBricks components for Streamlit."""
|
|
2
2
|
|
|
3
|
+
__version__ = "0.2.17"
|
|
3
4
|
|
|
5
|
+
|
|
6
|
+
from streambricks.auth import (
|
|
7
|
+
GoogleUser,
|
|
8
|
+
MicrosoftUser,
|
|
9
|
+
get_current_user,
|
|
10
|
+
google_login,
|
|
11
|
+
microsoft_login,
|
|
12
|
+
requires_login,
|
|
13
|
+
)
|
|
4
14
|
from streambricks.widgets.model_widget import (
|
|
5
15
|
render_model_form as model_edit,
|
|
6
16
|
render_model_readonly as model_display,
|
|
@@ -16,14 +26,20 @@ from streambricks.state import State
|
|
|
16
26
|
from streambricks.widgets.bind_kwargs import bind_kwargs_as_widget
|
|
17
27
|
|
|
18
28
|
__all__ = [
|
|
29
|
+
"GoogleUser",
|
|
30
|
+
"MicrosoftUser",
|
|
19
31
|
"MultiSelectItem",
|
|
20
32
|
"State",
|
|
21
33
|
"bind_kwargs_as_widget",
|
|
34
|
+
"get_current_user",
|
|
35
|
+
"google_login",
|
|
22
36
|
"image_capture",
|
|
23
37
|
"llm_model_selector",
|
|
38
|
+
"microsoft_login",
|
|
24
39
|
"model_display",
|
|
25
40
|
"model_edit",
|
|
26
41
|
"model_selector",
|
|
27
42
|
"multiselect",
|
|
43
|
+
"requires_login",
|
|
28
44
|
"run",
|
|
29
45
|
]
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from streambricks.auth.decorator import requires_login
|
|
4
|
+
from streambricks.auth.helpers import get_current_user, google_login, microsoft_login
|
|
5
|
+
from streambricks.auth.models import GoogleUser, MicrosoftUser
|
|
6
|
+
|
|
7
|
+
__all__ = [
|
|
8
|
+
"GoogleUser",
|
|
9
|
+
"MicrosoftUser",
|
|
10
|
+
"get_current_user",
|
|
11
|
+
"google_login",
|
|
12
|
+
"microsoft_login",
|
|
13
|
+
"requires_login",
|
|
14
|
+
]
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import functools
|
|
4
|
+
from typing import TYPE_CHECKING, Any, ParamSpec, TypeVar
|
|
5
|
+
|
|
6
|
+
import streamlit as st
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
if TYPE_CHECKING:
|
|
10
|
+
from collections.abc import Callable
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
T = TypeVar("T")
|
|
14
|
+
P = ParamSpec("P")
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def requires_login(
|
|
18
|
+
func: Callable[P, T] | None = None,
|
|
19
|
+
*,
|
|
20
|
+
unauthorized_handler: str | Callable[[], Any] | None = None,
|
|
21
|
+
) -> Callable[P, T] | Callable[[Callable[P, T]], Callable[P, T]]:
|
|
22
|
+
"""Decorator that requires a user to be logged in via Streamlit.
|
|
23
|
+
|
|
24
|
+
Args:
|
|
25
|
+
func: The function to wrap. If None, returns a decorator.
|
|
26
|
+
unauthorized_handler: How to handle unauthorized access:
|
|
27
|
+
- If None: Shows default error message
|
|
28
|
+
- If str: Shows that string as an error message
|
|
29
|
+
- If Callable: Calls the function for custom handling
|
|
30
|
+
|
|
31
|
+
Returns:
|
|
32
|
+
Decorated function that checks login status before executing.
|
|
33
|
+
|
|
34
|
+
Examples:
|
|
35
|
+
@requires_login
|
|
36
|
+
def protected_page():
|
|
37
|
+
st.write("Protected content")
|
|
38
|
+
|
|
39
|
+
@requires_login(unauthorized_handler="Please log in first")
|
|
40
|
+
def dashboard():
|
|
41
|
+
st.write("Dashboard content")
|
|
42
|
+
|
|
43
|
+
@requires_login(unauthorized_handler=lambda: st.switch_page("pages/login.py"))
|
|
44
|
+
def analytics():
|
|
45
|
+
st.write("Analytics")
|
|
46
|
+
"""
|
|
47
|
+
|
|
48
|
+
def default_unauthorized_handler() -> None:
|
|
49
|
+
st.error("You need to be logged in to access this page")
|
|
50
|
+
st.button("Log in with Google", on_click=st.login)
|
|
51
|
+
|
|
52
|
+
def get_handler() -> Callable[[], Any]:
|
|
53
|
+
if unauthorized_handler is None:
|
|
54
|
+
return default_unauthorized_handler
|
|
55
|
+
if isinstance(unauthorized_handler, str):
|
|
56
|
+
return lambda: st.error(unauthorized_handler)
|
|
57
|
+
return unauthorized_handler
|
|
58
|
+
|
|
59
|
+
def decorator(fn: Callable[P, T]) -> Callable[P, T]:
|
|
60
|
+
@functools.wraps(fn)
|
|
61
|
+
def wrapper(*args: P.args, **kwargs: P.kwargs) -> T:
|
|
62
|
+
if hasattr(st, "experimental_user") and st.experimental_user.is_logged_in:
|
|
63
|
+
return fn(*args, **kwargs)
|
|
64
|
+
|
|
65
|
+
# Handle unauthorized access
|
|
66
|
+
handler = get_handler()
|
|
67
|
+
handler()
|
|
68
|
+
|
|
69
|
+
# Return early with None
|
|
70
|
+
return None # type: ignore
|
|
71
|
+
|
|
72
|
+
return wrapper
|
|
73
|
+
|
|
74
|
+
# Handle both @requires_login and @requires_login()
|
|
75
|
+
if func is None:
|
|
76
|
+
return decorator
|
|
77
|
+
|
|
78
|
+
return decorator(func)
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from typing import Any, TypeVar, overload
|
|
4
|
+
|
|
5
|
+
import streamlit as st
|
|
6
|
+
|
|
7
|
+
from streambricks.auth.models import GoogleUser, MicrosoftUser
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
T = TypeVar("T", GoogleUser, MicrosoftUser)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def _get_user_data() -> dict[str, Any] | None:
|
|
14
|
+
"""Get user data from either experimental_user or stable user attribute."""
|
|
15
|
+
# Try stable version first
|
|
16
|
+
if hasattr(st, "user") and getattr(st.user, "is_logged_in", False): # pyright: ignore
|
|
17
|
+
return {**st.user} # pyright: ignore
|
|
18
|
+
|
|
19
|
+
# Fall back to experimental version
|
|
20
|
+
if hasattr(st, "experimental_user") and st.experimental_user.is_logged_in:
|
|
21
|
+
return {**st.experimental_user}
|
|
22
|
+
|
|
23
|
+
return None
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def google_login(
|
|
27
|
+
button_text: str = "Login with Google",
|
|
28
|
+
redirect_url: str | None = None,
|
|
29
|
+
key: str | None = None,
|
|
30
|
+
) -> GoogleUser | None:
|
|
31
|
+
"""Authenticate user with Google and return typed user object if successful.
|
|
32
|
+
|
|
33
|
+
Args:
|
|
34
|
+
button_text: Text to display on the login button
|
|
35
|
+
redirect_url: URL to redirect to after successful login
|
|
36
|
+
key: Streamlit widget key for the login button
|
|
37
|
+
|
|
38
|
+
Returns:
|
|
39
|
+
GoogleUser object if login successful, None otherwise
|
|
40
|
+
"""
|
|
41
|
+
user_data = _get_user_data()
|
|
42
|
+
if user_data is not None:
|
|
43
|
+
# User is already logged in, return typed user object
|
|
44
|
+
return GoogleUser(is_logged_in=True, **user_data) # pyright: ignore
|
|
45
|
+
|
|
46
|
+
# User not logged in, display login button
|
|
47
|
+
if st.button(button_text, key=key):
|
|
48
|
+
# The provider parameter should match what's configured in secrets.toml
|
|
49
|
+
st.login("google")
|
|
50
|
+
|
|
51
|
+
return None
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def microsoft_login(
|
|
55
|
+
button_text: str = "Login with Microsoft",
|
|
56
|
+
redirect_url: str | None = None,
|
|
57
|
+
key: str | None = None,
|
|
58
|
+
) -> MicrosoftUser | None:
|
|
59
|
+
"""Authenticate user with Microsoft and return typed user object if successful.
|
|
60
|
+
|
|
61
|
+
Args:
|
|
62
|
+
button_text: Text to display on the login button
|
|
63
|
+
redirect_url: URL to redirect to after successful login
|
|
64
|
+
key: Streamlit widget key for the login button
|
|
65
|
+
|
|
66
|
+
Returns:
|
|
67
|
+
MicrosoftUser object if login successful, None otherwise
|
|
68
|
+
"""
|
|
69
|
+
user_data = _get_user_data()
|
|
70
|
+
if user_data is not None:
|
|
71
|
+
# User is already logged in, return typed user object
|
|
72
|
+
return MicrosoftUser(is_logged_in=True, **user_data) # pyright: ignore
|
|
73
|
+
|
|
74
|
+
# User not logged in, display login button
|
|
75
|
+
if st.button(button_text, key=key):
|
|
76
|
+
# The provider parameter should match what's configured in secrets.toml
|
|
77
|
+
st.login("microsoft")
|
|
78
|
+
|
|
79
|
+
return None
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
@overload
|
|
83
|
+
def get_current_user(user_class: type[T]) -> T: ...
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
@overload
|
|
87
|
+
def get_current_user() -> GoogleUser | MicrosoftUser | None: ...
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
def get_current_user(
|
|
91
|
+
user_class: type[T] | None = None,
|
|
92
|
+
) -> T | GoogleUser | MicrosoftUser | None:
|
|
93
|
+
"""Get the currently logged in user as a typed object.
|
|
94
|
+
|
|
95
|
+
Args:
|
|
96
|
+
user_class: The class to use for the user model (GoogleUser or MicrosoftUser).
|
|
97
|
+
If specified, errors will be raised if the data doesn't match.
|
|
98
|
+
|
|
99
|
+
Returns:
|
|
100
|
+
Typed user object if logged in and matching requested type,
|
|
101
|
+
None if no user_class specified and no user is logged in
|
|
102
|
+
|
|
103
|
+
Raises:
|
|
104
|
+
Various exceptions: If the user data doesn't match the requested model,
|
|
105
|
+
the original validation exceptions from Pydantic will be raised
|
|
106
|
+
"""
|
|
107
|
+
user_data = _get_user_data()
|
|
108
|
+
if user_data is None:
|
|
109
|
+
if user_class is not None:
|
|
110
|
+
msg = "No user is currently logged in"
|
|
111
|
+
raise ValueError(msg)
|
|
112
|
+
return None
|
|
113
|
+
|
|
114
|
+
if user_class is not None:
|
|
115
|
+
return user_class(is_logged_in=True, **user_data) # pyright: ignore
|
|
116
|
+
try:
|
|
117
|
+
return GoogleUser(is_logged_in=True, **user_data) # pyright: ignore
|
|
118
|
+
except Exception: # noqa: BLE001
|
|
119
|
+
try:
|
|
120
|
+
return MicrosoftUser(is_logged_in=True, **user_data) # pyright: ignore
|
|
121
|
+
except Exception: # noqa: BLE001
|
|
122
|
+
return None
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from pydantic import BaseModel, ConfigDict, Field
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class MicrosoftUser(BaseModel):
|
|
7
|
+
"""Microsoft Identity Token information from Streamlit's experimental_user."""
|
|
8
|
+
|
|
9
|
+
model_config = ConfigDict(use_attribute_docstrings=True)
|
|
10
|
+
|
|
11
|
+
is_logged_in: bool
|
|
12
|
+
"""Whether the user is currently logged in"""
|
|
13
|
+
|
|
14
|
+
ver: str
|
|
15
|
+
"""Version of the token format"""
|
|
16
|
+
|
|
17
|
+
iss: str
|
|
18
|
+
"""The service that issued the token"""
|
|
19
|
+
|
|
20
|
+
sub: str
|
|
21
|
+
"""Subject identifier for the user"""
|
|
22
|
+
|
|
23
|
+
application_id: str = Field(alias="aud")
|
|
24
|
+
"""Intended recipient of the token (your application)"""
|
|
25
|
+
|
|
26
|
+
expiration_time: int = Field(alias="exp")
|
|
27
|
+
"""Timestamp when the token expires"""
|
|
28
|
+
|
|
29
|
+
issued_time: int = Field(alias="iat")
|
|
30
|
+
"""Timestamp when the token was issued"""
|
|
31
|
+
|
|
32
|
+
start_time: int = Field(alias="nbf")
|
|
33
|
+
"""Timestamp when the token becomes valid"""
|
|
34
|
+
|
|
35
|
+
name: str
|
|
36
|
+
"""Complete name of the user"""
|
|
37
|
+
|
|
38
|
+
username: str = Field(alias="preferred_username")
|
|
39
|
+
"""Preferred username for the user account"""
|
|
40
|
+
|
|
41
|
+
user_id: str = Field(alias="oid")
|
|
42
|
+
"""Unique Microsoft identifier for the user"""
|
|
43
|
+
|
|
44
|
+
email: str
|
|
45
|
+
"""Email address of the authenticated user"""
|
|
46
|
+
|
|
47
|
+
tenant_id: str = Field(alias="tid")
|
|
48
|
+
"""Microsoft Entra tenant identifier"""
|
|
49
|
+
|
|
50
|
+
nonce: str
|
|
51
|
+
"""One-time value to prevent replay attacks"""
|
|
52
|
+
|
|
53
|
+
aio: str
|
|
54
|
+
"""Internal Microsoft authentication tracking information"""
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
class GoogleUser(BaseModel):
|
|
58
|
+
"""Google Identity Token information from Streamlit's experimental_user."""
|
|
59
|
+
|
|
60
|
+
model_config = ConfigDict(use_attribute_docstrings=True, extra="allow")
|
|
61
|
+
|
|
62
|
+
is_logged_in: bool
|
|
63
|
+
"""Authentication status of the user"""
|
|
64
|
+
|
|
65
|
+
iss: str
|
|
66
|
+
"""The service that issued the token"""
|
|
67
|
+
|
|
68
|
+
authorized_party: str = Field(alias="azp")
|
|
69
|
+
"""The client that was authorized to receive the token"""
|
|
70
|
+
|
|
71
|
+
client_id: str = Field(alias="aud")
|
|
72
|
+
"""Intended recipient of the token (your application)"""
|
|
73
|
+
|
|
74
|
+
user_id: str = Field(alias="sub")
|
|
75
|
+
"""Unique Google identifier for the user"""
|
|
76
|
+
|
|
77
|
+
email: str
|
|
78
|
+
"""Email address of the authenticated user"""
|
|
79
|
+
|
|
80
|
+
email_verified: bool
|
|
81
|
+
"""Confirmation that Google has verified the email address"""
|
|
82
|
+
|
|
83
|
+
access_token_hash: str = Field(alias="at_hash")
|
|
84
|
+
"""Hash of access token for security validation"""
|
|
85
|
+
|
|
86
|
+
nonce: str
|
|
87
|
+
"""One-time value to prevent replay attacks"""
|
|
88
|
+
|
|
89
|
+
name: str
|
|
90
|
+
"""Complete name of the user"""
|
|
91
|
+
|
|
92
|
+
picture: str
|
|
93
|
+
"""Link to the user's Google profile image"""
|
|
94
|
+
|
|
95
|
+
given_name: str
|
|
96
|
+
"""First/given name of the user"""
|
|
97
|
+
|
|
98
|
+
family_name: str
|
|
99
|
+
"""Last/family name of the user"""
|
|
100
|
+
|
|
101
|
+
issued_time: int = Field(alias="iat")
|
|
102
|
+
"""Timestamp when the token was issued"""
|
|
103
|
+
|
|
104
|
+
expiration_time: int = Field(alias="exp")
|
|
105
|
+
"""Timestamp when the token expires"""
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{streambricks-0.2.16 → streambricks-0.2.17}/src/streambricks/widgets/model_widget/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{streambricks-0.2.16 → streambricks-0.2.17}/src/streambricks/widgets/model_widget/type_renderers.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|