jamlib 2.6.0b0.dev5__tar.gz → 3.0.0a4__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.
Files changed (105) hide show
  1. {jamlib-2.6.0b0.dev5 → jamlib-3.0.0a4}/PKG-INFO +3 -4
  2. {jamlib-2.6.0b0.dev5 → jamlib-3.0.0a4}/README.md +2 -3
  3. {jamlib-2.6.0b0.dev5 → jamlib-3.0.0a4}/pyproject.toml +16 -21
  4. {jamlib-2.6.0b0.dev5 → jamlib-3.0.0a4}/src/jam/__abc_instances__.py +0 -74
  5. {jamlib-2.6.0b0.dev5 → jamlib-3.0.0a4}/src/jam/__init__.py +1 -1
  6. {jamlib-2.6.0b0.dev5 → jamlib-3.0.0a4}/src/jam/aio/instance.py +27 -268
  7. {jamlib-2.6.0b0.dev5 → jamlib-3.0.0a4}/src/jam/aio/modules.py +1 -161
  8. {jamlib-2.6.0b0.dev5 → jamlib-3.0.0a4}/src/jam/instance.py +26 -279
  9. jamlib-3.0.0a4/src/jam/jwt/__algorithms__.py +466 -0
  10. jamlib-3.0.0a4/src/jam/jwt/__base__.py +38 -0
  11. jamlib-3.0.0a4/src/jam/jwt/__init__.py +7 -0
  12. jamlib-3.0.0a4/src/jam/jwt/__types__.py +15 -0
  13. jamlib-3.0.0a4/src/jam/jwt/module.py +224 -0
  14. jamlib-2.6.0b0.dev5/src/jam/jwt/__utils__.py → jamlib-3.0.0a4/src/jam/jwt/utils.py +2 -2
  15. jamlib-3.0.0a4/src/jam/logger.py +73 -0
  16. {jamlib-2.6.0b0.dev5 → jamlib-3.0.0a4}/src/jam/modules.py +1 -173
  17. {jamlib-2.6.0b0.dev5 → jamlib-3.0.0a4}/src/jam/tests/clients.py +9 -9
  18. {jamlib-2.6.0b0.dev5 → jamlib-3.0.0a4}/src/jam/tests/fakers.py +3 -15
  19. {jamlib-2.6.0b0.dev5 → jamlib-3.0.0a4}/src/jam/utils/__init__.py +3 -0
  20. jamlib-3.0.0a4/src/jam/utils/basic_auth.py +47 -0
  21. {jamlib-2.6.0b0.dev5 → jamlib-3.0.0a4}/src/jam/utils/config_maker.py +47 -12
  22. {jamlib-2.6.0b0.dev5 → jamlib-3.0.0a4}/src/jamlib.egg-info/PKG-INFO +3 -4
  23. {jamlib-2.6.0b0.dev5 → jamlib-3.0.0a4}/src/jamlib.egg-info/SOURCES.txt +7 -5
  24. jamlib-2.6.0b0.dev5/src/jam/jwt/__init__.py +0 -1
  25. jamlib-2.6.0b0.dev5/src/jam/jwt/tools.py +0 -168
  26. jamlib-2.6.0b0.dev5/src/jam/jwt/types.py +0 -34
  27. jamlib-2.6.0b0.dev5/src/jam/quick/__init__.py +0 -26
  28. jamlib-2.6.0b0.dev5/src/jam/quick/jwt.py +0 -245
  29. {jamlib-2.6.0b0.dev5 → jamlib-3.0.0a4}/LICENSE.md +0 -0
  30. {jamlib-2.6.0b0.dev5 → jamlib-3.0.0a4}/setup.cfg +0 -0
  31. {jamlib-2.6.0b0.dev5 → jamlib-3.0.0a4}/src/jam/__abc_encoder__.py +0 -0
  32. {jamlib-2.6.0b0.dev5 → jamlib-3.0.0a4}/src/jam/__deprecated__.py +0 -0
  33. {jamlib-2.6.0b0.dev5 → jamlib-3.0.0a4}/src/jam/__logger__.py +0 -0
  34. {jamlib-2.6.0b0.dev5 → jamlib-3.0.0a4}/src/jam/aio/__init__.py +0 -0
  35. {jamlib-2.6.0b0.dev5 → jamlib-3.0.0a4}/src/jam/aio/jwt/__init__.py +0 -0
  36. {jamlib-2.6.0b0.dev5 → jamlib-3.0.0a4}/src/jam/aio/jwt/lists/__init__.py +0 -0
  37. {jamlib-2.6.0b0.dev5 → jamlib-3.0.0a4}/src/jam/aio/jwt/lists/json.py +0 -0
  38. {jamlib-2.6.0b0.dev5 → jamlib-3.0.0a4}/src/jam/aio/jwt/lists/redis.py +0 -0
  39. {jamlib-2.6.0b0.dev5 → jamlib-3.0.0a4}/src/jam/aio/jwt/tools.py +0 -0
  40. {jamlib-2.6.0b0.dev5 → jamlib-3.0.0a4}/src/jam/aio/oauth2/__init__.py +0 -0
  41. {jamlib-2.6.0b0.dev5 → jamlib-3.0.0a4}/src/jam/aio/oauth2/builtin/__init__.py +0 -0
  42. {jamlib-2.6.0b0.dev5 → jamlib-3.0.0a4}/src/jam/aio/oauth2/builtin/github.py +0 -0
  43. {jamlib-2.6.0b0.dev5 → jamlib-3.0.0a4}/src/jam/aio/oauth2/builtin/gitlab.py +0 -0
  44. {jamlib-2.6.0b0.dev5 → jamlib-3.0.0a4}/src/jam/aio/oauth2/builtin/google.py +0 -0
  45. {jamlib-2.6.0b0.dev5 → jamlib-3.0.0a4}/src/jam/aio/oauth2/builtin/yandex.py +0 -0
  46. {jamlib-2.6.0b0.dev5 → jamlib-3.0.0a4}/src/jam/aio/oauth2/client.py +0 -0
  47. {jamlib-2.6.0b0.dev5 → jamlib-3.0.0a4}/src/jam/aio/sessions/__init__.py +0 -0
  48. {jamlib-2.6.0b0.dev5 → jamlib-3.0.0a4}/src/jam/aio/sessions/json.py +0 -0
  49. {jamlib-2.6.0b0.dev5 → jamlib-3.0.0a4}/src/jam/aio/sessions/redis.py +0 -0
  50. {jamlib-2.6.0b0.dev5 → jamlib-3.0.0a4}/src/jam/encoders.py +0 -0
  51. {jamlib-2.6.0b0.dev5 → jamlib-3.0.0a4}/src/jam/exceptions/__init__.py +0 -0
  52. {jamlib-2.6.0b0.dev5 → jamlib-3.0.0a4}/src/jam/exceptions/jwt.py +0 -0
  53. {jamlib-2.6.0b0.dev5 → jamlib-3.0.0a4}/src/jam/exceptions/oauth2.py +0 -0
  54. {jamlib-2.6.0b0.dev5 → jamlib-3.0.0a4}/src/jam/exceptions/sessions.py +0 -0
  55. {jamlib-2.6.0b0.dev5 → jamlib-3.0.0a4}/src/jam/ext/__init__.py +0 -0
  56. {jamlib-2.6.0b0.dev5 → jamlib-3.0.0a4}/src/jam/ext/fastapi/__init__.py +0 -0
  57. {jamlib-2.6.0b0.dev5 → jamlib-3.0.0a4}/src/jam/ext/flask/__init__.py +0 -0
  58. {jamlib-2.6.0b0.dev5 → jamlib-3.0.0a4}/src/jam/ext/flask/extensions.py +0 -0
  59. {jamlib-2.6.0b0.dev5 → jamlib-3.0.0a4}/src/jam/ext/litestar/__init__.py +0 -0
  60. {jamlib-2.6.0b0.dev5 → jamlib-3.0.0a4}/src/jam/ext/litestar/middlewares.py +0 -0
  61. {jamlib-2.6.0b0.dev5 → jamlib-3.0.0a4}/src/jam/ext/litestar/plugins.py +0 -0
  62. {jamlib-2.6.0b0.dev5 → jamlib-3.0.0a4}/src/jam/ext/litestar/value.py +0 -0
  63. {jamlib-2.6.0b0.dev5 → jamlib-3.0.0a4}/src/jam/ext/starlette/__init__.py +0 -0
  64. {jamlib-2.6.0b0.dev5 → jamlib-3.0.0a4}/src/jam/ext/starlette/auth_backends.py +0 -0
  65. {jamlib-2.6.0b0.dev5 → jamlib-3.0.0a4}/src/jam/ext/starlette/value.py +0 -0
  66. {jamlib-2.6.0b0.dev5 → jamlib-3.0.0a4}/src/jam/jwt/lists/__abc_list_repo__.py +0 -0
  67. {jamlib-2.6.0b0.dev5 → jamlib-3.0.0a4}/src/jam/jwt/lists/__init__.py +0 -0
  68. {jamlib-2.6.0b0.dev5 → jamlib-3.0.0a4}/src/jam/jwt/lists/json.py +0 -0
  69. {jamlib-2.6.0b0.dev5 → jamlib-3.0.0a4}/src/jam/jwt/lists/redis.py +0 -0
  70. {jamlib-2.6.0b0.dev5 → jamlib-3.0.0a4}/src/jam/oauth2/__abc_oauth2_repo__.py +0 -0
  71. {jamlib-2.6.0b0.dev5 → jamlib-3.0.0a4}/src/jam/oauth2/__init__.py +0 -0
  72. {jamlib-2.6.0b0.dev5 → jamlib-3.0.0a4}/src/jam/oauth2/builtin/__init__.py +0 -0
  73. {jamlib-2.6.0b0.dev5 → jamlib-3.0.0a4}/src/jam/oauth2/builtin/github.py +0 -0
  74. {jamlib-2.6.0b0.dev5 → jamlib-3.0.0a4}/src/jam/oauth2/builtin/gitlab.py +0 -0
  75. {jamlib-2.6.0b0.dev5 → jamlib-3.0.0a4}/src/jam/oauth2/builtin/google.py +0 -0
  76. {jamlib-2.6.0b0.dev5 → jamlib-3.0.0a4}/src/jam/oauth2/builtin/yandex.py +0 -0
  77. {jamlib-2.6.0b0.dev5 → jamlib-3.0.0a4}/src/jam/oauth2/client.py +0 -0
  78. {jamlib-2.6.0b0.dev5 → jamlib-3.0.0a4}/src/jam/otp/__abc_module__.py +0 -0
  79. {jamlib-2.6.0b0.dev5 → jamlib-3.0.0a4}/src/jam/otp/__init__.py +0 -0
  80. {jamlib-2.6.0b0.dev5 → jamlib-3.0.0a4}/src/jam/otp/hotp.py +0 -0
  81. {jamlib-2.6.0b0.dev5 → jamlib-3.0.0a4}/src/jam/otp/totp.py +0 -0
  82. {jamlib-2.6.0b0.dev5 → jamlib-3.0.0a4}/src/jam/paseto/__abc_paseto_repo__.py +0 -0
  83. {jamlib-2.6.0b0.dev5 → jamlib-3.0.0a4}/src/jam/paseto/__init__.py +0 -0
  84. {jamlib-2.6.0b0.dev5 → jamlib-3.0.0a4}/src/jam/paseto/utils.py +0 -0
  85. {jamlib-2.6.0b0.dev5 → jamlib-3.0.0a4}/src/jam/paseto/v1.py +0 -0
  86. {jamlib-2.6.0b0.dev5 → jamlib-3.0.0a4}/src/jam/paseto/v2.py +0 -0
  87. {jamlib-2.6.0b0.dev5 → jamlib-3.0.0a4}/src/jam/paseto/v3.py +0 -0
  88. {jamlib-2.6.0b0.dev5 → jamlib-3.0.0a4}/src/jam/paseto/v4.py +0 -0
  89. {jamlib-2.6.0b0.dev5 → jamlib-3.0.0a4}/src/jam/sessions/__abc_session_repo__.py +0 -0
  90. {jamlib-2.6.0b0.dev5 → jamlib-3.0.0a4}/src/jam/sessions/__init__.py +0 -0
  91. {jamlib-2.6.0b0.dev5 → jamlib-3.0.0a4}/src/jam/sessions/json.py +0 -0
  92. {jamlib-2.6.0b0.dev5 → jamlib-3.0.0a4}/src/jam/sessions/redis.py +0 -0
  93. {jamlib-2.6.0b0.dev5 → jamlib-3.0.0a4}/src/jam/tests/__init__.py +0 -0
  94. {jamlib-2.6.0b0.dev5 → jamlib-3.0.0a4}/src/jam/utils/aes.py +0 -0
  95. {jamlib-2.6.0b0.dev5 → jamlib-3.0.0a4}/src/jam/utils/await_maybe.py +0 -0
  96. {jamlib-2.6.0b0.dev5 → jamlib-3.0.0a4}/src/jam/utils/ed.py +0 -0
  97. {jamlib-2.6.0b0.dev5 → jamlib-3.0.0a4}/src/jam/utils/otp_keys.py +0 -0
  98. {jamlib-2.6.0b0.dev5 → jamlib-3.0.0a4}/src/jam/utils/rsa.py +0 -0
  99. {jamlib-2.6.0b0.dev5 → jamlib-3.0.0a4}/src/jam/utils/salt_hash.py +0 -0
  100. {jamlib-2.6.0b0.dev5 → jamlib-3.0.0a4}/src/jam/utils/symmetric.py +0 -0
  101. {jamlib-2.6.0b0.dev5 → jamlib-3.0.0a4}/src/jam/utils/xchacha20poly1305.py +0 -0
  102. {jamlib-2.6.0b0.dev5 → jamlib-3.0.0a4}/src/jam/utils/xor.py +0 -0
  103. {jamlib-2.6.0b0.dev5 → jamlib-3.0.0a4}/src/jamlib.egg-info/dependency_links.txt +0 -0
  104. {jamlib-2.6.0b0.dev5 → jamlib-3.0.0a4}/src/jamlib.egg-info/requires.txt +0 -0
  105. {jamlib-2.6.0b0.dev5 → jamlib-3.0.0a4}/src/jamlib.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: jamlib
3
- Version: 2.6.0b0.dev5
3
+ Version: 3.0.0a4
4
4
  Summary: Simple and universal library for authorization.
5
5
  Author-email: Makridenko Adrian <adrianmakridenko@duck.com>, Ksenia Travnikova <kseniatravnikova@duck.com>
6
6
  License: MIT License
@@ -55,7 +55,7 @@ Dynamic: license-file
55
55
 
56
56
  ![logo](https://github.com/lyaguxafrog/jam/blob/master/docs/assets/h_logo_n_title.png?raw=true)
57
57
 
58
- ![Static Badge](https://img.shields.io/badge/Python-3.9%2B-blue?logo=python&logoColor=white)
58
+ ![Python Version](https://img.shields.io/badge/Python-3.9.*%20--%203.14.*-blue?logo=python&logoColor=white)
59
59
  [![PyPI - Version](https://img.shields.io/pypi/v/jamlib)](https://pypi.org/project/jamlib/)
60
60
  [![PyPI Downloads](https://static.pepy.tech/personalized-badge/jamlib?period=total&units=INTERNATIONAL_SYSTEM&left_color=GRAY&right_color=RED&left_text=Downloads)](https://pypi.org/project/jamlib/)
61
61
  ![tests](https://github.com/lyaguxafrog/jam/actions/workflows/run-tests.yml/badge.svg)
@@ -76,7 +76,7 @@ from jam import Jam
76
76
  jam = Jam()
77
77
 
78
78
  jwt = jam.jwt_create_token({"user": 1})
79
- decoded_payload = jam.jwt_verify_token(jwt)
79
+ session_id = jam.session_create(session_key="username", data={"user": 1})
80
80
  ```
81
81
 
82
82
  ## Why Jam?
@@ -115,4 +115,3 @@ Here is a comparison with other libraries:
115
115
  | PASETO | ✅ | ❌ | ❌ | ❌ | ❌ |
116
116
  | Flexible config | ✅ | ❌ | ❌ | ❌ | ❌ |
117
117
  | Modularity | ✅ | ❌ | ❌ | ❌ | ❌ |
118
-
@@ -2,7 +2,7 @@
2
2
 
3
3
  ![logo](https://github.com/lyaguxafrog/jam/blob/master/docs/assets/h_logo_n_title.png?raw=true)
4
4
 
5
- ![Static Badge](https://img.shields.io/badge/Python-3.9%2B-blue?logo=python&logoColor=white)
5
+ ![Python Version](https://img.shields.io/badge/Python-3.9.*%20--%203.14.*-blue?logo=python&logoColor=white)
6
6
  [![PyPI - Version](https://img.shields.io/pypi/v/jamlib)](https://pypi.org/project/jamlib/)
7
7
  [![PyPI Downloads](https://static.pepy.tech/personalized-badge/jamlib?period=total&units=INTERNATIONAL_SYSTEM&left_color=GRAY&right_color=RED&left_text=Downloads)](https://pypi.org/project/jamlib/)
8
8
  ![tests](https://github.com/lyaguxafrog/jam/actions/workflows/run-tests.yml/badge.svg)
@@ -23,7 +23,7 @@ from jam import Jam
23
23
  jam = Jam()
24
24
 
25
25
  jwt = jam.jwt_create_token({"user": 1})
26
- decoded_payload = jam.jwt_verify_token(jwt)
26
+ session_id = jam.session_create(session_key="username", data={"user": 1})
27
27
  ```
28
28
 
29
29
  ## Why Jam?
@@ -62,4 +62,3 @@ Here is a comparison with other libraries:
62
62
  | PASETO | ✅ | ❌ | ❌ | ❌ | ❌ |
63
63
  | Flexible config | ✅ | ❌ | ❌ | ❌ | ❌ |
64
64
  | Modularity | ✅ | ❌ | ❌ | ❌ | ❌ |
65
-
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "jamlib"
3
- version = "2.6.0b0.dev5"
3
+ version = "3.0.0a4"
4
4
  description = "Simple and universal library for authorization."
5
5
  authors = [
6
6
  {name = "Makridenko Adrian",email = "adrianmakridenko@duck.com"},
@@ -101,33 +101,28 @@ tests = [
101
101
  [tool.ruff]
102
102
  target-version = "py39"
103
103
  line-length = 80
104
- ignore = ["UP009", "D100"]
105
- exclude = ["*__init__.py", "tests/", "*exceptions/"]
104
+ ignore = ["UP009", "D100", "UP007"]
105
+ exclude = ["*__init__.py", "tests/", "*exceptions/", "env", ".env", ".env.example", "migrations/", ".venv/"]
106
106
 
107
107
  [tool.ruff.lint]
108
- extend-select = ["UP", "D"]
108
+ extend-select = ["UP", "D", "I"]
109
109
 
110
110
  [tool.ruff.lint.pydocstyle]
111
111
  convention = "google"
112
112
 
113
- [tool.isort]
114
- profile = "black"
115
- default_section = "THIRDPARTY"
116
- balanced_wrapping = true
117
- known_first_party = "src"
118
- line_length = 80
119
- lines_after_imports = 2
120
- lines_between_sections = 1
121
- multi_line_output = 3
122
- sections = ["FUTURE", "STDLIB", "THIRDPARTY", "FIRSTPARTY", "LOCALFOLDER"]
123
- skip = ["env", ".env", ".env.example", "migrations/", ".venv/"]
124
-
125
- [tool.black]
126
- line-length = 80
127
- skip-string-normalization = false
113
+ [tool.ruff.lint.isort]
114
+ known-first-party = ["jam"]
115
+ split-on-trailing-comma = true
116
+ force-wrap-aliases = true
117
+ force-sort-within-sections = true
118
+ lines-after-imports = 2
119
+ lines-between-types = 1
120
+
121
+ [tool.ruff.format]
122
+ quote-style = "double"
123
+ skip-magic-trailing-comma = false
124
+ line-ending = "auto"
128
125
 
129
- [tool.mypy]
130
- disable_error_code = ["no-redef", "import-not-found", "import-untyped", "attr-defined"]
131
126
 
132
127
  [tool.pytest]
133
128
  python_files = ["test*.py"]
@@ -216,80 +216,6 @@ class BaseJam(ABC):
216
216
  """
217
217
  raise NotImplementedError
218
218
 
219
- @abstractmethod
220
- def gen_jwt_token(self, payload) -> str:
221
- """Generate new JWT token."""
222
- raise NotImplementedError
223
-
224
- @abstractmethod
225
- def verify_jwt_token(
226
- self, token: str, check_exp: bool, check_list: bool
227
- ) -> dict[str, Any]:
228
- """Verify JWT token."""
229
- raise NotImplementedError
230
-
231
- @abstractmethod
232
- def make_payload(self, **payload) -> dict[str, Any]:
233
- """Generate new template."""
234
- raise NotImplementedError
235
-
236
- @abstractmethod
237
- def create_session(self, session_key: str, data: dict) -> str:
238
- """Create new session."""
239
- raise NotImplementedError
240
-
241
- @abstractmethod
242
- def get_session(self, session_id: str) -> Optional[dict]:
243
- """Retrieve session data by session ID."""
244
- raise NotImplementedError
245
-
246
- @abstractmethod
247
- def delete_session(self, session_id: str) -> None:
248
- """Delete a session by its ID."""
249
- raise NotImplementedError
250
-
251
- @abstractmethod
252
- def update_session(self, session_id: str, data: dict) -> None:
253
- """Update session data by session ID."""
254
- raise NotImplementedError
255
-
256
- @abstractmethod
257
- def clear_sessions(self, session_key: str) -> None:
258
- """Clear all sessions associated with a specific session key."""
259
- raise NotImplementedError
260
-
261
- @abstractmethod
262
- def rework_session(self, old_session_key: str) -> str:
263
- """Rework an existing session key to a new one."""
264
- raise NotImplementedError
265
-
266
- @abstractmethod
267
- def get_otp_uri(
268
- self,
269
- secret: str,
270
- name: Optional[str] = None,
271
- issuer: Optional[str] = None,
272
- counter: Optional[int] = None,
273
- ) -> str:
274
- """Generates an otpauth:// URI for Google Authenticator."""
275
- raise NotImplementedError
276
-
277
- @abstractmethod
278
- def get_otp_code(self, secret: str, factor: Optional[int] = None) -> str:
279
- """Generates a OTP code."""
280
- raise NotImplementedError
281
-
282
- @abstractmethod
283
- def verify_otp_code(
284
- self,
285
- secret: str,
286
- code: str,
287
- factor: Optional[int] = None,
288
- look_ahead: Optional[int] = None,
289
- ) -> bool:
290
- """Verify TOTP code."""
291
- raise NotImplementedError
292
-
293
219
  @abstractmethod
294
220
  def oauth2_get_authorized_url(
295
221
  self, provider: str, scope: list[str], **extra_params: Any
@@ -13,5 +13,5 @@ from jam.encoders import JsonEncoder
13
13
  from jam.instance import Jam
14
14
 
15
15
 
16
- __version__ = "2.6.0b0.dev5"
16
+ __version__ = "3.0.0a4"
17
17
  __all__ = ["Jam", "JsonEncoder", "BaseJam", "BaseEncoder"]
@@ -1,22 +1,24 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
- import gc
4
3
  from collections.abc import Callable
4
+ from datetime import datetime
5
+ import gc
5
6
  from typing import Any, Optional, Union
7
+ import uuid
6
8
 
7
9
  from jam.__abc_instances__ import BaseJam
8
- from jam.__deprecated__ import deprecated
9
10
  from jam.__logger__ import logger
10
- from jam.aio.modules import JWTModule, OAuth2Module, SessionModule
11
+ from jam.aio.modules import OAuth2Module, SessionModule
12
+ from jam.jwt import JWT
11
13
  from jam.paseto import BasePASETO
12
- from jam.utils.config_maker import __config_maker__, __module_loader__
14
+ from jam.utils.config_maker import __config_maker__
13
15
 
14
16
 
15
17
  class Jam(BaseJam):
16
18
  """Main instance for aio."""
17
19
 
18
20
  _JAM_MODULES: dict[str, str] = {
19
- "jwt": "jam.aio.modules.JWTModule",
21
+ "jwt": "jam.jwt.module.JWT",
20
22
  "session": "jam.aio.modules.SessionModule",
21
23
  "oauth2": "jam.aio.modules.OAuth2Module",
22
24
  "paseto": "jam.paseto.utils.init_paseto_instance",
@@ -33,7 +35,7 @@ class Jam(BaseJam):
33
35
  config (dict[str, Any] | str): dict or path to config file
34
36
  pointer (str): Config read point
35
37
  """
36
- self.jwt: Optional[JWTModule] = None
38
+ self.jwt: Optional[JWT] = None
37
39
  self.session: Optional[SessionModule] = None
38
40
  self.oauth2: Optional[OAuth2Module] = None
39
41
  self.paseto: Optional[BasePASETO] = None
@@ -49,30 +51,18 @@ class Jam(BaseJam):
49
51
  self._otp_module = self._otp_module_setup()
50
52
  logger.debug("OTP module initialized")
51
53
 
52
- # Other modules
53
- if config.get("auth_type", None):
54
- logger.warning(
55
- "This configuration type is deprecated, see: https://jam.makridenko.ru/config"
56
- )
57
- name = config.pop("auth_type")
58
- module = __module_loader__(self._JAM_MODULES[name])
59
- self.module = module
60
- setattr(self, name, module(**config))
61
- else:
62
- _jam_modules = self._JAM_MODULES
63
- for name, cfg in config.items():
64
- try:
65
- module = self.build_module(name, cfg, _jam_modules)
66
- if name == "jwt":
67
- self.module = module
68
- setattr(self, name, module)
69
- logger.debug(
70
- f"Auth module '{name}' successfully initialized"
71
- )
72
- except Exception as e:
73
- logger.exception(
74
- f"Failed to initialize auth module '{name}': {e}"
75
- )
54
+ # config build
55
+ for name, cfg in config.items():
56
+ try:
57
+ module = self.build_module(name, cfg, self._JAM_MODULES)
58
+ if name == "jwt":
59
+ self.module = module
60
+ setattr(self, name, module)
61
+ logger.debug(f"Auth module '{name}' successfully initialized")
62
+ except Exception as e:
63
+ logger.exception(
64
+ f"Failed to initialize auth module '{name}': {e}"
65
+ )
76
66
  gc.collect()
77
67
 
78
68
  def _otp_module_setup(self) -> Callable:
@@ -106,7 +96,13 @@ class Jam(BaseJam):
106
96
  Returns:
107
97
  dict[str, Any]: Payload
108
98
  """
109
- return await self.jwt.make_payload(exp=exp, **data)
99
+ payload = {
100
+ "iat": datetime.datetime.now().timestamp(),
101
+ "exp": (datetime.datetime.now().timestamp() + exp) if exp else None,
102
+ "jti": str(uuid.uuid4()),
103
+ }
104
+ payload = payload | data
105
+ return payload
110
106
 
111
107
  async def jwt_create_token(self, payload: dict[str, Any]) -> str:
112
108
  """Create JWT token.
@@ -275,243 +271,6 @@ class Jam(BaseJam):
275
271
  secret=secret, digits=self._otp.digits, digest=self._otp.digest
276
272
  ).verify(code=code, factor=factor, look_ahead=look_ahead)
277
273
 
278
- @deprecated("This method is deprecated, use: Jam.jwt_create_token")
279
- async def gen_jwt_token(self, payload: dict[str, Any]) -> str:
280
- """Creating a new token.
281
-
282
- Args:
283
- payload (dict[str, Any]): Payload with information
284
-
285
- Deprecated:
286
- Use: `Jam.jwt_create_token`
287
-
288
- Raises:
289
- EmptySecretKey: If the HMAC algorithm is selected, but the secret key is None
290
- EmtpyPrivateKey: If RSA algorithm is selected, but private key None
291
-
292
- Returns:
293
- (str): Generated token
294
- """
295
- return await self.jwt.gen_token(**payload)
296
-
297
- @deprecated("This method is deprecated, use: Jam.jwt_verify_token")
298
- async def verify_jwt_token(
299
- self, token: str, check_exp: bool = True, check_list: bool = True
300
- ) -> dict[str, Any]:
301
- """A method for verifying a token.
302
-
303
- Args:
304
- token (str): The token to check
305
- check_exp (bool): Check for expiration?
306
- check_list (bool): Check if there is a black/white list
307
-
308
- Deprecated:
309
- Use: `Jam.jwt_verify_token`
310
-
311
- Raises:
312
- ValueError: If the token is invalid.
313
- EmptySecretKey: If the HMAC algorithm is selected, but the secret key is None.
314
- EmtpyPublicKey: If RSA algorithm is selected, but public key None.
315
- NotFoundSomeInPayload: If 'exp' not found in payload.
316
- TokenLifeTimeExpired: If token has expired.
317
- TokenNotInWhiteList: If the list type is white, but the token is not there
318
- TokenInBlackList: If the list type is black and the token is there
319
-
320
- Returns:
321
- (dict[str, Any]): Payload from token
322
- """
323
- return await self.jwt.validate_payload(
324
- token=token, check_exp=check_exp, check_list=check_list
325
- )
326
-
327
- @deprecated("This method is deprecated, use: Jam.jwt_make_payload")
328
- async def make_payload(
329
- self, exp: Optional[int] = None, **data: Any
330
- ) -> dict[str, Any]:
331
- """Payload maker tool.
332
-
333
- Args:
334
- exp (int | None): If none exp = JWTModule.exp
335
- **data: Custom data
336
-
337
- Deprecated:
338
- Use: `Jam.jwt_make_payload`
339
- """
340
- return await self.jwt.make_payload(exp=exp, **data)
341
-
342
- @deprecated("This method is deprecated, use: `Jam.session_create`")
343
- async def create_session(
344
- self, session_key: str, data: dict[str, Any]
345
- ) -> str:
346
- """Create new session.
347
-
348
- Args:
349
- session_key (str): Key for sessions
350
- data (dict[str, Any]): Session payload
351
-
352
- Deprecated:
353
- Use: `Jam.session_create`
354
-
355
- Returns:
356
- str: New session ID
357
- """
358
- return await self.session.create(session_key, data)
359
-
360
- @deprecated("This method is deprecates, use: Jam.session_get")
361
- async def get_session(self, session_id: str) -> Optional[dict[str, Any]]:
362
- """Retrieve session data by session ID.
363
-
364
- Args:
365
- session_id (str): Session ID
366
-
367
- Deprecated:
368
- Use: `Jam.session_get`
369
-
370
- Returns:
371
- dict | None: Session payload if exists
372
- """
373
- return await self.session.get(session_id)
374
-
375
- @deprecated("This method is deprecated, use: Jam.session_delete")
376
- async def delete_session(self, session_id: str) -> None:
377
- """Delete a session by its ID.
378
-
379
- Args:
380
- session_id (str): Session ID
381
-
382
- Deprecated:
383
- Use: `Jam.session_delete`
384
-
385
- Returns:
386
- None
387
- """
388
- return await self.session.delete(session_id)
389
-
390
- @deprecated("This method is deprecated, use: Jam.session_update")
391
- async def update_session(
392
- self, session_id: str, data: dict[str, Any]
393
- ) -> None:
394
- """Update session data by session ID.
395
-
396
- Args:
397
- session_id (str): Session ID
398
- data (dict[str, Any]): Data for update
399
-
400
- Deprecated:
401
- Use: `Jam.session_update`
402
-
403
- Returns:
404
- None
405
- """
406
- return await self.session.update(session_id, data)
407
-
408
- @deprecated("This method is deprecated, use: Jam.session_clear")
409
- async def clear_sessions(self, session_key: str) -> None:
410
- """Clear all sessions associated with a specific session key.
411
-
412
- Args:
413
- session_key (str): Key for session scope
414
-
415
- Deprecated:
416
- Use: `Jam.session_clear`
417
-
418
- Returns:
419
- None
420
- """
421
- return await self.session.clear(session_key)
422
-
423
- @deprecated("This method is deprecated, use: Jam.session_rework")
424
- async def rework_session(self, old_session_key: str) -> str:
425
- """Rework an existing session key to a new one.
426
-
427
- Args:
428
- old_session_key (str): Rework session
429
-
430
- Deprecated:
431
- Use: `Jam.session_rework`
432
-
433
- Returns:
434
- str: New session ID
435
- """
436
- return await self.session.rework(old_session_key)
437
-
438
- @deprecated("This method is deprecated, use: Jam.otp_code")
439
- async def get_otp_code(
440
- self, secret: Union[str, bytes], factor: Optional[int] = None
441
- ) -> str:
442
- """Generates an OTP.
443
-
444
- Args:
445
- secret (str | bytes): User secret key.
446
- factor (int | None, optional): Unixtime for TOTP(if none, use now time) / Counter for HOTP.
447
-
448
- Deprecated:
449
- Use: `Jam.otp_code`
450
-
451
- Returns:
452
- str: OTP code (fixed-length string).
453
- """
454
- self._otp_checker()
455
- return self._otp_module(
456
- secret=secret, digits=self._otp.digits, digest=self._otp.digest
457
- ).at(factor)
458
-
459
- @deprecated("This method os deprecated, use: Jam.otp_uri")
460
- async def get_otp_uri(
461
- self,
462
- secret: str,
463
- name: Optional[str] = None,
464
- issuer: Optional[str] = None,
465
- counter: Optional[int] = None,
466
- ) -> str:
467
- """Generates an otpauth:// URI for Google Authenticator.
468
-
469
- Args:
470
- secret (str): User secret key.
471
- name (str): Account name (e.g., email).
472
- issuer (str): Service name (e.g., "GitHub").
473
- counter (int | None, optional): Counter (for HOTP). Default is None.
474
-
475
- Deprecated:
476
- Use: `Jam.otp_uri`
477
-
478
- Returns:
479
- str: A string of the form "otpauth://..."
480
- """
481
- self._otp_checker()
482
- return self._otp_module(
483
- secret=secret, digits=self._otp.digits, digest=self._otp.digest
484
- ).provisioning_uri(
485
- name=name, issuer=issuer, type_=self._otp.type, counter=counter
486
- )
487
-
488
- @deprecated("This method is deprecated, use: Jam.otp_verify_code")
489
- async def verify_otp_code(
490
- self,
491
- secret: Union[str, bytes],
492
- code: str,
493
- factor: Optional[int] = None,
494
- look_ahead: Optional[int] = 1,
495
- ) -> bool:
496
- """Checks the OTP code, taking into account the acceptable window.
497
-
498
- Args:
499
- secret (str | bytes): User secret key.
500
- code (str): The code entered.
501
- factor (int | None, optional): Unixtime for TOTP(if none, use now time) / Counter for HOTP.
502
- look_ahead (int, optional): Acceptable deviation in intervals (±window(totp) / ±look ahead(hotp)). Default is 1.
503
-
504
- Deprecated:
505
- Use: `Jam.otp_verify_code`
506
-
507
- Returns:
508
- bool: True if the code matches, otherwise False.
509
- """
510
- self._otp_checker()
511
- return self._otp_module(
512
- secret=secret, digits=self._otp.digits, digest=self._otp.digest
513
- ).verify(code=code, factor=factor, look_ahead=look_ahead)
514
-
515
274
  async def oauth2_get_authorized_url(
516
275
  self, provider: str, scope: list[str], **extra_params: Any
517
276
  ) -> str: