pypomes-jwt 1.2.5__tar.gz → 1.2.6__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.
Potentially problematic release.
This version of pypomes-jwt might be problematic. Click here for more details.
- {pypomes_jwt-1.2.5 → pypomes_jwt-1.2.6}/PKG-INFO +1 -1
- {pypomes_jwt-1.2.5 → pypomes_jwt-1.2.6}/pyproject.toml +1 -1
- {pypomes_jwt-1.2.5 → pypomes_jwt-1.2.6}/src/pypomes_jwt/__init__.py +6 -6
- pypomes_jwt-1.2.5/src/pypomes_jwt/jwt_external.py → pypomes_jwt-1.2.6/src/pypomes_jwt/jwt_providers.py +35 -28
- {pypomes_jwt-1.2.5 → pypomes_jwt-1.2.6}/.gitignore +0 -0
- {pypomes_jwt-1.2.5 → pypomes_jwt-1.2.6}/LICENSE +0 -0
- {pypomes_jwt-1.2.5 → pypomes_jwt-1.2.6}/README.md +0 -0
- {pypomes_jwt-1.2.5 → pypomes_jwt-1.2.6}/src/pypomes_jwt/jwt_config.py +0 -0
- {pypomes_jwt-1.2.5 → pypomes_jwt-1.2.6}/src/pypomes_jwt/jwt_pomes.py +0 -0
- {pypomes_jwt-1.2.5 → pypomes_jwt-1.2.6}/src/pypomes_jwt/jwt_registry.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: pypomes_jwt
|
|
3
|
-
Version: 1.2.
|
|
3
|
+
Version: 1.2.6
|
|
4
4
|
Summary: A collection of Python pomes, penyeach (JWT module)
|
|
5
5
|
Project-URL: Homepage, https://github.com/TheWiseCoder/PyPomes-JWT
|
|
6
6
|
Project-URL: Bug Tracker, https://github.com/TheWiseCoder/PyPomes-JWT/issues
|
|
@@ -1,26 +1,26 @@
|
|
|
1
1
|
from .jwt_config import (
|
|
2
2
|
JwtConfig, JwtDbConfig, JwtAlgorithm
|
|
3
3
|
)
|
|
4
|
-
from .jwt_external import (
|
|
5
|
-
provider_register, provider_get_token
|
|
6
|
-
)
|
|
7
4
|
from .jwt_pomes import (
|
|
8
5
|
jwt_needed, jwt_verify_request,
|
|
9
6
|
jwt_assert_account, jwt_set_account, jwt_remove_account,
|
|
10
7
|
jwt_issue_token, jwt_issue_tokens, jwt_refresh_tokens,
|
|
11
8
|
jwt_get_claims, jwt_validate_token, jwt_revoke_token
|
|
12
9
|
)
|
|
10
|
+
from .jwt_providers import (
|
|
11
|
+
provider_register, provider_get_token
|
|
12
|
+
)
|
|
13
13
|
|
|
14
14
|
__all__ = [
|
|
15
15
|
# jwt_constants
|
|
16
16
|
"JwtConfig", "JwtDbConfig", "JwtAlgorithm",
|
|
17
|
-
# jwt_external
|
|
18
|
-
"provider_register", "provider_get_token",
|
|
19
17
|
# jwt_pomes
|
|
20
18
|
"jwt_needed", "jwt_verify_request",
|
|
21
19
|
"jwt_assert_account", "jwt_set_account", "jwt_remove_account",
|
|
22
20
|
"jwt_issue_token", "jwt_issue_tokens", "jwt_refresh_tokens",
|
|
23
|
-
"jwt_get_claims", "jwt_validate_token", "jwt_revoke_token"
|
|
21
|
+
"jwt_get_claims", "jwt_validate_token", "jwt_revoke_token",
|
|
22
|
+
# jwt_providers
|
|
23
|
+
"provider_register", "provider_get_token"
|
|
24
24
|
]
|
|
25
25
|
|
|
26
26
|
from importlib.metadata import version
|
|
@@ -3,20 +3,20 @@ import sys
|
|
|
3
3
|
from base64 import b64encode
|
|
4
4
|
from datetime import datetime
|
|
5
5
|
from logging import Logger
|
|
6
|
-
from pypomes_core import TZ_LOCAL,
|
|
6
|
+
from pypomes_core import TZ_LOCAL, exc_format
|
|
7
7
|
from requests import Response
|
|
8
8
|
from typing import Any
|
|
9
9
|
|
|
10
10
|
# structure:
|
|
11
11
|
# {
|
|
12
12
|
# <provider-id>: {
|
|
13
|
-
# "url": <
|
|
14
|
-
# "
|
|
15
|
-
# "
|
|
16
|
-
# "
|
|
17
|
-
# "
|
|
18
|
-
# "
|
|
19
|
-
# "token": <
|
|
13
|
+
# "url": <strl>,
|
|
14
|
+
# "user": <str>,
|
|
15
|
+
# "pwd": <str>,
|
|
16
|
+
# "basic-auth": <bool>,
|
|
17
|
+
# "headers-data": <dict[str, str]>,
|
|
18
|
+
# "body-data": <dict[str, str],
|
|
19
|
+
# "token": <str>,
|
|
20
20
|
# "expiration": <timestamp>
|
|
21
21
|
# }
|
|
22
22
|
# }
|
|
@@ -25,30 +25,38 @@ _provider_registry: dict[str, dict[str, Any]] = {}
|
|
|
25
25
|
|
|
26
26
|
def provider_register(provider_id: str,
|
|
27
27
|
access_url: str,
|
|
28
|
-
grant_type: str,
|
|
29
28
|
auth_user: str,
|
|
30
29
|
auth_pwd: str,
|
|
31
|
-
|
|
32
|
-
|
|
30
|
+
custom_auth: tuple[str, str] = None,
|
|
31
|
+
headers_data: dict[str, str] = None,
|
|
32
|
+
body_data: dict[str, str] = None) -> None:
|
|
33
33
|
"""
|
|
34
34
|
Register an external authentication token provider.
|
|
35
35
|
|
|
36
|
+
If specified, *custom_auth* provides key names for sending credentials (username and password, in this order)
|
|
37
|
+
as key-value pairs in the body of the request. Otherwise, the external provider *provider_id* uses the standard
|
|
38
|
+
HTTP Basic Authorization scheme, wherein the credentials are B64-encoded and send in the request headers.
|
|
39
|
+
|
|
40
|
+
Optional constant key-value pairs (such as ['Content-Type', 'application/x-www-form-urlencoded']), to be
|
|
41
|
+
added to the request headers, may be specified in *header_data*. Likewise, optional constant key-value pairs
|
|
42
|
+
(such as ['grant-type', 'client_crdentials']), to be added to the request body, may be specified in *body_data*.
|
|
43
|
+
|
|
36
44
|
:param provider_id: the provider's identification
|
|
37
|
-
:param grant_type: the type of grant to request (typically, 'client_credentials' or 'password')
|
|
38
45
|
:param access_url: the url to request authentication tokens with
|
|
39
46
|
:param auth_user: the basic authorization user
|
|
40
47
|
:param auth_pwd: the basic authorization password
|
|
41
|
-
:param
|
|
42
|
-
:param
|
|
48
|
+
:param custom_auth: optional key names for sending the credentials as key-value pairs in the body of the request
|
|
49
|
+
:param headers_data: optional key-value pairs to be added to the request headers
|
|
50
|
+
:param body_data: optional key-value pairs to be added to the request body
|
|
43
51
|
"""
|
|
44
52
|
global _provider_registry # noqa: PLW0602
|
|
45
53
|
_provider_registry[provider_id] = {
|
|
46
54
|
"url": access_url,
|
|
47
|
-
"grant_type": grant_type,
|
|
48
55
|
"user": auth_user,
|
|
49
56
|
"pwd": auth_pwd,
|
|
50
|
-
"
|
|
51
|
-
"
|
|
57
|
+
"custom-auth": custom_auth,
|
|
58
|
+
"headers-data": headers_data,
|
|
59
|
+
"body-data": body_data,
|
|
52
60
|
"token": None,
|
|
53
61
|
"expiration": datetime.now(tz=TZ_LOCAL).timestamp()
|
|
54
62
|
}
|
|
@@ -75,16 +83,15 @@ def provider_get_token(errors: list[str] | None,
|
|
|
75
83
|
if now > provider.get("expiration"):
|
|
76
84
|
user: str = provider.get("user")
|
|
77
85
|
pwd: str = provider.get("pwd")
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
86
|
+
headers_data: dict[str, str] = provider.get("headers-data") or {}
|
|
87
|
+
body_data: dict[str, str] = provider.get("body-data") or {}
|
|
88
|
+
custom_auth: tuple[str, str] = provider.get("custom-auth")
|
|
89
|
+
if custom_auth:
|
|
90
|
+
body_data[custom_auth[0]] = user
|
|
91
|
+
body_data[custom_auth[1]] = pwd
|
|
83
92
|
else:
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
if provider.get("client-id"):
|
|
87
|
-
data["client-id"] = provider.get("client-id")
|
|
93
|
+
enc_bytes: bytes = b64encode(f"{user}:{pwd}".encode())
|
|
94
|
+
headers_data["Authorization"] = f"Basic {enc_bytes.decode()}"
|
|
88
95
|
url: str = provider.get("url")
|
|
89
96
|
try:
|
|
90
97
|
# typical return on a token request:
|
|
@@ -94,8 +101,8 @@ def provider_get_token(errors: list[str] | None,
|
|
|
94
101
|
# "access_token": <the-token>
|
|
95
102
|
# }
|
|
96
103
|
response: Response = requests.post(url=url,
|
|
97
|
-
data=
|
|
98
|
-
headers=
|
|
104
|
+
data=body_data,
|
|
105
|
+
headers=headers_data,
|
|
99
106
|
timeout=None)
|
|
100
107
|
if response.status_code < 200 or response.status_code >= 300:
|
|
101
108
|
# request resulted in error, report the problem
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|