sweatstack 0.13.1__py3-none-any.whl → 0.14.0__py3-none-any.whl
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.
- sweatstack/streamlit.py +8 -33
- {sweatstack-0.13.1.dist-info → sweatstack-0.14.0.dist-info}/METADATA +1 -2
- {sweatstack-0.13.1.dist-info → sweatstack-0.14.0.dist-info}/RECORD +5 -5
- {sweatstack-0.13.1.dist-info → sweatstack-0.14.0.dist-info}/WHEEL +0 -0
- {sweatstack-0.13.1.dist-info → sweatstack-0.14.0.dist-info}/entry_points.txt +0 -0
sweatstack/streamlit.py
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
import hashlib
|
|
2
|
-
import base64
|
|
3
1
|
import os
|
|
4
|
-
import secrets
|
|
5
2
|
import urllib.parse
|
|
6
3
|
|
|
7
4
|
try:
|
|
@@ -13,58 +10,42 @@ except ImportError:
|
|
|
13
10
|
"pip install 'sweatstack[streamlit]'\n\n"
|
|
14
11
|
)
|
|
15
12
|
import httpx
|
|
16
|
-
from streamlit_cookies_controller import CookieController
|
|
17
13
|
from sweatstack import Client
|
|
18
14
|
|
|
19
15
|
from .constants import DEFAULT_URL
|
|
20
16
|
|
|
21
17
|
|
|
22
|
-
cookie_controller = CookieController()
|
|
23
|
-
|
|
24
|
-
|
|
25
18
|
class StreamlitAuth:
|
|
26
|
-
def __init__(self,
|
|
19
|
+
def __init__(self, client_id=None, client_secret=None, scope=None, redirect_uri=None):
|
|
27
20
|
"""
|
|
28
21
|
Args:
|
|
29
|
-
set_env_var: Whether to set the SWEATSTACK_API_KEY environment variable. Default is False.
|
|
30
22
|
client_id: The client ID to use. If not provided, the SWEATSTACK_CLIENT_ID environment variable will be used.
|
|
31
23
|
client_secret: The client secret to use. If not provided, the SWEATSTACK_CLIENT_SECRET environment variable will be used.
|
|
32
24
|
scope: The scope to use. If not provided, the SWEATSTACK_SCOPE environment variable will be used.
|
|
33
25
|
redirect_uri: The redirect URI to use. If not provided, the SWEATSTACK_REDIRECT_URI environment variable will be used.
|
|
34
26
|
"""
|
|
35
|
-
self.set_env_var = set_env_var
|
|
36
27
|
self.client_id = client_id or os.environ.get("SWEATSTACK_CLIENT_ID")
|
|
37
28
|
self.client_secret = client_secret or os.environ.get("SWEATSTACK_CLIENT_SECRET")
|
|
38
29
|
self.scope = scope or os.environ.get("SWEATSTACK_SCOPE")
|
|
39
30
|
self.redirect_uri = redirect_uri or os.environ.get("SWEATSTACK_REDIRECT_URI")
|
|
40
31
|
|
|
41
|
-
self.api_key =
|
|
32
|
+
self.api_key = st.session_state.get("sweatstack_api_key")
|
|
42
33
|
self.client = Client(self.api_key)
|
|
43
34
|
|
|
44
|
-
if self.api_key and self.set_env_var:
|
|
45
|
-
os.environ["SWEATSTACK_API_KEY"] = self.api_key
|
|
46
|
-
|
|
47
35
|
def _show_sweatstack_logout(self):
|
|
48
36
|
if st.button("Logout"):
|
|
49
37
|
self.api_key = None
|
|
50
38
|
self.client = Client()
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
os.environ.pop("SWEATSTACK_API_KEY")
|
|
39
|
+
st.session_state.pop("sweatstack_api_key")
|
|
40
|
+
st.rerun()
|
|
54
41
|
|
|
55
42
|
def _show_sweatstack_login(self):
|
|
56
43
|
st.link_button("Login", self._get_authorization_url_implicit())
|
|
57
44
|
|
|
58
45
|
def _get_authorization_url_implicit(self):
|
|
59
|
-
code_verifier = secrets.token_urlsafe(32)
|
|
60
|
-
cookie_controller.set("code_verifier", code_verifier)
|
|
61
|
-
code_challenge = hashlib.sha256(code_verifier.encode("ascii")).digest()
|
|
62
|
-
code_challenge = base64.urlsafe_b64encode(code_challenge).rstrip(b"=").decode("ascii")
|
|
63
|
-
|
|
64
46
|
params = {
|
|
65
47
|
"client_id": self.client_id,
|
|
66
48
|
"redirect_uri": self.redirect_uri,
|
|
67
|
-
"code_challenge": code_challenge,
|
|
68
49
|
"scope": "data:read",
|
|
69
50
|
}
|
|
70
51
|
path = "/oauth/authorize"
|
|
@@ -72,14 +53,12 @@ class StreamlitAuth:
|
|
|
72
53
|
|
|
73
54
|
return authorization_url
|
|
74
55
|
|
|
75
|
-
|
|
76
|
-
def _exchange_token_implicit(self, code):
|
|
77
|
-
code_verifier = cookie_controller.get("code_verifier")
|
|
56
|
+
def _exchange_token(self, code):
|
|
78
57
|
token_data = {
|
|
79
58
|
"grant_type": "authorization_code",
|
|
80
59
|
"client_id": self.client_id,
|
|
60
|
+
"client_secret": self.client_secret,
|
|
81
61
|
"code": code,
|
|
82
|
-
"code_verifier": code_verifier
|
|
83
62
|
}
|
|
84
63
|
response = httpx.post(
|
|
85
64
|
f"{DEFAULT_URL}/oauth/token",
|
|
@@ -92,14 +71,10 @@ class StreamlitAuth:
|
|
|
92
71
|
token_response = response.json()
|
|
93
72
|
|
|
94
73
|
self.api_key = token_response.get("access_token")
|
|
95
|
-
|
|
96
|
-
if self.set_env_var:
|
|
97
|
-
os.environ["SWEATSTACK_API_KEY"] = self.api_key
|
|
74
|
+
st.session_state["sweatstack_api_key"] = self.api_key
|
|
98
75
|
|
|
99
76
|
self.client = Client(self.api_key)
|
|
100
77
|
|
|
101
|
-
cookie_controller.remove("code_verifier")
|
|
102
|
-
|
|
103
78
|
return
|
|
104
79
|
|
|
105
80
|
def is_authenticated(self):
|
|
@@ -109,7 +84,7 @@ class StreamlitAuth:
|
|
|
109
84
|
if self.is_authenticated():
|
|
110
85
|
self._show_sweatstack_logout()
|
|
111
86
|
elif code := st.query_params.get("code"):
|
|
112
|
-
self.
|
|
87
|
+
self._exchange_token(code)
|
|
113
88
|
st.query_params.clear()
|
|
114
89
|
st.rerun()
|
|
115
90
|
else:
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: sweatstack
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.14.0
|
|
4
4
|
Summary: The official Python client for SweatStack
|
|
5
5
|
Author-email: Aart Goossens <aart@gssns.io>
|
|
6
6
|
Requires-Python: >=3.12
|
|
@@ -13,7 +13,6 @@ Requires-Dist: ipython>=8.31.0; extra == 'jupyterlab'
|
|
|
13
13
|
Requires-Dist: jupyterlab>=4.3.4; extra == 'jupyterlab'
|
|
14
14
|
Requires-Dist: matplotlib; extra == 'jupyterlab'
|
|
15
15
|
Provides-Extra: streamlit
|
|
16
|
-
Requires-Dist: streamlit-cookies-controller>=0.0.4; extra == 'streamlit'
|
|
17
16
|
Requires-Dist: streamlit>=1.42.0; extra == 'streamlit'
|
|
18
17
|
Description-Content-Type: text/markdown
|
|
19
18
|
|
|
@@ -7,10 +7,10 @@ sweatstack/jupyterlab_oauth2_startup.py,sha256=eZ6xi0Sa4hO4vUanimq0SqjduHtiywCUR
|
|
|
7
7
|
sweatstack/openapi_schemas.py,sha256=vtYHa6A0kADFbd_jK1O7Kbn8YkbPfzaIwsRDDYjYeSA,13038
|
|
8
8
|
sweatstack/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
9
9
|
sweatstack/schemas.py,sha256=CdkeV6IRmIuvxae7C5dz-hVlb6hkzEYfqKHHgVJprmY,90
|
|
10
|
-
sweatstack/streamlit.py,sha256=
|
|
10
|
+
sweatstack/streamlit.py,sha256=DmKnx5LgK7HJxQ2auloXzGEmK5P1xHNT42quS6xWPac,3261
|
|
11
11
|
sweatstack/sweatshell.py,sha256=MYLNcWbOdceqKJ3S0Pe8dwHXEeYsGJNjQoYUXpMTftA,333
|
|
12
12
|
sweatstack/utils.py,sha256=0DcvHV1EOHQnN5OlfYo2DRrw8a9-6YkxTjLVCfi5ylE,277
|
|
13
|
-
sweatstack-0.
|
|
14
|
-
sweatstack-0.
|
|
15
|
-
sweatstack-0.
|
|
16
|
-
sweatstack-0.
|
|
13
|
+
sweatstack-0.14.0.dist-info/METADATA,sha256=OCzxaI0oICWD7GuHSjDyNbPiz54sWU3EHL9fspPgOf0,2966
|
|
14
|
+
sweatstack-0.14.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
15
|
+
sweatstack-0.14.0.dist-info/entry_points.txt,sha256=kCzOUQI3dqbTpEYqtgYDeiKFaqaA7BMlV6D24BMzCFU,208
|
|
16
|
+
sweatstack-0.14.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|