usso 0.10.0__tar.gz → 0.12.0__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: usso
3
- Version: 0.10.0
3
+ Version: 0.12.0
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>
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "usso"
7
- version = "0.10.0"
7
+ version = "0.12.0"
8
8
  description = "A plug-and-play client for integrating universal single sign-on (SSO) with Python frameworks, enabling secure and seamless authentication across microservices."
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.8"
@@ -0,0 +1 @@
1
+ from .core import UserData
@@ -29,6 +29,10 @@ class UserData(BaseModel):
29
29
 
30
30
  return uuid.UUID(user_id)
31
31
 
32
+ @property
33
+ def b64id(self) -> uuid.UUID:
34
+ return b64tools.b64_encode_uuid_strip(self.uid)
35
+
32
36
 
33
37
  def get_authorization_scheme_param(
34
38
  authorization_header_value: Optional[str],
@@ -0,0 +1 @@
1
+ from .integration import jwt_access_security, user_data_from_token
@@ -1,7 +1,7 @@
1
1
  import logging
2
2
 
3
3
  import jwt
4
- from fastapi import Request
4
+ from fastapi import Request, WebSocket
5
5
  from starlette.status import HTTP_401_UNAUTHORIZED
6
6
 
7
7
  from usso.core import UserData, get_authorization_scheme_param, get_jwks_keys
@@ -77,3 +77,25 @@ async def jwt_access_security(request: Request) -> UserData | None:
77
77
  error="unauthorized",
78
78
  )
79
79
  return None
80
+
81
+
82
+ async def jwt_access_security_ws(websocket: WebSocket) -> UserData | None:
83
+ """Return the user associated with a token value."""
84
+ kwargs = {}
85
+ authorization = websocket.headers.get("Authorization")
86
+ if authorization:
87
+ scheme, _, credentials = get_authorization_scheme_param(authorization)
88
+ if scheme.lower() == "bearer":
89
+ token = credentials
90
+ return await user_data_from_token(token, **kwargs)
91
+
92
+ cookie_token = websocket.cookies.get("access_token")
93
+ if cookie_token:
94
+ return await user_data_from_token(cookie_token, **kwargs)
95
+
96
+ if kwargs.get("raise_exception", True):
97
+ raise USSOException(
98
+ status_code=HTTP_401_UNAUTHORIZED,
99
+ error="unauthorized",
100
+ )
101
+ return None
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: usso
3
- Version: 0.10.0
3
+ Version: 0.12.0
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>
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