sanic-security 1.17.1__py3-none-any.whl → 1.17.2__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.
@@ -368,12 +368,12 @@ def initialize_security(app: Sanic, create_root: bool = True) -> None:
368
368
  await account.roles.add(role)
369
369
  logger.info("Initial admin account created.")
370
370
 
371
- @app.on_response
372
- async def session_middleware(request, response):
373
- if hasattr(request.ctx, "session"):
374
- if getattr(request.ctx.session, "is_refresh", False):
375
- request.ctx.session.encode(response)
376
- elif not request.ctx.session.active:
377
- response.delete_cookie(
378
- f"{config.SESSION_PREFIX}_{request.ctx.session.__class__.__name__[:7].lower()}"
379
- )
371
+ @app.on_response
372
+ async def session_middleware(request, response):
373
+ if hasattr(request.ctx, "session"):
374
+ if getattr(request.ctx.session, "is_refresh", False):
375
+ request.ctx.session.encode(response)
376
+ elif not request.ctx.session.active:
377
+ response.delete_cookie(
378
+ f"{config.SESSION_PREFIX}_{request.ctx.session.__class__.__name__[:7].lower()}"
379
+ )
@@ -218,14 +218,14 @@ async def on_captcha_attempt(request):
218
218
  @app.post("api/test/two-step/request")
219
219
  async def on_request_verification(request):
220
220
  """Request two-step verification with code in the response."""
221
- two_step_session = await request_two_step_verification(request)
221
+ two_step_session = await request_two_step_verification(request, tag="forgot-pass")
222
222
  response = json("Verification request successful!", two_step_session.code)
223
223
  two_step_session.encode(response)
224
224
  return response
225
225
 
226
226
 
227
227
  @app.post("api/test/two-step")
228
- @requires_two_step_verification
228
+ @requires_two_step_verification("forgot-pass")
229
229
  async def on_verification_attempt(request):
230
230
  """Attempt two-step verification challenge."""
231
231
  return json("Two step verification attempt successful!", request.ctx.session.json)
@@ -135,12 +135,15 @@ def requires_two_step_verification(func=None, *, tag="2sv"):
135
135
  ChallengeError
136
136
  MaxedOutChallengeError
137
137
  """
138
+ if isinstance(func, str):
139
+ tag = func
140
+ func = None
138
141
 
139
- def decorator(func):
140
- @functools.wraps(func)
142
+ def decorator(inner_func):
143
+ @functools.wraps(inner_func)
141
144
  async def wrapper(request, *args, **kwargs):
142
145
  await two_step_verification(request, tag)
143
- return await func(request, *args, **kwargs)
146
+ return await inner_func(request, *args, **kwargs)
144
147
 
145
148
  return wrapper
146
149
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: sanic-security
3
- Version: 1.17.1
3
+ Version: 1.17.2
4
4
  Summary: An async security library for the Sanic framework.
5
5
  Author-email: Aidan Stewart <me@na-stewart.com>
6
6
  Project-URL: Documentation, https://security.na-stewart.com/
@@ -70,8 +70,8 @@ Dynamic: license-file
70
70
  <!-- ABOUT THE PROJECT -->
71
71
  ## About The Project
72
72
 
73
- Sanic Security is an authentication, authorization, and verification library designed for use with the
74
- [Sanic](https://github.com/huge-success/sanic) web app framework.
73
+ Sanic Security is a suite of authentication, authorization, and verification tools designed for use with the
74
+ [Sanic](https://github.com/sanic-org/sanic) web app framework.
75
75
 
76
76
  * OAuth2 integration
77
77
  * Login, registration, and authentication with refresh mechanisms
@@ -463,7 +463,7 @@ Two-step verification should be integrated with other custom functionalities, su
463
463
  ```python
464
464
  @app.post("api/security/two-step/request")
465
465
  async def on_two_step_request(request):
466
- two_step_session = await request_two_step_verification(request) # Code = T2I58I
466
+ two_step_session = await request_two_step_verification(request, tag="forgot-pass") # Code = T2I58I
467
467
  await email_code(
468
468
  two_step_session.bearer.email, two_step_session.code
469
469
  ) # Custom method for emailing verification code.
@@ -493,7 +493,7 @@ async def on_two_step_resend(request):
493
493
  ```python
494
494
  @app.post("api/security/two-step")
495
495
  async def on_two_step_verification(request):
496
- two_step_session = await two_step_verification(request)
496
+ two_step_session = await two_step_verification(request, "forgot-pass")
497
497
  response = json("Two-step verification attempt successful!", two_step_session.json)
498
498
  return response
499
499
  ```
@@ -506,7 +506,7 @@ async def on_two_step_verification(request):
506
506
 
507
507
  ```python
508
508
  @app.post("api/security/two-step")
509
- @requires_two_step_verification
509
+ @requires_two_step_verification("forgot-pass")
510
510
  async def on_two_step_verification(request):
511
511
  response = json(
512
512
  "Two-step verification attempt successful!", request.ctx.session.json
@@ -551,7 +551,7 @@ async def on_check_perms(request):
551
551
  return json("Account is authorized.", authentication_session.json)
552
552
  ```
553
553
 
554
- * Require Permissions (this method is not called directly and instead used as a decorator.)
554
+ * Requires Permission (this method is not called directly and instead used as a decorator.)
555
555
 
556
556
  ```python
557
557
  @app.post("api/security/perms")
@@ -569,7 +569,7 @@ async def on_check_roles(request):
569
569
  return json("Account is authorized.", authentication_session.json)
570
570
  ```
571
571
 
572
- * Require Roles (This method is not called directly and instead used as a decorator)
572
+ * Requires Role (This method is not called directly and instead used as a decorator)
573
573
 
574
574
  ```python
575
575
  @app.post("api/security/roles")
@@ -1,17 +1,17 @@
1
1
  sanic_security/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
- sanic_security/authentication.py,sha256=kRcxddITe7FrfXCV_71DRGq8U39wJNmXwG1bfnuw-p0,13528
2
+ sanic_security/authentication.py,sha256=TUGLQKVEH6WkXE82rh-ZY6k77-6cWfREXaNNf4MjLzU,13492
3
3
  sanic_security/authorization.py,sha256=JY3vIG_zlTNaTZ9xyExTADhlLLnfzYZ5FLOePovhzVA,7992
4
4
  sanic_security/configuration.py,sha256=2_XdxFcmMq4UNl1NUon1zBIKMfYCeMN3ixBZTgrNQRM,6039
5
5
  sanic_security/exceptions.py,sha256=CiH4M2bXZpGyh--eGG0TQdZjOu_mjKQiqnalpCLHLGM,4791
6
6
  sanic_security/models.py,sha256=c7j2RxuwA0PEWzoClplNROK9HWAw7-qATHMsaviqYLM,22133
7
7
  sanic_security/oauth.py,sha256=1aYPr5QGFv-mQYhSoExP7eszn7us0AOy2QJZiQPkptU,8403
8
8
  sanic_security/utils.py,sha256=B-nSBwP2sClkXfJHs5g7t9jmMHnl4LXJPUAeraDBQ7Y,3641
9
- sanic_security/verification.py,sha256=qQGc-vn22NM3JkYVERl-1SvG4tv1XN8agTWvuKPKNBE,8193
9
+ sanic_security/verification.py,sha256=6YMfO5lTAhfTkkp4uUwJPuCDY_NOZlwaUjrOZq4CsoI,8280
10
10
  sanic_security/test/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
11
- sanic_security/test/server.py,sha256=cmRHXyONBY5RZkIgfz6__dMKTr-LGZBFThz0Tp0272o,13363
11
+ sanic_security/test/server.py,sha256=-vzpbLE2NkmBfsHkPv2d9-QGL1x2uYSrYwaq95FyvW8,13397
12
12
  sanic_security/test/tests.py,sha256=AbFCyK7Fg8FjI_Iisi4vAr-ebWsPdKWauZQuyBkAMEo,22071
13
- sanic_security-1.17.1.dist-info/licenses/LICENSE,sha256=DlJ21DRx8S4vaYJPBIDT3Rik4FaxXVYNottjE7oBZio,1079
14
- sanic_security-1.17.1.dist-info/METADATA,sha256=Jibu09vjT3-TMrViVC2-GddmhRwb4GE8lFZ0usCRmK0,24753
15
- sanic_security-1.17.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
16
- sanic_security-1.17.1.dist-info/top_level.txt,sha256=ZybkhHXSjfzhmv8XeqLvnNmLmv21Z0oPX6Ep4DJN8b0,15
17
- sanic_security-1.17.1.dist-info/RECORD,,
13
+ sanic_security-1.17.2.dist-info/licenses/LICENSE,sha256=DlJ21DRx8S4vaYJPBIDT3Rik4FaxXVYNottjE7oBZio,1079
14
+ sanic_security-1.17.2.dist-info/METADATA,sha256=fTcvfKa4hHNDZSdxYClhtY8VUEDcAVnDoJB9q0mwHQ0,24805
15
+ sanic_security-1.17.2.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
16
+ sanic_security-1.17.2.dist-info/top_level.txt,sha256=ZybkhHXSjfzhmv8XeqLvnNmLmv21Z0oPX6Ep4DJN8b0,15
17
+ sanic_security-1.17.2.dist-info/RECORD,,