sanic-security 1.10.4__tar.gz → 1.11.0__tar.gz

Sign up to get free protection for your applications and to get access to all the features.
Files changed (22) hide show
  1. {sanic-security-1.10.4/sanic_security.egg-info → sanic-security-1.11.0}/PKG-INFO +15 -10
  2. {sanic-security-1.10.4 → sanic-security-1.11.0}/README.md +14 -9
  3. {sanic-security-1.10.4 → sanic-security-1.11.0}/sanic_security/authentication.py +3 -3
  4. {sanic-security-1.10.4 → sanic-security-1.11.0}/sanic_security/authorization.py +8 -6
  5. {sanic-security-1.10.4 → sanic-security-1.11.0}/sanic_security/test/server.py +14 -13
  6. {sanic-security-1.10.4 → sanic-security-1.11.0}/sanic_security/verification.py +6 -6
  7. {sanic-security-1.10.4 → sanic-security-1.11.0/sanic_security.egg-info}/PKG-INFO +15 -10
  8. {sanic-security-1.10.4 → sanic-security-1.11.0}/setup.py +1 -1
  9. {sanic-security-1.10.4 → sanic-security-1.11.0}/LICENSE +0 -0
  10. {sanic-security-1.10.4 → sanic-security-1.11.0}/MANIFEST.in +0 -0
  11. {sanic-security-1.10.4 → sanic-security-1.11.0}/sanic_security/__init__.py +0 -0
  12. {sanic-security-1.10.4 → sanic-security-1.11.0}/sanic_security/configuration.py +0 -0
  13. {sanic-security-1.10.4 → sanic-security-1.11.0}/sanic_security/exceptions.py +0 -0
  14. {sanic-security-1.10.4 → sanic-security-1.11.0}/sanic_security/models.py +0 -0
  15. {sanic-security-1.10.4 → sanic-security-1.11.0}/sanic_security/test/__init__.py +0 -0
  16. {sanic-security-1.10.4 → sanic-security-1.11.0}/sanic_security/test/tests.py +0 -0
  17. {sanic-security-1.10.4 → sanic-security-1.11.0}/sanic_security/utils.py +0 -0
  18. {sanic-security-1.10.4 → sanic-security-1.11.0}/sanic_security.egg-info/SOURCES.txt +0 -0
  19. {sanic-security-1.10.4 → sanic-security-1.11.0}/sanic_security.egg-info/dependency_links.txt +0 -0
  20. {sanic-security-1.10.4 → sanic-security-1.11.0}/sanic_security.egg-info/requires.txt +0 -0
  21. {sanic-security-1.10.4 → sanic-security-1.11.0}/sanic_security.egg-info/top_level.txt +0 -0
  22. {sanic-security-1.10.4 → sanic-security-1.11.0}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: sanic-security
3
- Version: 1.10.4
3
+ Version: 1.11.0
4
4
  Summary: An effective, simple, and async security library for the Sanic framework.
5
5
  Home-page: https://github.com/na-stewart/sanic-security
6
6
  Author: Aidan Stewart
@@ -98,6 +98,11 @@ pip3 install sanic-security[crypto]
98
98
  pip3 install -e ".[dev]"
99
99
  ````
100
100
 
101
+ * Update sanic-security if already installed.
102
+ ```shell
103
+ pip3 install --upgrade sanic-security
104
+ ```
105
+
101
106
  ### Configuration
102
107
 
103
108
  Sanic Security configuration is merely an object that can be modified either using dot-notation or like a
@@ -277,10 +282,10 @@ async def on_authenticate(request):
277
282
  ```python
278
283
  @app.post("api/security/auth")
279
284
  @requires_authentication()
280
- async def on_authenticate(request, authentication_session):
285
+ async def on_authenticate(request):
281
286
  return json(
282
287
  "You have been authenticated.",
283
- authentication_session.bearer.json,
288
+ request.ctx.authentication_session.bearer.json,
284
289
  )
285
290
  ```
286
291
 
@@ -330,8 +335,8 @@ async def on_captcha(request):
330
335
  ```python
331
336
  @app.post("ap/security/captcha")
332
337
  @requires_captcha()
333
- async def on_captcha(request, captcha_session):
334
- return json("Captcha attempt successful!", captcha_session.json)
338
+ async def on_captcha(request):
339
+ return json("Captcha attempt successful!", request.ctx.captcha_session.json)
335
340
  ```
336
341
 
337
342
  ## Two-step Verification
@@ -393,9 +398,10 @@ async def on_two_step_verification(request):
393
398
  ```python
394
399
  @app.post("api/security/two-step")
395
400
  @requires_two_step_verification()
396
- async def on_two_step_verification(request, two_step_session):
401
+ async def on_two_step_verification(request):
397
402
  response = json(
398
- "Two-step verification attempt successful!", two_step_session.bearer.json
403
+ "Two-step verification attempt successful!",
404
+ request.ctx.two_step_session.bearer.json,
399
405
  )
400
406
  return response
401
407
  ```
@@ -434,13 +440,12 @@ async def on_check_perms(request):
434
440
  return text("Account is authorized.")
435
441
  ```
436
442
 
437
-
438
443
  * Require Permissions (This method is not called directly and instead used as a decorator.)
439
444
 
440
445
  ```python
441
446
  @app.post("api/security/perms")
442
447
  @require_permissions("channels:view", "voice:*")
443
- async def on_check_perms(request, authentication_session):
448
+ async def on_check_perms(request):
444
449
  return text("Account is authorized.")
445
450
  ```
446
451
 
@@ -458,7 +463,7 @@ async def on_check_roles(request):
458
463
  ```python
459
464
  @app.post("api/security/roles")
460
465
  @require_roles("Chat Room Moderator")
461
- async def on_check_roles(request, authentication_session):
466
+ async def on_check_roles(request):
462
467
  return text("Account is authorized.")
463
468
  ```
464
469
 
@@ -83,6 +83,11 @@ pip3 install sanic-security[crypto]
83
83
  pip3 install -e ".[dev]"
84
84
  ````
85
85
 
86
+ * Update sanic-security if already installed.
87
+ ```shell
88
+ pip3 install --upgrade sanic-security
89
+ ```
90
+
86
91
  ### Configuration
87
92
 
88
93
  Sanic Security configuration is merely an object that can be modified either using dot-notation or like a
@@ -262,10 +267,10 @@ async def on_authenticate(request):
262
267
  ```python
263
268
  @app.post("api/security/auth")
264
269
  @requires_authentication()
265
- async def on_authenticate(request, authentication_session):
270
+ async def on_authenticate(request):
266
271
  return json(
267
272
  "You have been authenticated.",
268
- authentication_session.bearer.json,
273
+ request.ctx.authentication_session.bearer.json,
269
274
  )
270
275
  ```
271
276
 
@@ -315,8 +320,8 @@ async def on_captcha(request):
315
320
  ```python
316
321
  @app.post("ap/security/captcha")
317
322
  @requires_captcha()
318
- async def on_captcha(request, captcha_session):
319
- return json("Captcha attempt successful!", captcha_session.json)
323
+ async def on_captcha(request):
324
+ return json("Captcha attempt successful!", request.ctx.captcha_session.json)
320
325
  ```
321
326
 
322
327
  ## Two-step Verification
@@ -378,9 +383,10 @@ async def on_two_step_verification(request):
378
383
  ```python
379
384
  @app.post("api/security/two-step")
380
385
  @requires_two_step_verification()
381
- async def on_two_step_verification(request, two_step_session):
386
+ async def on_two_step_verification(request):
382
387
  response = json(
383
- "Two-step verification attempt successful!", two_step_session.bearer.json
388
+ "Two-step verification attempt successful!",
389
+ request.ctx.two_step_session.bearer.json,
384
390
  )
385
391
  return response
386
392
  ```
@@ -419,13 +425,12 @@ async def on_check_perms(request):
419
425
  return text("Account is authorized.")
420
426
  ```
421
427
 
422
-
423
428
  * Require Permissions (This method is not called directly and instead used as a decorator.)
424
429
 
425
430
  ```python
426
431
  @app.post("api/security/perms")
427
432
  @require_permissions("channels:view", "voice:*")
428
- async def on_check_perms(request, authentication_session):
433
+ async def on_check_perms(request):
429
434
  return text("Account is authorized.")
430
435
  ```
431
436
 
@@ -443,7 +448,7 @@ async def on_check_roles(request):
443
448
  ```python
444
449
  @app.post("api/security/roles")
445
450
  @require_roles("Chat Room Moderator")
446
- async def on_check_roles(request, authentication_session):
451
+ async def on_check_roles(request):
447
452
  return text("Account is authorized.")
448
453
  ```
449
454
 
@@ -239,7 +239,7 @@ def requires_authentication():
239
239
 
240
240
  @app.post('api/authenticate')
241
241
  @requires_authentication()
242
- async def on_authenticate(request, authentication_session):
242
+ async def on_authenticate(request):
243
243
  return text('User is authenticated!')
244
244
 
245
245
  Raises:
@@ -255,8 +255,8 @@ def requires_authentication():
255
255
  def wrapper(func):
256
256
  @functools.wraps(func)
257
257
  async def wrapped(request, *args, **kwargs):
258
- authentication_session = await authenticate(request)
259
- return await func(request, authentication_session, *args, **kwargs)
258
+ request.ctx.authentication_session = await authenticate(request)
259
+ return await func(request, *args, **kwargs)
260
260
 
261
261
  return wrapped
262
262
 
@@ -107,7 +107,7 @@ def require_permissions(*required_permissions: str):
107
107
 
108
108
  @app.post("api/auth/perms")
109
109
  @require_permissions("admin:update", "employee:add")
110
- async def on_require_perms(request, authentication_session):
110
+ async def on_require_perms(request):
111
111
  return text("Account permitted.")
112
112
 
113
113
  Raises:
@@ -124,10 +124,10 @@ def require_permissions(*required_permissions: str):
124
124
  def wrapper(func):
125
125
  @functools.wraps(func)
126
126
  async def wrapped(request, *args, **kwargs):
127
- authentication_session = await check_permissions(
127
+ request.ctx.authentication_session = await check_permissions(
128
128
  request, *required_permissions
129
129
  )
130
- return await func(request, authentication_session, *args, **kwargs)
130
+ return await func(request, *args, **kwargs)
131
131
 
132
132
  return wrapped
133
133
 
@@ -146,7 +146,7 @@ def require_roles(*required_roles: str):
146
146
 
147
147
  @app.post("api/auth/roles")
148
148
  @require_roles("Admin", "Moderator")
149
- async def on_require_roles(request, authentication_session):
149
+ async def on_require_roles(request):
150
150
  return text("Account permitted")
151
151
 
152
152
  Raises:
@@ -163,8 +163,10 @@ def require_roles(*required_roles: str):
163
163
  def wrapper(func):
164
164
  @functools.wraps(func)
165
165
  async def wrapped(request, *args, **kwargs):
166
- authentication_session = await check_roles(request, *required_roles)
167
- return await func(request, authentication_session, *args, **kwargs)
166
+ request.ctx.authentication_session = await check_roles(
167
+ request, *required_roles
168
+ )
169
+ return await func(request, *args, **kwargs)
168
170
 
169
171
  return wrapped
170
172
 
@@ -1,6 +1,5 @@
1
1
  from argon2 import PasswordHasher
2
2
  from sanic import Sanic, text
3
- from sanic.utils import str_to_bool
4
3
  from tortoise.contrib.sanic import register_tortoise
5
4
 
6
5
  from sanic_security.authentication import (
@@ -132,23 +131,23 @@ async def on_logout(request):
132
131
 
133
132
  @app.post("api/test/auth")
134
133
  @requires_authentication()
135
- async def on_authenticate(request, authentication_session):
134
+ async def on_authenticate(request):
136
135
  """
137
136
  Authenticate client session and account.
138
137
  """
139
- response = json("Authenticated!", authentication_session.bearer.json)
140
- authentication_session.encode(response)
138
+ response = json("Authenticated!", request.ctx.authentication_session.bearer.json)
139
+ request.ctx.authentication_session.encode(response)
141
140
  return response
142
141
 
143
142
 
144
143
  @app.post("api/test/auth/associated")
145
144
  @requires_authentication()
146
- async def on_get_associated_authentication_sessions(request, authentication_session):
145
+ async def on_get_associated_authentication_sessions(request):
147
146
  """
148
147
  Retrieves authentication sessions associated with logged in account.
149
148
  """
150
149
  authentication_sessions = await AuthenticationSession.get_associated(
151
- authentication_session.bearer
150
+ request.ctx.authentication_session.bearer
152
151
  )
153
152
  return json(
154
153
  "Associated authentication sessions retrieved!",
@@ -180,11 +179,11 @@ async def on_captcha_image(request):
180
179
 
181
180
  @app.post("api/test/capt")
182
181
  @requires_captcha()
183
- async def on_captcha_attempt(request, captcha_session):
182
+ async def on_captcha_attempt(request):
184
183
  """
185
184
  Attempt captcha challenge.
186
185
  """
187
- return json("Captcha attempt successful!", captcha_session.json)
186
+ return json("Captcha attempt successful!", request.ctx.captcha_session.json)
188
187
 
189
188
 
190
189
  @app.post("api/test/two-step/request")
@@ -200,16 +199,18 @@ async def on_request_verification(request):
200
199
 
201
200
  @app.post("api/test/two-step")
202
201
  @requires_two_step_verification()
203
- async def on_verification_attempt(request, two_step_session):
202
+ async def on_verification_attempt(request):
204
203
  """
205
204
  Attempt two-step verification challenge.
206
205
  """
207
- return json("Two step verification attempt successful!", two_step_session.json)
206
+ return json(
207
+ "Two step verification attempt successful!", request.ctx.two_step_session.json
208
+ )
208
209
 
209
210
 
210
211
  @app.post("api/test/auth/roles")
211
212
  @requires_authentication()
212
- async def on_authorization(request, authentication_session):
213
+ async def on_authorization(request):
213
214
  """
214
215
  Check if client is authorized with sufficient roles and permissions.
215
216
  """
@@ -223,13 +224,13 @@ async def on_authorization(request, authentication_session):
223
224
 
224
225
  @app.post("api/test/auth/roles/assign")
225
226
  @requires_authentication()
226
- async def on_role_assign(request, authentication_session):
227
+ async def on_role_assign(request):
227
228
  """
228
229
  Assign authenticated account a role.
229
230
  """
230
231
  await assign_role(
231
232
  request.form.get("name"),
232
- authentication_session.bearer,
233
+ request.ctx.authentication_session.bearer,
233
234
  request.form.get("permissions"),
234
235
  "Role used for testing.",
235
236
  )
@@ -99,7 +99,7 @@ def requires_two_step_verification():
99
99
 
100
100
  @app.post("api/verification/attempt")
101
101
  @requires_two_step_verification()
102
- async def on_verified(request, two_step_session):
102
+ async def on_verified(request):
103
103
  response = json("Two-step verification attempt successful!", two_step_session.json())
104
104
  return response
105
105
 
@@ -118,8 +118,8 @@ def requires_two_step_verification():
118
118
  def wrapper(func):
119
119
  @functools.wraps(func)
120
120
  async def wrapped(request, *args, **kwargs):
121
- two_step_session = await two_step_verification(request)
122
- return await func(request, two_step_session, *args, **kwargs)
121
+ request.ctx.two_step_session = await two_step_verification(request)
122
+ return await func(request, *args, **kwargs)
123
123
 
124
124
  return wrapped
125
125
 
@@ -207,7 +207,7 @@ def requires_captcha():
207
207
 
208
208
  @app.post("api/captcha/attempt")
209
209
  @requires_captcha()
210
- async def on_captcha_attempt(request, captcha_session):
210
+ async def on_captcha_attempt(request):
211
211
  return json("Captcha attempt successful!", captcha_session.json())
212
212
 
213
213
  Raises:
@@ -223,8 +223,8 @@ def requires_captcha():
223
223
  def wrapper(func):
224
224
  @functools.wraps(func)
225
225
  async def wrapped(request, *args, **kwargs):
226
- captcha_session = await captcha(request)
227
- return await func(request, captcha_session, *args, **kwargs)
226
+ request.ctx.captcha_session = await captcha(request)
227
+ return await func(request, *args, **kwargs)
228
228
 
229
229
  return wrapped
230
230
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: sanic-security
3
- Version: 1.10.4
3
+ Version: 1.11.0
4
4
  Summary: An effective, simple, and async security library for the Sanic framework.
5
5
  Home-page: https://github.com/na-stewart/sanic-security
6
6
  Author: Aidan Stewart
@@ -98,6 +98,11 @@ pip3 install sanic-security[crypto]
98
98
  pip3 install -e ".[dev]"
99
99
  ````
100
100
 
101
+ * Update sanic-security if already installed.
102
+ ```shell
103
+ pip3 install --upgrade sanic-security
104
+ ```
105
+
101
106
  ### Configuration
102
107
 
103
108
  Sanic Security configuration is merely an object that can be modified either using dot-notation or like a
@@ -277,10 +282,10 @@ async def on_authenticate(request):
277
282
  ```python
278
283
  @app.post("api/security/auth")
279
284
  @requires_authentication()
280
- async def on_authenticate(request, authentication_session):
285
+ async def on_authenticate(request):
281
286
  return json(
282
287
  "You have been authenticated.",
283
- authentication_session.bearer.json,
288
+ request.ctx.authentication_session.bearer.json,
284
289
  )
285
290
  ```
286
291
 
@@ -330,8 +335,8 @@ async def on_captcha(request):
330
335
  ```python
331
336
  @app.post("ap/security/captcha")
332
337
  @requires_captcha()
333
- async def on_captcha(request, captcha_session):
334
- return json("Captcha attempt successful!", captcha_session.json)
338
+ async def on_captcha(request):
339
+ return json("Captcha attempt successful!", request.ctx.captcha_session.json)
335
340
  ```
336
341
 
337
342
  ## Two-step Verification
@@ -393,9 +398,10 @@ async def on_two_step_verification(request):
393
398
  ```python
394
399
  @app.post("api/security/two-step")
395
400
  @requires_two_step_verification()
396
- async def on_two_step_verification(request, two_step_session):
401
+ async def on_two_step_verification(request):
397
402
  response = json(
398
- "Two-step verification attempt successful!", two_step_session.bearer.json
403
+ "Two-step verification attempt successful!",
404
+ request.ctx.two_step_session.bearer.json,
399
405
  )
400
406
  return response
401
407
  ```
@@ -434,13 +440,12 @@ async def on_check_perms(request):
434
440
  return text("Account is authorized.")
435
441
  ```
436
442
 
437
-
438
443
  * Require Permissions (This method is not called directly and instead used as a decorator.)
439
444
 
440
445
  ```python
441
446
  @app.post("api/security/perms")
442
447
  @require_permissions("channels:view", "voice:*")
443
- async def on_check_perms(request, authentication_session):
448
+ async def on_check_perms(request):
444
449
  return text("Account is authorized.")
445
450
  ```
446
451
 
@@ -458,7 +463,7 @@ async def on_check_roles(request):
458
463
  ```python
459
464
  @app.post("api/security/roles")
460
465
  @require_roles("Chat Room Moderator")
461
- async def on_check_roles(request, authentication_session):
466
+ async def on_check_roles(request):
462
467
  return text("Account is authorized.")
463
468
  ```
464
469
 
@@ -13,7 +13,7 @@ setup(
13
13
  long_description=long_description,
14
14
  long_description_content_type="text/markdown",
15
15
  license="GNU Affero General Public License v3.0",
16
- version="1.10.4",
16
+ version="1.11.0",
17
17
  packages=setuptools.find_packages(),
18
18
  python_requires=">=3.6",
19
19
  install_requires=[
File without changes