sanic-security 1.17.0__tar.gz → 1.17.2__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 (22) hide show
  1. {sanic_security-1.17.0/sanic_security.egg-info → sanic_security-1.17.2}/PKG-INFO +10 -10
  2. {sanic_security-1.17.0 → sanic_security-1.17.2}/README.md +9 -9
  3. {sanic_security-1.17.0 → sanic_security-1.17.2}/pyproject.toml +1 -1
  4. {sanic_security-1.17.0 → sanic_security-1.17.2}/sanic_security/authentication.py +10 -10
  5. {sanic_security-1.17.0 → sanic_security-1.17.2}/sanic_security/test/server.py +3 -3
  6. {sanic_security-1.17.0 → sanic_security-1.17.2}/sanic_security/verification.py +6 -3
  7. {sanic_security-1.17.0 → sanic_security-1.17.2/sanic_security.egg-info}/PKG-INFO +10 -10
  8. {sanic_security-1.17.0 → sanic_security-1.17.2}/LICENSE +0 -0
  9. {sanic_security-1.17.0 → sanic_security-1.17.2}/sanic_security/__init__.py +0 -0
  10. {sanic_security-1.17.0 → sanic_security-1.17.2}/sanic_security/authorization.py +0 -0
  11. {sanic_security-1.17.0 → sanic_security-1.17.2}/sanic_security/configuration.py +0 -0
  12. {sanic_security-1.17.0 → sanic_security-1.17.2}/sanic_security/exceptions.py +0 -0
  13. {sanic_security-1.17.0 → sanic_security-1.17.2}/sanic_security/models.py +0 -0
  14. {sanic_security-1.17.0 → sanic_security-1.17.2}/sanic_security/oauth.py +0 -0
  15. {sanic_security-1.17.0 → sanic_security-1.17.2}/sanic_security/test/__init__.py +0 -0
  16. {sanic_security-1.17.0 → sanic_security-1.17.2}/sanic_security/test/tests.py +0 -0
  17. {sanic_security-1.17.0 → sanic_security-1.17.2}/sanic_security/utils.py +0 -0
  18. {sanic_security-1.17.0 → sanic_security-1.17.2}/sanic_security.egg-info/SOURCES.txt +0 -0
  19. {sanic_security-1.17.0 → sanic_security-1.17.2}/sanic_security.egg-info/dependency_links.txt +0 -0
  20. {sanic_security-1.17.0 → sanic_security-1.17.2}/sanic_security.egg-info/requires.txt +0 -0
  21. {sanic_security-1.17.0 → sanic_security-1.17.2}/sanic_security.egg-info/top_level.txt +0 -0
  22. {sanic_security-1.17.0 → sanic_security-1.17.2}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: sanic-security
3
- Version: 1.17.0
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
@@ -268,7 +268,7 @@ Phone can be null or empty.
268
268
  @app.post("api/security/register")
269
269
  async def on_register(request):
270
270
  account = await register(request)
271
- two_step_session = await request_two_step_verification(request, account, "2fa")
271
+ two_step_session = await request_two_step_verification(request, account)
272
272
  await email_code(
273
273
  account.email, two_step_session.code # Code = 24KF19
274
274
  ) # Custom method for emailing verification code.
@@ -309,7 +309,7 @@ You can use a username as well as an email for login if `ALLOW_LOGIN_WITH_USERNA
309
309
  async def on_login(request):
310
310
  authentication_session = await login(request, require_second_factor=True)
311
311
  two_step_session = await request_two_step_verification(
312
- request, authentication_session.bearer
312
+ request, authentication_session.bearer, "2fa"
313
313
  )
314
314
  await email_code(
315
315
  authentication_session.bearer.email, two_step_session.code # Code = XGED2U
@@ -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")
@@ -37,8 +37,8 @@
37
37
  <!-- ABOUT THE PROJECT -->
38
38
  ## About The Project
39
39
 
40
- Sanic Security is an authentication, authorization, and verification library designed for use with the
41
- [Sanic](https://github.com/huge-success/sanic) web app framework.
40
+ Sanic Security is a suite of authentication, authorization, and verification tools designed for use with the
41
+ [Sanic](https://github.com/sanic-org/sanic) web app framework.
42
42
 
43
43
  * OAuth2 integration
44
44
  * Login, registration, and authentication with refresh mechanisms
@@ -235,7 +235,7 @@ Phone can be null or empty.
235
235
  @app.post("api/security/register")
236
236
  async def on_register(request):
237
237
  account = await register(request)
238
- two_step_session = await request_two_step_verification(request, account, "2fa")
238
+ two_step_session = await request_two_step_verification(request, account)
239
239
  await email_code(
240
240
  account.email, two_step_session.code # Code = 24KF19
241
241
  ) # Custom method for emailing verification code.
@@ -276,7 +276,7 @@ You can use a username as well as an email for login if `ALLOW_LOGIN_WITH_USERNA
276
276
  async def on_login(request):
277
277
  authentication_session = await login(request, require_second_factor=True)
278
278
  two_step_session = await request_two_step_verification(
279
- request, authentication_session.bearer
279
+ request, authentication_session.bearer, "2fa"
280
280
  )
281
281
  await email_code(
282
282
  authentication_session.bearer.email, two_step_session.code # Code = XGED2U
@@ -430,7 +430,7 @@ Two-step verification should be integrated with other custom functionalities, su
430
430
  ```python
431
431
  @app.post("api/security/two-step/request")
432
432
  async def on_two_step_request(request):
433
- two_step_session = await request_two_step_verification(request) # Code = T2I58I
433
+ two_step_session = await request_two_step_verification(request, tag="forgot-pass") # Code = T2I58I
434
434
  await email_code(
435
435
  two_step_session.bearer.email, two_step_session.code
436
436
  ) # Custom method for emailing verification code.
@@ -460,7 +460,7 @@ async def on_two_step_resend(request):
460
460
  ```python
461
461
  @app.post("api/security/two-step")
462
462
  async def on_two_step_verification(request):
463
- two_step_session = await two_step_verification(request)
463
+ two_step_session = await two_step_verification(request, "forgot-pass")
464
464
  response = json("Two-step verification attempt successful!", two_step_session.json)
465
465
  return response
466
466
  ```
@@ -473,7 +473,7 @@ async def on_two_step_verification(request):
473
473
 
474
474
  ```python
475
475
  @app.post("api/security/two-step")
476
- @requires_two_step_verification
476
+ @requires_two_step_verification("forgot-pass")
477
477
  async def on_two_step_verification(request):
478
478
  response = json(
479
479
  "Two-step verification attempt successful!", request.ctx.session.json
@@ -518,7 +518,7 @@ async def on_check_perms(request):
518
518
  return json("Account is authorized.", authentication_session.json)
519
519
  ```
520
520
 
521
- * Require Permissions (this method is not called directly and instead used as a decorator.)
521
+ * Requires Permission (this method is not called directly and instead used as a decorator.)
522
522
 
523
523
  ```python
524
524
  @app.post("api/security/perms")
@@ -536,7 +536,7 @@ async def on_check_roles(request):
536
536
  return json("Account is authorized.", authentication_session.json)
537
537
  ```
538
538
 
539
- * Require Roles (This method is not called directly and instead used as a decorator)
539
+ * Requires Role (This method is not called directly and instead used as a decorator)
540
540
 
541
541
  ```python
542
542
  @app.post("api/security/roles")
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "sanic-security"
7
- version = "1.17.0"
7
+ version = "1.17.2"
8
8
  requires-python = ">=3.8"
9
9
  dependencies = [
10
10
  "tortoise-orm>=0.17.0",
@@ -185,7 +185,7 @@ async def fulfill_second_factor(request: Request) -> AuthenticationSession:
185
185
  authentication_session = await AuthenticationSession.decode(request)
186
186
  if not authentication_session.requires_second_factor:
187
187
  raise DeactivatedError("Session second factor requirement already met.", 403)
188
- two_step_session = await TwoStepSession.decode(request)
188
+ two_step_session = await TwoStepSession.decode(request, tag="2fa")
189
189
  two_step_session.validate()
190
190
  await two_step_session.check_code(request.form.get("code"))
191
191
  authentication_session.requires_second_factor = False
@@ -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
+ )
@@ -101,7 +101,7 @@ async def on_login(request):
101
101
  )
102
102
  if str_to_bool(request.args.get("two-factor-authentication")):
103
103
  two_step_session = await request_two_step_verification(
104
- request, authentication_session.bearer
104
+ request, authentication_session.bearer, "2fa"
105
105
  )
106
106
  response = json(
107
107
  "Login successful! Two-factor authentication required.",
@@ -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.0
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
@@ -268,7 +268,7 @@ Phone can be null or empty.
268
268
  @app.post("api/security/register")
269
269
  async def on_register(request):
270
270
  account = await register(request)
271
- two_step_session = await request_two_step_verification(request, account, "2fa")
271
+ two_step_session = await request_two_step_verification(request, account)
272
272
  await email_code(
273
273
  account.email, two_step_session.code # Code = 24KF19
274
274
  ) # Custom method for emailing verification code.
@@ -309,7 +309,7 @@ You can use a username as well as an email for login if `ALLOW_LOGIN_WITH_USERNA
309
309
  async def on_login(request):
310
310
  authentication_session = await login(request, require_second_factor=True)
311
311
  two_step_session = await request_two_step_verification(
312
- request, authentication_session.bearer
312
+ request, authentication_session.bearer, "2fa"
313
313
  )
314
314
  await email_code(
315
315
  authentication_session.bearer.email, two_step_session.code # Code = XGED2U
@@ -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")
File without changes