usso 0.27.20__py3-none-any.whl → 0.27.22__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.
@@ -29,14 +29,16 @@ class AsyncUssoSession(httpx.AsyncClient, BaseUssoSession):
29
29
  user_id=user_id,
30
30
  client=client,
31
31
  )
32
- if not self.api_key:
32
+ if not hasattr(self, "api_key") or not self.api_key:
33
33
  self._refresh_sync()
34
34
 
35
35
  def _prepare_refresh_request(self) -> tuple[dict, dict]:
36
36
  """
37
37
  Helper function to prepare headers and parameters for refresh requests.
38
38
  """
39
- headers = {"x-api-key": self.usso_api_key} if self.usso_api_key else {}
39
+ headers = (
40
+ {"x-api-key": self.usso_admin_api_key} if self.usso_admin_api_key else {}
41
+ )
40
42
  params = {"user_id": self.user_id} if self.user_id else {}
41
43
  return headers, params
42
44
 
@@ -54,12 +56,12 @@ class AsyncUssoSession(httpx.AsyncClient, BaseUssoSession):
54
56
 
55
57
  def _refresh_sync(self) -> dict:
56
58
  assert (
57
- self.refresh_token or self.usso_api_key
59
+ self.refresh_token or self.usso_admin_api_key
58
60
  ), "refresh_token or usso_api_key is required"
59
61
 
60
62
  headers, params = self._prepare_refresh_request()
61
63
 
62
- if self.usso_api_key and not self.refresh_token:
64
+ if self.usso_admin_api_key and not self.refresh_token:
63
65
  response = httpx.get(
64
66
  f"{self.usso_refresh_url}/api", headers=headers, params=params
65
67
  )
@@ -72,12 +74,12 @@ class AsyncUssoSession(httpx.AsyncClient, BaseUssoSession):
72
74
 
73
75
  async def _refresh(self) -> dict:
74
76
  assert (
75
- self.refresh_token or self.usso_api_key
77
+ self.refresh_token or self.usso_admin_api_key
76
78
  ), "refresh_token or usso_api_key is required"
77
79
 
78
80
  headers, params = self._prepare_refresh_request()
79
81
 
80
- if self.usso_api_key and not self.refresh_token:
82
+ if self.usso_admin_api_key and not self.refresh_token:
81
83
  response = await self.get(
82
84
  f"{self.usso_refresh_url}/api", headers=headers, params=params
83
85
  )
@@ -89,7 +91,7 @@ class AsyncUssoSession(httpx.AsyncClient, BaseUssoSession):
89
91
  return self._handle_refresh_response(response)
90
92
 
91
93
  async def get_session(self):
92
- if self.api_key:
94
+ if hasattr(self, "api_key") and self.api_key:
93
95
  return self
94
96
 
95
97
  if not self.access_token or is_expired(self.access_token):
@@ -2,9 +2,7 @@ import os
2
2
  from urllib.parse import urlparse
3
3
 
4
4
  from usso.core import is_expired
5
- from typing import Optional, Any, Callable
6
- import inspect
7
-
5
+ from typing import Optional
8
6
 
9
7
 
10
8
  class BaseUssoSession:
@@ -61,7 +59,10 @@ class BaseUssoSession:
61
59
 
62
60
  if api_key:
63
61
  self.api_key = api_key
62
+ self.headers = self.headers or {}
64
63
  self.headers.update({"x-api-key": api_key})
64
+ else:
65
+ self.api_key = None
65
66
 
66
67
  if not usso_base_url:
67
68
  url_parts = urlparse(usso_refresh_url)
usso/session/session.py CHANGED
@@ -40,11 +40,11 @@ class UssoSession(httpx.Client, BaseUssoSession):
40
40
  self._refresh()
41
41
 
42
42
  def _refresh_api(self):
43
- assert self.usso_api_key, "usso_api_key is required"
43
+ assert self.usso_admin_api_key, "usso_api_key is required"
44
44
  params = {"user_id": self.user_id} if self.user_id else {}
45
45
  response = httpx.get(
46
46
  f"{self.usso_refresh_url}/api",
47
- headers={"x-api-key": self.usso_api_key},
47
+ headers={"x-api-key": self.usso_admin_api_key},
48
48
  params=params,
49
49
  )
50
50
  response.raise_for_status()
@@ -53,10 +53,10 @@ class UssoSession(httpx.Client, BaseUssoSession):
53
53
 
54
54
  def _refresh(self):
55
55
  assert (
56
- self.refresh_token or self.usso_api_key
56
+ self.refresh_token or self.usso_admin_api_key
57
57
  ), "refresh_token or usso_api_key is required"
58
58
 
59
- if self.usso_api_key and not self.refresh_token:
59
+ if self.usso_admin_api_key and not self.refresh_token:
60
60
  self._refresh_api()
61
61
 
62
62
  response = httpx.post(
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: usso
3
- Version: 0.27.20
3
+ Version: 0.27.22
4
4
  Summary: A plug-and-play client for integrating universal single sign-on (SSO) with Python frameworks, enabling secure and seamless authentication across microservices.
5
5
  Author-email: Mahdi Kiani <mahdikiany@gmail.com>
6
6
  Maintainer-email: Mahdi Kiani <mahdikiany@gmail.com>
@@ -11,12 +11,12 @@ usso/django/middleware.py,sha256=EEEpHvMQ6QiWw2HY8zQ2Aec0RCATcLWsCKeyiPWJKio,324
11
11
  usso/fastapi/__init__.py,sha256=0EcdOzb4f3yu9nILIdGWnlyUz-0VaVX2az1e3f2BusI,201
12
12
  usso/fastapi/integration.py,sha256=IonxxNj_B9sG2j672rIzE047qo972vk7ch4-eGENp3Q,2638
13
13
  usso/session/__init__.py,sha256=tE4qWUdSI7iN_pywm47Mg8NKOTBa2nCNwCy3wCZWRmU,124
14
- usso/session/async_session.py,sha256=CLtgIXcLF0if_VX1x0IJK_RpVEu1waUw69x4YVj4xxU,3517
15
- usso/session/base_session.py,sha256=wZ96VPf0zz8zDRtjJrOmZ2S4XvEBLLZAc74A4iDy7G4,3369
16
- usso/session/session.py,sha256=bjG0-WJIzNPTW1dKG1kKcwiXDNtRq-fZ__G2wNME-Lw,2545
17
- usso-0.27.20.dist-info/LICENSE.txt,sha256=ceC9ZJOV9H6CtQDcYmHOS46NA3dHJ_WD4J9blH513pc,1081
18
- usso-0.27.20.dist-info/METADATA,sha256=IHOr6tLj0dSr4TRTKNcxYIfhxVhI9B1b5ob6u4eL-7s,4580
19
- usso-0.27.20.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
20
- usso-0.27.20.dist-info/entry_points.txt,sha256=4Zgpm5ELaAWPf0jPGJFz1_X69H7un8ycT3WdGoJ0Vvk,35
21
- usso-0.27.20.dist-info/top_level.txt,sha256=g9Jf6h1Oyidh0vPiFni7UHInTJjSvu6cUalpLTIvthg,5
22
- usso-0.27.20.dist-info/RECORD,,
14
+ usso/session/async_session.py,sha256=bOWUeBpE2reDdK9zXrD4ZrZrRWlEOyyafWgPcLg2WLY,3638
15
+ usso/session/base_session.py,sha256=1Ad6LbX8IsCPTeEIopnYwybrkPkN5zgGUobv8VHcipA,3430
16
+ usso/session/session.py,sha256=T3v3lGvLxs4Yi-zZRzdKHLxEo2rtVewcLk-1V6Y44Jk,2569
17
+ usso-0.27.22.dist-info/LICENSE.txt,sha256=ceC9ZJOV9H6CtQDcYmHOS46NA3dHJ_WD4J9blH513pc,1081
18
+ usso-0.27.22.dist-info/METADATA,sha256=_di-fqd1GQaRLFMQHK2aVHv6xApGgeOEPlYYjqoI15E,4580
19
+ usso-0.27.22.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
20
+ usso-0.27.22.dist-info/entry_points.txt,sha256=4Zgpm5ELaAWPf0jPGJFz1_X69H7un8ycT3WdGoJ0Vvk,35
21
+ usso-0.27.22.dist-info/top_level.txt,sha256=g9Jf6h1Oyidh0vPiFni7UHInTJjSvu6cUalpLTIvthg,5
22
+ usso-0.27.22.dist-info/RECORD,,
File without changes