usso 0.18.0__py3-none-any.whl → 0.20.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.
- usso/__init__.py +2 -2
- usso/api.py +104 -35
- usso/core.py +2 -2
- {usso-0.18.0.dist-info → usso-0.20.0.dist-info}/METADATA +1 -1
- usso-0.20.0.dist-info/RECORD +14 -0
- usso-0.18.0.dist-info/RECORD +0 -14
- {usso-0.18.0.dist-info → usso-0.20.0.dist-info}/LICENSE.txt +0 -0
- {usso-0.18.0.dist-info → usso-0.20.0.dist-info}/WHEEL +0 -0
- {usso-0.18.0.dist-info → usso-0.20.0.dist-info}/entry_points.txt +0 -0
- {usso-0.18.0.dist-info → usso-0.20.0.dist-info}/top_level.txt +0 -0
usso/__init__.py
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
from .core import UserData,
|
1
|
+
from .core import UserData, Usso
|
2
2
|
|
3
|
-
__all__ = ["UserData", "
|
3
|
+
__all__ = ["UserData", "Usso"]
|
usso/api.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
import requests
|
2
2
|
from singleton import Singleton
|
3
3
|
|
4
|
-
from usso.core import Usso
|
4
|
+
from usso.core import UserData, Usso
|
5
5
|
|
6
6
|
|
7
7
|
class UssoAPI(metaclass=Singleton):
|
@@ -11,6 +11,8 @@ class UssoAPI(metaclass=Singleton):
|
|
11
11
|
api_key: str = None,
|
12
12
|
refresh_token: str = None,
|
13
13
|
):
|
14
|
+
if url and not url.startswith("http"):
|
15
|
+
url = f"https://{url}"
|
14
16
|
self.url = url
|
15
17
|
assert (
|
16
18
|
api_key or refresh_token
|
@@ -19,19 +21,22 @@ class UssoAPI(metaclass=Singleton):
|
|
19
21
|
self.refresh_token = refresh_token
|
20
22
|
self.access_token = None
|
21
23
|
|
22
|
-
def
|
24
|
+
def _refresh(self):
|
23
25
|
if not self.refresh_token:
|
24
26
|
return
|
25
27
|
|
26
28
|
url = f"{self.url}/auth/refresh"
|
27
29
|
|
28
30
|
if self.refresh_token:
|
29
|
-
headers = {
|
31
|
+
headers = {
|
32
|
+
"Authorization": f"Bearer {self.refresh_token}",
|
33
|
+
"content-type": "application/json",
|
34
|
+
}
|
30
35
|
|
31
36
|
resp = requests.post(url, headers=headers)
|
32
37
|
self.access_token = resp.json().get("access_token")
|
33
38
|
|
34
|
-
def _access_valid(self):
|
39
|
+
def _access_valid(self) -> bool:
|
35
40
|
if not self.access_token:
|
36
41
|
return False
|
37
42
|
|
@@ -42,67 +47,131 @@ class UssoAPI(metaclass=Singleton):
|
|
42
47
|
return True
|
43
48
|
return False
|
44
49
|
|
45
|
-
def _request(
|
50
|
+
def _request(
|
51
|
+
self,
|
52
|
+
method="get",
|
53
|
+
endpoint: str = "",
|
54
|
+
data: dict = None,
|
55
|
+
**kwargs,
|
56
|
+
) -> dict:
|
46
57
|
url = f"{self.url}/{endpoint}"
|
47
|
-
headers = {}
|
58
|
+
headers = {"content-type": "application/json"}
|
48
59
|
if self.api_key:
|
49
60
|
headers["x-api-key"] = self.api_key
|
50
61
|
elif self.refresh_token:
|
51
62
|
if not self.access_token:
|
52
|
-
self.
|
63
|
+
self._refresh()
|
53
64
|
headers["Authorization"] = f"Bearer {self.access_token}"
|
54
65
|
|
55
|
-
resp = requests.request(
|
66
|
+
resp = requests.request(
|
67
|
+
method,
|
68
|
+
url,
|
69
|
+
headers=headers,
|
70
|
+
json=data,
|
71
|
+
)
|
72
|
+
if kwargs.get("raise", True):
|
73
|
+
resp.raise_for_status()
|
56
74
|
return resp.json()
|
57
75
|
|
58
|
-
def get_users(self):
|
59
|
-
|
76
|
+
def get_users(self, **kwargs) -> list[UserData]:
|
77
|
+
users_dict = self._request(endpoint="website/users", **kwargs)
|
60
78
|
|
61
|
-
|
62
|
-
|
79
|
+
return [
|
80
|
+
UserData(user_id=user.get("uid"), **user) for user in users_dict
|
81
|
+
]
|
63
82
|
|
64
|
-
def
|
65
|
-
return
|
83
|
+
def get_user(self, user_id: str, **kwargs) -> UserData:
|
84
|
+
return UserData(
|
85
|
+
**self._request(
|
86
|
+
endpoint=f"website/users/{user_id}",
|
87
|
+
**kwargs,
|
88
|
+
)
|
89
|
+
)
|
66
90
|
|
67
|
-
def
|
68
|
-
return
|
69
|
-
|
91
|
+
def get_user_credentials(self, user_id: str, **kwargs) -> UserData:
|
92
|
+
return UserData(
|
93
|
+
**self._request(
|
94
|
+
endpoint=f"website/users/{user_id}/credentials",
|
95
|
+
**kwargs,
|
96
|
+
)
|
70
97
|
)
|
71
98
|
|
72
|
-
def
|
73
|
-
return
|
74
|
-
|
99
|
+
def get_user_by_credentials(self, credentials: dict, **kwargs) -> UserData:
|
100
|
+
return UserData(
|
101
|
+
**self._request(
|
102
|
+
endpoint="website/users/credentials",
|
103
|
+
data=credentials,
|
104
|
+
**kwargs,
|
105
|
+
)
|
75
106
|
)
|
76
107
|
|
77
|
-
def
|
78
|
-
return
|
79
|
-
|
80
|
-
|
81
|
-
|
108
|
+
def create_user(self, user_data: dict, **kwargs) -> UserData:
|
109
|
+
return UserData(
|
110
|
+
**self._request(
|
111
|
+
method="post",
|
112
|
+
endpoint="website/users",
|
113
|
+
data=user_data,
|
114
|
+
**kwargs,
|
115
|
+
)
|
116
|
+
)
|
117
|
+
|
118
|
+
def create_user_credentials(
|
119
|
+
self, user_id: str, credentials: dict, **kwargs
|
120
|
+
) -> UserData:
|
121
|
+
return UserData(
|
122
|
+
**self._request(
|
123
|
+
method="post",
|
124
|
+
endpoint=f"website/users/{user_id}/credentials",
|
125
|
+
data=credentials,
|
126
|
+
**kwargs,
|
127
|
+
)
|
82
128
|
)
|
83
129
|
|
84
130
|
def create_user_by_credentials(
|
85
|
-
self,
|
86
|
-
|
131
|
+
self,
|
132
|
+
user_data: dict | None = None,
|
133
|
+
credentials: dict | None = None,
|
134
|
+
**kwargs,
|
135
|
+
) -> UserData:
|
136
|
+
|
87
137
|
if credentials:
|
88
138
|
user_data["authenticators"] = [credentials]
|
89
|
-
return
|
90
|
-
|
139
|
+
return UserData(
|
140
|
+
**self._request(
|
141
|
+
method="post",
|
142
|
+
endpoint="website/users",
|
143
|
+
data=user_data,
|
144
|
+
**kwargs,
|
145
|
+
)
|
91
146
|
)
|
92
147
|
|
93
|
-
def get_user_payload(self, user_id: str):
|
94
|
-
return self._request(
|
148
|
+
def get_user_payload(self, user_id: str, **kwargs) -> dict:
|
149
|
+
return self._request(
|
150
|
+
endpoint=f"website/users/{user_id}/payload", **kwargs
|
151
|
+
)
|
95
152
|
|
96
|
-
def update_user_payload(
|
153
|
+
def update_user_payload(
|
154
|
+
self,
|
155
|
+
user_id: str,
|
156
|
+
payload: dict,
|
157
|
+
**kwargs,
|
158
|
+
) -> dict:
|
97
159
|
return self._request(
|
98
160
|
method="patch",
|
99
|
-
endpoint=f"website/users/{user_id}/payload
|
161
|
+
endpoint=f"website/users/{user_id}/payload",
|
100
162
|
data=payload,
|
163
|
+
**kwargs,
|
101
164
|
)
|
102
165
|
|
103
|
-
def set_user_payload(
|
166
|
+
def set_user_payload(
|
167
|
+
self,
|
168
|
+
user_id: str,
|
169
|
+
payload: dict,
|
170
|
+
**kwargs,
|
171
|
+
) -> dict:
|
104
172
|
return self._request(
|
105
173
|
method="put",
|
106
|
-
endpoint=f"website/users/{user_id}/payload
|
174
|
+
endpoint=f"website/users/{user_id}/payload",
|
107
175
|
data=payload,
|
176
|
+
**kwargs,
|
108
177
|
)
|
usso/core.py
CHANGED
@@ -1,12 +1,12 @@
|
|
1
|
-
import os
|
2
1
|
import logging
|
2
|
+
import os
|
3
3
|
import uuid
|
4
4
|
from functools import lru_cache
|
5
5
|
from typing import Optional, Tuple
|
6
|
-
from singleton import Singleton
|
7
6
|
|
8
7
|
import jwt
|
9
8
|
from pydantic import BaseModel
|
9
|
+
from singleton import Singleton
|
10
10
|
|
11
11
|
from . import b64tools
|
12
12
|
from .exceptions import USSOException
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: usso
|
3
|
-
Version: 0.
|
3
|
+
Version: 0.20.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>
|
@@ -0,0 +1,14 @@
|
|
1
|
+
usso/__init__.py,sha256=RN0E6HI9kHedvDxheDPVWiAmh-169IrhXfvq_sHphQc,65
|
2
|
+
usso/api.py,sha256=Gl_Gxivt78EzvJp6VnRjT9AMREmA0C3xHoWSgCtb3fs,4824
|
3
|
+
usso/b64tools.py,sha256=6YCBx2lLaYFdk36f064VNZ1RejJTHtmgxqq0eT1sCwQ,518
|
4
|
+
usso/core.py,sha256=wGtzwzuZ-qq2lBbUUoRifmAb0LoFoNFrDgW-uS7r5RQ,3034
|
5
|
+
usso/exceptions.py,sha256=hawOAuVbvQtjgRfwp1KFZ4SmV7fh720y5Gom9JVA8W8,504
|
6
|
+
usso/package_data.dat,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
7
|
+
usso/fastapi/__init__.py,sha256=TRTDVJo8bwZQDAuCQFhh-g1XbIspf6TdFYXGAO5cgAU,130
|
8
|
+
usso/fastapi/integration.py,sha256=9Q10dfy8UagOkmG49-Ar0mj6PPsiKS8ioLFgBIREpWQ,1823
|
9
|
+
usso-0.20.0.dist-info/LICENSE.txt,sha256=ceC9ZJOV9H6CtQDcYmHOS46NA3dHJ_WD4J9blH513pc,1081
|
10
|
+
usso-0.20.0.dist-info/METADATA,sha256=RVG1LcaSbhNOLwSwrd6qpC64CS2we5nxbrqie0LjrDQ,4334
|
11
|
+
usso-0.20.0.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
|
12
|
+
usso-0.20.0.dist-info/entry_points.txt,sha256=4Zgpm5ELaAWPf0jPGJFz1_X69H7un8ycT3WdGoJ0Vvk,35
|
13
|
+
usso-0.20.0.dist-info/top_level.txt,sha256=g9Jf6h1Oyidh0vPiFni7UHInTJjSvu6cUalpLTIvthg,5
|
14
|
+
usso-0.20.0.dist-info/RECORD,,
|
usso-0.18.0.dist-info/RECORD
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
usso/__init__.py,sha256=r-fyIVLnUT6r5pNnQaRzHZYhQ2b6DoJD0D-ZgoO91ik,97
|
2
|
-
usso/api.py,sha256=Sxo1JJOzfjSuidmFWfdE4g2CrllLxxWjzrW9VXSpKP4,3329
|
3
|
-
usso/b64tools.py,sha256=6YCBx2lLaYFdk36f064VNZ1RejJTHtmgxqq0eT1sCwQ,518
|
4
|
-
usso/core.py,sha256=3K6LMsryvqf3b7NZwNUt7Hx31xJ9KX3g7Pa6HBjkY4o,3034
|
5
|
-
usso/exceptions.py,sha256=hawOAuVbvQtjgRfwp1KFZ4SmV7fh720y5Gom9JVA8W8,504
|
6
|
-
usso/package_data.dat,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
7
|
-
usso/fastapi/__init__.py,sha256=TRTDVJo8bwZQDAuCQFhh-g1XbIspf6TdFYXGAO5cgAU,130
|
8
|
-
usso/fastapi/integration.py,sha256=9Q10dfy8UagOkmG49-Ar0mj6PPsiKS8ioLFgBIREpWQ,1823
|
9
|
-
usso-0.18.0.dist-info/LICENSE.txt,sha256=ceC9ZJOV9H6CtQDcYmHOS46NA3dHJ_WD4J9blH513pc,1081
|
10
|
-
usso-0.18.0.dist-info/METADATA,sha256=XpDPq1YPrmX5aCClDCnUP3yS1m2MbQ5es3KC5M0935Q,4334
|
11
|
-
usso-0.18.0.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
|
12
|
-
usso-0.18.0.dist-info/entry_points.txt,sha256=4Zgpm5ELaAWPf0jPGJFz1_X69H7un8ycT3WdGoJ0Vvk,35
|
13
|
-
usso-0.18.0.dist-info/top_level.txt,sha256=g9Jf6h1Oyidh0vPiFni7UHInTJjSvu6cUalpLTIvthg,5
|
14
|
-
usso-0.18.0.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|