nc-user-terminator 0.1.11__py3-none-any.whl → 0.1.13__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.
Potentially problematic release.
This version of nc-user-terminator might be problematic. Click here for more details.
- nc_user_manager/client.py +70 -8
- nc_user_manager/utils.py +10 -1
- {nc_user_terminator-0.1.11.dist-info → nc_user_terminator-0.1.13.dist-info}/METADATA +7 -1
- nc_user_terminator-0.1.13.dist-info/RECORD +10 -0
- nc_user_terminator-0.1.11.dist-info/RECORD +0 -10
- {nc_user_terminator-0.1.11.dist-info → nc_user_terminator-0.1.13.dist-info}/WHEEL +0 -0
- {nc_user_terminator-0.1.11.dist-info → nc_user_terminator-0.1.13.dist-info}/top_level.txt +0 -0
nc_user_manager/client.py
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import asyncio
|
|
2
2
|
from typing import Optional, Dict, Any
|
|
3
3
|
|
|
4
|
-
from .cache import MemoryCache, BaseCache, AsyncRedisCache
|
|
5
|
-
from .models import UserResponse, OAuth2AuthorizeResponse, CallbackResponse
|
|
6
|
-
from .exceptions import OAuthError
|
|
7
|
-
from .utils import request
|
|
4
|
+
from nc_user_manager.cache import MemoryCache, BaseCache, AsyncRedisCache
|
|
5
|
+
from nc_user_manager.models import UserResponse, OAuth2AuthorizeResponse, CallbackResponse
|
|
6
|
+
from nc_user_manager.exceptions import OAuthError
|
|
7
|
+
from nc_user_manager.utils import request
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
PRODUCT_HEADER = "X-Product-Code"
|
|
@@ -47,8 +47,11 @@ class OAuthClient:
|
|
|
47
47
|
def _headers(self, extra: Optional[Dict[str, str]] = None) -> Dict[str, str]:
|
|
48
48
|
headers = {
|
|
49
49
|
PRODUCT_HEADER: self._product_code,
|
|
50
|
-
"Host": "auth.nc.com"
|
|
51
50
|
}
|
|
51
|
+
if self._base_url == 'http://172.27.92.74':
|
|
52
|
+
headers.update({
|
|
53
|
+
"Host": "auth.nc.com"
|
|
54
|
+
})
|
|
52
55
|
if extra:
|
|
53
56
|
headers.update(extra)
|
|
54
57
|
return headers
|
|
@@ -279,6 +282,59 @@ class OAuthClient:
|
|
|
279
282
|
self._uncache_user(token, data)
|
|
280
283
|
return resp
|
|
281
284
|
|
|
285
|
+
# 密码学登录
|
|
286
|
+
def open_sesame(self, user_name:str, password: str) -> CallbackResponse:
|
|
287
|
+
params = {"single_session": str(self._single_session).lower()}
|
|
288
|
+
|
|
289
|
+
form = {
|
|
290
|
+
"username": user_name,
|
|
291
|
+
"password": password,
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
res_dict = request("POST", f"{self._base_url}/api/auth/login", headers=self._headers(), params=params, form_body=form)
|
|
295
|
+
|
|
296
|
+
return CallbackResponse(res_dict)
|
|
297
|
+
|
|
298
|
+
|
|
299
|
+
async def open_sesame_async(self, user_name:str, password: str) -> CallbackResponse:
|
|
300
|
+
params = {"single_session": str(self._single_session).lower()}
|
|
301
|
+
|
|
302
|
+
form = {
|
|
303
|
+
"username": user_name,
|
|
304
|
+
"password": password,
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
res_dict = await self._arequest(
|
|
308
|
+
"POST",
|
|
309
|
+
f"{self._base_url}/api/auth/login",
|
|
310
|
+
params=params,
|
|
311
|
+
form_body=form,
|
|
312
|
+
headers={
|
|
313
|
+
"Content-Type": "application/x-www-form-urlencoded",
|
|
314
|
+
**self._headers(),
|
|
315
|
+
}
|
|
316
|
+
)
|
|
317
|
+
return CallbackResponse(res_dict)
|
|
318
|
+
|
|
319
|
+
def forgot_password(self, token: str) -> str:
|
|
320
|
+
headers = self._headers({"Authorization": f"Bearer {token}"})
|
|
321
|
+
resp = request("POST", f"{self._base_url}/api/auth/forgot-password", headers=headers)
|
|
322
|
+
return resp.get("token")
|
|
323
|
+
|
|
324
|
+
def reset_password(self, password_token: str, password: str) -> None:
|
|
325
|
+
"""
|
|
326
|
+
修改密码
|
|
327
|
+
:param password_token: forgot_password获取的验证token
|
|
328
|
+
:param password: 新密码
|
|
329
|
+
:return:
|
|
330
|
+
"""
|
|
331
|
+
json_data = {
|
|
332
|
+
"token": password_token,
|
|
333
|
+
"password": password
|
|
334
|
+
}
|
|
335
|
+
request("POST", f"{self._base_url}/api/auth/forgot-password", headers=self._headers(), json_body=json_data)
|
|
336
|
+
|
|
337
|
+
|
|
282
338
|
async def main():
|
|
283
339
|
def get_redis_url() -> str:
|
|
284
340
|
return f'redis://default:1q2w3e@localhost:6379/1'
|
|
@@ -289,11 +345,17 @@ async def main():
|
|
|
289
345
|
_redis = redis.from_url(get_redis_url(), decode_responses=True)
|
|
290
346
|
|
|
291
347
|
redis_cache = AsyncRedisCache(_redis)
|
|
348
|
+
import socket
|
|
349
|
+
print(socket.gethostbyname("dev.ncuser.com"))
|
|
292
350
|
|
|
293
|
-
client = OAuthClient("http://
|
|
294
|
-
authorize = client.
|
|
295
|
-
|
|
351
|
+
client = OAuthClient("kode", "http://dev.ncuser.com", "http://localhost:8000/auth/google/custom_callback", single_session=True, cache=redis_cache)
|
|
352
|
+
authorize = await client.say_my_name_async("QtbMAqXNwrsy-7dr-D_lIVvUu88gjhPM0fBXeJTaOiA")
|
|
353
|
+
|
|
354
|
+
# res = client.forgot_password("QtbMAqXNwrsy-7dr-D_lIVvUu88gjhPM0fBXeJTaOiA")
|
|
296
355
|
|
|
356
|
+
token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiI1IiwicGFzc3dvcmRfZmdwdCI6IiRhcmdvbjJpZCR2PTE5JG09NjU1MzYsdD0zLHA9NCRYUlQ1K1p3Uk5sbjhKQzQrZW94TFlnJERadnFKb29xUDNMUGVJbEV6OVR5TjZIdm1LYW9yYnpvdGxGRlB5SlBKZE0iLCJhdWQiOiJmYXN0YXBpLXVzZXJzOnJlc2V0IiwiZXhwIjoxNzYxNTU4MTUxfQ.rSr8tRql4ZsE2k-WGHzhq9aT387E9jXGJ_bNomC4LKA"
|
|
357
|
+
print(client.reset_password(token, "965965965"))
|
|
358
|
+
print(authorize)
|
|
297
359
|
|
|
298
360
|
|
|
299
361
|
|
nc_user_manager/utils.py
CHANGED
|
@@ -10,7 +10,8 @@ def request(
|
|
|
10
10
|
url: str,
|
|
11
11
|
params: Optional[Dict[str, Any]] = None,
|
|
12
12
|
headers: Optional[Dict[str, str]] = None,
|
|
13
|
-
json_body: Optional[dict] = None
|
|
13
|
+
json_body: Optional[dict] = None,
|
|
14
|
+
form_body: Optional[dict] = None,
|
|
14
15
|
) -> dict:
|
|
15
16
|
"""
|
|
16
17
|
发送 HTTP 请求并返回统一结果,不抛异常
|
|
@@ -28,12 +29,20 @@ def request(
|
|
|
28
29
|
url = f"{url}?{query}"
|
|
29
30
|
|
|
30
31
|
data = None
|
|
32
|
+
|
|
33
|
+
# JSON 请求
|
|
31
34
|
if json_body is not None:
|
|
32
35
|
data = json.dumps(json_body).encode("utf-8")
|
|
33
36
|
if headers is None:
|
|
34
37
|
headers = {}
|
|
35
38
|
headers["Content-Type"] = "application/json"
|
|
36
39
|
|
|
40
|
+
# Form 表单请求
|
|
41
|
+
if form_body is not None:
|
|
42
|
+
data = urllib.parse.urlencode(form_body).encode("utf-8")
|
|
43
|
+
headers = headers or {}
|
|
44
|
+
headers["Content-Type"] = "application/x-www-form-urlencoded"
|
|
45
|
+
|
|
37
46
|
req = urllib.request.Request(url, method=method.upper(), data=data)
|
|
38
47
|
if headers:
|
|
39
48
|
for k, v in headers.items():
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: nc-user-terminator
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.13
|
|
4
4
|
Summary: OAuth client wrapper for multi-tenant projects
|
|
5
5
|
Author: bw_song
|
|
6
6
|
Author-email: m132777096902@gmail.com
|
|
@@ -25,3 +25,9 @@ Dynamic: requires-python
|
|
|
25
25
|
- 获取用户信息,本地缓存配置
|
|
26
26
|
+ v0.1.11
|
|
27
27
|
- 用户头像字段调整
|
|
28
|
+
+ v0.1.12
|
|
29
|
+
- 新增密码学登录
|
|
30
|
+
- 新增修改密码
|
|
31
|
+
- 支持重置社媒账号密码
|
|
32
|
+
+ v0.1.13
|
|
33
|
+
- 包路径调整
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
nc_user_manager/__init__.py,sha256=fF3FZD0XUW5YCfTbBeJs3RK-Mnm3IQ7lns6Eb_tMqPU,238
|
|
2
|
+
nc_user_manager/cache.py,sha256=u9ioXDwHmEJHRB4VKI4JU_pp-8Y5O4bLPm8-pwqiMVc,2273
|
|
3
|
+
nc_user_manager/client.py,sha256=3Ua1pGUa4pU0JiBmU-SK5G3yCP9i7lD1XbddKdwphm0,13893
|
|
4
|
+
nc_user_manager/exceptions.py,sha256=yUMDrh1HHZF36UUadQNHvJlDgEYSYoYOObs8Q11fjrE,351
|
|
5
|
+
nc_user_manager/models.py,sha256=r3OmicvfeDtDyvFlfxhn-g0svAvyeXIwa1BEuCMx4Ns,1074
|
|
6
|
+
nc_user_manager/utils.py,sha256=zn0ds3UftTaEnrTVDn0YL9N-EkVWpbJtowFzAotU80E,2608
|
|
7
|
+
nc_user_terminator-0.1.13.dist-info/METADATA,sha256=Tdatp5ycYaPfATDaDUz9_hHQSmjO4N6lAXWIOVEKcgY,732
|
|
8
|
+
nc_user_terminator-0.1.13.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
9
|
+
nc_user_terminator-0.1.13.dist-info/top_level.txt,sha256=kOAUtl6RYo-x3vMJL8It3KCJLoIFPvMUiAAyXjPQTYA,16
|
|
10
|
+
nc_user_terminator-0.1.13.dist-info/RECORD,,
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
nc_user_manager/__init__.py,sha256=fF3FZD0XUW5YCfTbBeJs3RK-Mnm3IQ7lns6Eb_tMqPU,238
|
|
2
|
-
nc_user_manager/cache.py,sha256=u9ioXDwHmEJHRB4VKI4JU_pp-8Y5O4bLPm8-pwqiMVc,2273
|
|
3
|
-
nc_user_manager/client.py,sha256=TrRM3GPg6FCRDUlC2W4rvyzWzNeXRmtp4zUWhz8ouWk,11330
|
|
4
|
-
nc_user_manager/exceptions.py,sha256=yUMDrh1HHZF36UUadQNHvJlDgEYSYoYOObs8Q11fjrE,351
|
|
5
|
-
nc_user_manager/models.py,sha256=r3OmicvfeDtDyvFlfxhn-g0svAvyeXIwa1BEuCMx4Ns,1074
|
|
6
|
-
nc_user_manager/utils.py,sha256=gxFSaUq0oiymIlvHITu2L7EkU2ZYQmW2q_okmUxGBeU,2319
|
|
7
|
-
nc_user_terminator-0.1.11.dist-info/METADATA,sha256=Z5NfbEqefb5bA-Viz_Fpb_3VCPzHhUNC6QrpmsgiEK0,602
|
|
8
|
-
nc_user_terminator-0.1.11.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
9
|
-
nc_user_terminator-0.1.11.dist-info/top_level.txt,sha256=kOAUtl6RYo-x3vMJL8It3KCJLoIFPvMUiAAyXjPQTYA,16
|
|
10
|
-
nc_user_terminator-0.1.11.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|