sanic-security 1.12.2__tar.gz → 1.12.3__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 (21) hide show
  1. {sanic_security-1.12.2/sanic_security.egg-info → sanic_security-1.12.3}/PKG-INFO +5 -13
  2. {sanic_security-1.12.2 → sanic_security-1.12.3}/README.md +4 -12
  3. {sanic_security-1.12.2 → sanic_security-1.12.3}/pyproject.toml +1 -1
  4. {sanic_security-1.12.2 → sanic_security-1.12.3}/sanic_security/authentication.py +1 -0
  5. {sanic_security-1.12.2 → sanic_security-1.12.3}/sanic_security/models.py +7 -2
  6. {sanic_security-1.12.2 → sanic_security-1.12.3}/sanic_security/test/server.py +1 -3
  7. {sanic_security-1.12.2 → sanic_security-1.12.3/sanic_security.egg-info}/PKG-INFO +5 -13
  8. {sanic_security-1.12.2 → sanic_security-1.12.3}/LICENSE +0 -0
  9. {sanic_security-1.12.2 → sanic_security-1.12.3}/sanic_security/__init__.py +0 -0
  10. {sanic_security-1.12.2 → sanic_security-1.12.3}/sanic_security/authorization.py +0 -0
  11. {sanic_security-1.12.2 → sanic_security-1.12.3}/sanic_security/configuration.py +0 -0
  12. {sanic_security-1.12.2 → sanic_security-1.12.3}/sanic_security/exceptions.py +0 -0
  13. {sanic_security-1.12.2 → sanic_security-1.12.3}/sanic_security/test/__init__.py +0 -0
  14. {sanic_security-1.12.2 → sanic_security-1.12.3}/sanic_security/test/tests.py +0 -0
  15. {sanic_security-1.12.2 → sanic_security-1.12.3}/sanic_security/utils.py +0 -0
  16. {sanic_security-1.12.2 → sanic_security-1.12.3}/sanic_security/verification.py +0 -0
  17. {sanic_security-1.12.2 → sanic_security-1.12.3}/sanic_security.egg-info/SOURCES.txt +0 -0
  18. {sanic_security-1.12.2 → sanic_security-1.12.3}/sanic_security.egg-info/dependency_links.txt +0 -0
  19. {sanic_security-1.12.2 → sanic_security-1.12.3}/sanic_security.egg-info/requires.txt +0 -0
  20. {sanic_security-1.12.2 → sanic_security-1.12.3}/sanic_security.egg-info/top_level.txt +0 -0
  21. {sanic_security-1.12.2 → sanic_security-1.12.3}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: sanic-security
3
- Version: 1.12.2
3
+ Version: 1.12.3
4
4
  Summary: An async security library for the Sanic framework.
5
5
  Author-email: Aidan Stewart <na.stewart365@gmail.com>
6
6
  Project-URL: Documentation, https://security.na-stewart.com/
@@ -295,8 +295,6 @@ async def on_logout(request):
295
295
 
296
296
  * Authenticate
297
297
 
298
- New/Refreshed session returned if client's session expired during authentication, requires encoding.
299
-
300
298
  ```python
301
299
  @app.post("api/security/auth")
302
300
  async def on_authenticate(request):
@@ -305,15 +303,11 @@ async def on_authenticate(request):
305
303
  "You have been authenticated.",
306
304
  authentication_session.json,
307
305
  )
308
- if authentication_session.is_refresh:
309
- authentication_session.encode(response)
310
306
  return response
311
307
  ```
312
308
 
313
309
  * Requires Authentication (This method is not called directly and instead used as a decorator)
314
310
 
315
- New/Refreshed session returned if client's session expired during authentication, requires encoding.
316
-
317
311
  ```python
318
312
  @app.post("api/security/auth")
319
313
  @requires_authentication
@@ -323,24 +317,22 @@ async def on_authenticate(request):
323
317
  "You have been authenticated.",
324
318
  authentication_session.json,
325
319
  )
326
- if authentication_session.is_refresh:
327
- authentication_session.encode(response)
328
320
  return response
329
321
  ```
330
322
 
331
323
  * Authentication Middleware
332
324
 
333
- Refreshed session can be encoded automatically via middleware.
325
+ New/Refreshed session returned if client's session expired during authentication, requires encoding.
326
+
327
+ Middleware is recommended to automatically encode the refreshed session.
334
328
 
335
329
  ```python
336
330
  @app.on_response
337
331
  async def authentication_refresh_encoder(request, response):
338
- try:
332
+ if hasattr(request.ctx, "authentication_session"):
339
333
  authentication_session = request.ctx.authentication_session
340
334
  if authentication_session.is_refresh:
341
335
  authentication_session.encode(response)
342
- except AttributeError:
343
- pass
344
336
  ```
345
337
 
346
338
  ## Captcha
@@ -264,8 +264,6 @@ async def on_logout(request):
264
264
 
265
265
  * Authenticate
266
266
 
267
- New/Refreshed session returned if client's session expired during authentication, requires encoding.
268
-
269
267
  ```python
270
268
  @app.post("api/security/auth")
271
269
  async def on_authenticate(request):
@@ -274,15 +272,11 @@ async def on_authenticate(request):
274
272
  "You have been authenticated.",
275
273
  authentication_session.json,
276
274
  )
277
- if authentication_session.is_refresh:
278
- authentication_session.encode(response)
279
275
  return response
280
276
  ```
281
277
 
282
278
  * Requires Authentication (This method is not called directly and instead used as a decorator)
283
279
 
284
- New/Refreshed session returned if client's session expired during authentication, requires encoding.
285
-
286
280
  ```python
287
281
  @app.post("api/security/auth")
288
282
  @requires_authentication
@@ -292,24 +286,22 @@ async def on_authenticate(request):
292
286
  "You have been authenticated.",
293
287
  authentication_session.json,
294
288
  )
295
- if authentication_session.is_refresh:
296
- authentication_session.encode(response)
297
289
  return response
298
290
  ```
299
291
 
300
292
  * Authentication Middleware
301
293
 
302
- Refreshed session can be encoded automatically via middleware.
294
+ New/Refreshed session returned if client's session expired during authentication, requires encoding.
295
+
296
+ Middleware is recommended to automatically encode the refreshed session.
303
297
 
304
298
  ```python
305
299
  @app.on_response
306
300
  async def authentication_refresh_encoder(request, response):
307
- try:
301
+ if hasattr(request.ctx, "authentication_session"):
308
302
  authentication_session = request.ctx.authentication_session
309
303
  if authentication_session.is_refresh:
310
304
  authentication_session.encode(response)
311
- except AttributeError:
312
- pass
313
305
  ```
314
306
 
315
307
  ## Captcha
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "sanic-security"
7
- version = "1.12.2"
7
+ version = "1.12.3"
8
8
  requires-python = ">=3.8"
9
9
  dependencies = [
10
10
  "tortoise-orm>=0.17.0",
@@ -223,6 +223,7 @@ async def authenticate(request: Request) -> AuthenticationSession:
223
223
  authentication_session.bearer.validate()
224
224
  except ExpiredError:
225
225
  authentication_session = await authentication_session.refresh(request)
226
+ request.ctx.authentication_session = authentication_session
226
227
  return authentication_session
227
228
 
228
229
 
@@ -296,8 +296,13 @@ class Session(BaseModel):
296
296
  samesite=security_config.SESSION_SAMESITE,
297
297
  secure=security_config.SESSION_SECURE,
298
298
  )
299
- if self.expiration_date:
300
- response.cookies.get_cookie(cookie).expires = self.expiration_date
299
+ if self.expiration_date: # Overrides refresh expiration.
300
+ if hasattr(self, "refresh_expiration_date"):
301
+ response.cookies.get_cookie(cookie).expires = (
302
+ self.refresh_expiration_date
303
+ )
304
+ else:
305
+ response.cookies.get_cookie(cookie).expires = self.expiration_date
301
306
  if security_config.SESSION_DOMAIN:
302
307
  response.cookies.get_cookie(cookie).domain = security_config.SESSION_DOMAIN
303
308
 
@@ -175,12 +175,10 @@ async def on_authenticate(request):
175
175
 
176
176
  @app.on_response
177
177
  async def authentication_refresh_encoder(request, response):
178
- try:
178
+ if hasattr(request.ctx, "authentication_session"):
179
179
  authentication_session = request.ctx.authentication_session
180
180
  if authentication_session.is_refresh:
181
181
  authentication_session.encode(response)
182
- except AttributeError:
183
- pass
184
182
 
185
183
 
186
184
  @app.post("api/test/auth/expire")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: sanic-security
3
- Version: 1.12.2
3
+ Version: 1.12.3
4
4
  Summary: An async security library for the Sanic framework.
5
5
  Author-email: Aidan Stewart <na.stewart365@gmail.com>
6
6
  Project-URL: Documentation, https://security.na-stewart.com/
@@ -295,8 +295,6 @@ async def on_logout(request):
295
295
 
296
296
  * Authenticate
297
297
 
298
- New/Refreshed session returned if client's session expired during authentication, requires encoding.
299
-
300
298
  ```python
301
299
  @app.post("api/security/auth")
302
300
  async def on_authenticate(request):
@@ -305,15 +303,11 @@ async def on_authenticate(request):
305
303
  "You have been authenticated.",
306
304
  authentication_session.json,
307
305
  )
308
- if authentication_session.is_refresh:
309
- authentication_session.encode(response)
310
306
  return response
311
307
  ```
312
308
 
313
309
  * Requires Authentication (This method is not called directly and instead used as a decorator)
314
310
 
315
- New/Refreshed session returned if client's session expired during authentication, requires encoding.
316
-
317
311
  ```python
318
312
  @app.post("api/security/auth")
319
313
  @requires_authentication
@@ -323,24 +317,22 @@ async def on_authenticate(request):
323
317
  "You have been authenticated.",
324
318
  authentication_session.json,
325
319
  )
326
- if authentication_session.is_refresh:
327
- authentication_session.encode(response)
328
320
  return response
329
321
  ```
330
322
 
331
323
  * Authentication Middleware
332
324
 
333
- Refreshed session can be encoded automatically via middleware.
325
+ New/Refreshed session returned if client's session expired during authentication, requires encoding.
326
+
327
+ Middleware is recommended to automatically encode the refreshed session.
334
328
 
335
329
  ```python
336
330
  @app.on_response
337
331
  async def authentication_refresh_encoder(request, response):
338
- try:
332
+ if hasattr(request.ctx, "authentication_session"):
339
333
  authentication_session = request.ctx.authentication_session
340
334
  if authentication_session.is_refresh:
341
335
  authentication_session.encode(response)
342
- except AttributeError:
343
- pass
344
336
  ```
345
337
 
346
338
  ## Captcha
File without changes