sweatstack 0.13.2__py3-none-any.whl → 0.14.1__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 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,59 +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, set_env_var=False, client_id=None, client_secret=None, scope=None, redirect_uri=None):
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 = cookie_controller.get("sweatstack_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
- cookie_controller.remove("sweatstack_api_key")
52
- if self.set_env_var:
53
- os.environ.pop("SWEATSTACK_API_KEY")
39
+ st.session_state.pop("sweatstack_api_key")
54
40
  st.rerun()
55
41
 
56
42
  def _show_sweatstack_login(self):
57
43
  st.link_button("Login", self._get_authorization_url_implicit())
58
44
 
59
45
  def _get_authorization_url_implicit(self):
60
- code_verifier = secrets.token_urlsafe(32)
61
- cookie_controller.set("code_verifier", code_verifier)
62
- code_challenge = hashlib.sha256(code_verifier.encode("ascii")).digest()
63
- code_challenge = base64.urlsafe_b64encode(code_challenge).rstrip(b"=").decode("ascii")
64
-
65
46
  params = {
66
47
  "client_id": self.client_id,
67
48
  "redirect_uri": self.redirect_uri,
68
- "code_challenge": code_challenge,
69
49
  "scope": "data:read",
70
50
  }
71
51
  path = "/oauth/authorize"
@@ -73,17 +53,15 @@ class StreamlitAuth:
73
53
 
74
54
  return authorization_url
75
55
 
76
-
77
- def _exchange_token_implicit(self, code):
78
- code_verifier = cookie_controller.get("code_verifier")
56
+ def _exchange_token(self, code):
79
57
  token_data = {
80
58
  "grant_type": "authorization_code",
81
59
  "client_id": self.client_id,
60
+ "client_secret": self.client_secret,
82
61
  "code": code,
83
- "code_verifier": code_verifier
84
62
  }
85
63
  response = httpx.post(
86
- f"{DEFAULT_URL}/oauth/token",
64
+ f"{DEFAULT_URL}/api/v1/oauth/token",
87
65
  data=token_data,
88
66
  )
89
67
  try:
@@ -93,14 +71,10 @@ class StreamlitAuth:
93
71
  token_response = response.json()
94
72
 
95
73
  self.api_key = token_response.get("access_token")
96
- cookie_controller.set("sweatstack_api_key", self.api_key)
97
- if self.set_env_var:
98
- os.environ["SWEATSTACK_API_KEY"] = self.api_key
74
+ st.session_state["sweatstack_api_key"] = self.api_key
99
75
 
100
76
  self.client = Client(self.api_key)
101
77
 
102
- cookie_controller.remove("code_verifier")
103
-
104
78
  return
105
79
 
106
80
  def is_authenticated(self):
@@ -110,7 +84,7 @@ class StreamlitAuth:
110
84
  if self.is_authenticated():
111
85
  self._show_sweatstack_logout()
112
86
  elif code := st.query_params.get("code"):
113
- self._exchange_token_implicit(code)
87
+ self._exchange_token(code)
114
88
  st.query_params.clear()
115
89
  st.rerun()
116
90
  else:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: sweatstack
3
- Version: 0.13.2
3
+ Version: 0.14.1
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=0OE26TPMEwtIbm18E0JXE9fyJW_bER_wrOp90EC5C1g,4317
10
+ sweatstack/streamlit.py,sha256=8RLMklQmpwyoRuLQDUeeGAveRvYu5PoBBay2ecOV5FM,3268
11
11
  sweatstack/sweatshell.py,sha256=MYLNcWbOdceqKJ3S0Pe8dwHXEeYsGJNjQoYUXpMTftA,333
12
12
  sweatstack/utils.py,sha256=0DcvHV1EOHQnN5OlfYo2DRrw8a9-6YkxTjLVCfi5ylE,277
13
- sweatstack-0.13.2.dist-info/METADATA,sha256=OZgehws5KkzNtvyHbyaMKRn31R8YJ6iG7usrbFl-jaQ,3039
14
- sweatstack-0.13.2.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
15
- sweatstack-0.13.2.dist-info/entry_points.txt,sha256=kCzOUQI3dqbTpEYqtgYDeiKFaqaA7BMlV6D24BMzCFU,208
16
- sweatstack-0.13.2.dist-info/RECORD,,
13
+ sweatstack-0.14.1.dist-info/METADATA,sha256=A7gRbsBnp_lEH5YxR0YfmJCxECOMTHXTE2g3d29g4rU,2966
14
+ sweatstack-0.14.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
15
+ sweatstack-0.14.1.dist-info/entry_points.txt,sha256=kCzOUQI3dqbTpEYqtgYDeiKFaqaA7BMlV6D24BMzCFU,208
16
+ sweatstack-0.14.1.dist-info/RECORD,,