sanic-security 1.12.2__py3-none-any.whl → 1.12.3__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.
@@ -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
 
sanic_security/models.py CHANGED
@@ -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
@@ -1,16 +1,16 @@
1
1
  sanic_security/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
- sanic_security/authentication.py,sha256=j-nFOLuNBcacKH34J04JIbsKSZ2JMH33ZqnS6vipwfQ,12508
2
+ sanic_security/authentication.py,sha256=E17jQg1gD06CTRk7l9q8EUzgeAEXn2J0E02Va-QYx9I,12573
3
3
  sanic_security/authorization.py,sha256=aQztMiZG9LDctr_C6QEzO5qScwbxpiLk96XVxwdCChM,6921
4
4
  sanic_security/configuration.py,sha256=p44nTSrBQQSJZYN6qJEod_Ettf90rRNlmPxmNzxqQ9A,5514
5
5
  sanic_security/exceptions.py,sha256=8c3xoQSiIKfSiOQOtw49RG8Qdlc3vZDzqjrEnPad4Ds,5411
6
- sanic_security/models.py,sha256=aB1fFCutUHDAg8jG3_VdZijOblXnSYh99gyA5fOm1u4,20528
6
+ sanic_security/models.py,sha256=OEvO4xUh_7QCdwfaiKt51T3fmn3MJSrIcM1TszDfqgg,20776
7
7
  sanic_security/utils.py,sha256=Zgde7W69ixwv_H8eTs7indO5_U2Jvq62YUpG6ipN768,2629
8
8
  sanic_security/verification.py,sha256=vrxYborEOBKEirOHczul9WYub5j6T2ldXE1gsoA8iyY,7503
9
9
  sanic_security/test/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
10
- sanic_security/test/server.py,sha256=qQtbQh8m9QYf4g1SL8QJbOyyJzAXFaNmDyBxU8b6RBc,12627
10
+ sanic_security/test/server.py,sha256=G5q7mzTUxOpKlhbzNbzTZYSWd6g8a0toOFX9qTA_nVg,12631
11
11
  sanic_security/test/tests.py,sha256=Hg40wlZfC-CDZX6lIjeT6uXy-3BJMc4ChJsnCRCBIu8,22459
12
- sanic_security-1.12.2.dist-info/LICENSE,sha256=sXlJs9_mG-dCkPfWsDnuzydJWagS82E2gYtkVH9enHA,1100
13
- sanic_security-1.12.2.dist-info/METADATA,sha256=YRKIzZgdU5Ka7QXR3Q0DdAj5dnNgHVh4P9vaVi03wV0,23954
14
- sanic_security-1.12.2.dist-info/WHEEL,sha256=mguMlWGMX-VHnMpKOjjQidIo1ssRlCFu4a4mBpz1s2M,91
15
- sanic_security-1.12.2.dist-info/top_level.txt,sha256=ZybkhHXSjfzhmv8XeqLvnNmLmv21Z0oPX6Ep4DJN8b0,15
16
- sanic_security-1.12.2.dist-info/RECORD,,
12
+ sanic_security-1.12.3.dist-info/LICENSE,sha256=sXlJs9_mG-dCkPfWsDnuzydJWagS82E2gYtkVH9enHA,1100
13
+ sanic_security-1.12.3.dist-info/METADATA,sha256=Xaqk6JqUV3Y7IafPDQ85k7VTaghTLTQGtbLpKiZ7gEo,23680
14
+ sanic_security-1.12.3.dist-info/WHEEL,sha256=Z4pYXqR_rTB7OWNDYFOm1qRk0RX6GFP2o8LgvP453Hk,91
15
+ sanic_security-1.12.3.dist-info/top_level.txt,sha256=ZybkhHXSjfzhmv8XeqLvnNmLmv21Z0oPX6Ep4DJN8b0,15
16
+ sanic_security-1.12.3.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (70.1.1)
2
+ Generator: setuptools (70.3.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5