sanic-security 1.16.8__tar.gz → 1.16.10__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.16.8/sanic_security.egg-info → sanic_security-1.16.10}/PKG-INFO +11 -13
  2. {sanic_security-1.16.8 → sanic_security-1.16.10}/README.md +8 -11
  3. {sanic_security-1.16.8 → sanic_security-1.16.10}/pyproject.toml +1 -1
  4. {sanic_security-1.16.8 → sanic_security-1.16.10}/sanic_security/configuration.py +10 -16
  5. {sanic_security-1.16.8 → sanic_security-1.16.10}/sanic_security/models.py +1 -2
  6. {sanic_security-1.16.8 → sanic_security-1.16.10/sanic_security.egg-info}/PKG-INFO +11 -13
  7. {sanic_security-1.16.8 → sanic_security-1.16.10}/LICENSE +0 -0
  8. {sanic_security-1.16.8 → sanic_security-1.16.10}/sanic_security/__init__.py +0 -0
  9. {sanic_security-1.16.8 → sanic_security-1.16.10}/sanic_security/authentication.py +0 -0
  10. {sanic_security-1.16.8 → sanic_security-1.16.10}/sanic_security/authorization.py +0 -0
  11. {sanic_security-1.16.8 → sanic_security-1.16.10}/sanic_security/exceptions.py +0 -0
  12. {sanic_security-1.16.8 → sanic_security-1.16.10}/sanic_security/oauth.py +0 -0
  13. {sanic_security-1.16.8 → sanic_security-1.16.10}/sanic_security/test/__init__.py +0 -0
  14. {sanic_security-1.16.8 → sanic_security-1.16.10}/sanic_security/test/server.py +0 -0
  15. {sanic_security-1.16.8 → sanic_security-1.16.10}/sanic_security/test/tests.py +0 -0
  16. {sanic_security-1.16.8 → sanic_security-1.16.10}/sanic_security/utils.py +0 -0
  17. {sanic_security-1.16.8 → sanic_security-1.16.10}/sanic_security/verification.py +0 -0
  18. {sanic_security-1.16.8 → sanic_security-1.16.10}/sanic_security.egg-info/SOURCES.txt +0 -0
  19. {sanic_security-1.16.8 → sanic_security-1.16.10}/sanic_security.egg-info/dependency_links.txt +0 -0
  20. {sanic_security-1.16.8 → sanic_security-1.16.10}/sanic_security.egg-info/requires.txt +0 -0
  21. {sanic_security-1.16.8 → sanic_security-1.16.10}/sanic_security.egg-info/top_level.txt +0 -0
  22. {sanic_security-1.16.8 → sanic_security-1.16.10}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.2
1
+ Metadata-Version: 2.4
2
2
  Name: sanic-security
3
- Version: 1.16.8
3
+ Version: 1.16.10
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/
@@ -29,6 +29,7 @@ Requires-Dist: pdoc3; extra == "dev"
29
29
  Requires-Dist: cryptography; extra == "dev"
30
30
  Provides-Extra: crypto
31
31
  Requires-Dist: cryptography>=3.3.1; extra == "crypto"
32
+ Dynamic: license-file
32
33
 
33
34
  [![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
34
35
  [![Downloads](https://static.pepy.tech/badge/sanic-security)](https://pepy.tech/project/sanic-security)
@@ -121,19 +122,16 @@ pip3 install sanic-security --upgrade
121
122
 
122
123
  ### Configuration
123
124
 
124
- Sanic Security configuration is merely an object that can be modified either using dot-notation or like a dictionary.
125
-
125
+ Sanic Security configuration is merely a `SimpleNamespace` that can be modified using dot-notation.
126
126
  For example:
127
127
 
128
128
  ```python
129
129
  from sanic_security.configuration import config as security_config
130
130
 
131
131
  security_config.SECRET = "This is a big secret. Shhhhh"
132
- security_config["CAPTCHA_FONT"] = "resources/captcha-font.ttf"
132
+ security_config.CAPTCHA_FONT = "resources/captcha-font.ttf"
133
133
  ```
134
134
 
135
- You can also use the update() method like on regular dictionaries.
136
-
137
135
  Any environment variables defined with the SANIC_SECURITY_ prefix will be applied to the config. For example, setting
138
136
  SANIC_SECURITY_SECRET will be loaded by the application automatically and fed into the SECRET config variable.
139
137
 
@@ -294,9 +292,7 @@ Verifies the client's account via two-step session code.
294
292
  @app.put("api/security/verify")
295
293
  async def on_verify(request):
296
294
  two_step_session = await verify_account(request)
297
- return json(
298
- "You have verified your account and may login!", two_step_session.bearer.json
299
- )
295
+ return json("You have verified your account and may login!", two_step_session.json)
300
296
  ```
301
297
 
302
298
  * Login (with two-factor authentication)
@@ -318,7 +314,7 @@ async def on_login(request):
318
314
  ) # Custom method for emailing verification code.
319
315
  response = json(
320
316
  "Login successful! Two-factor authentication required.",
321
- authentication_session.bearer.json,
317
+ authentication_session.json,
322
318
  )
323
319
  authentication_session.encode(response)
324
320
  two_step_session.encode(response)
@@ -341,7 +337,7 @@ async def on_two_factor_authentication(request):
341
337
  authentication_session = await fulfill_second_factor(request)
342
338
  response = json(
343
339
  "Authentication session second-factor fulfilled! You are now authenticated.",
344
- authentication_session.bearer.json,
340
+ authentication_session.json,
345
341
  )
346
342
  return response
347
343
  ```
@@ -367,7 +363,9 @@ async def on_anonymous_login(request):
367
363
  @app.post("api/security/logout")
368
364
  async def on_logout(request):
369
365
  authentication_session = await logout(request)
370
- token_info = await oauth_revoke(request, google_oauth) # Remove if not utilizing OAuth
366
+ token_info = await oauth_revoke(
367
+ request, google_oauth
368
+ ) # Remove if not utilizing OAuth
371
369
  response = json(
372
370
  "Logout successful!",
373
371
  {"token_info": token_info, "auth_session": authentication_session.json},
@@ -89,19 +89,16 @@ pip3 install sanic-security --upgrade
89
89
 
90
90
  ### Configuration
91
91
 
92
- Sanic Security configuration is merely an object that can be modified either using dot-notation or like a dictionary.
93
-
92
+ Sanic Security configuration is merely a `SimpleNamespace` that can be modified using dot-notation.
94
93
  For example:
95
94
 
96
95
  ```python
97
96
  from sanic_security.configuration import config as security_config
98
97
 
99
98
  security_config.SECRET = "This is a big secret. Shhhhh"
100
- security_config["CAPTCHA_FONT"] = "resources/captcha-font.ttf"
99
+ security_config.CAPTCHA_FONT = "resources/captcha-font.ttf"
101
100
  ```
102
101
 
103
- You can also use the update() method like on regular dictionaries.
104
-
105
102
  Any environment variables defined with the SANIC_SECURITY_ prefix will be applied to the config. For example, setting
106
103
  SANIC_SECURITY_SECRET will be loaded by the application automatically and fed into the SECRET config variable.
107
104
 
@@ -262,9 +259,7 @@ Verifies the client's account via two-step session code.
262
259
  @app.put("api/security/verify")
263
260
  async def on_verify(request):
264
261
  two_step_session = await verify_account(request)
265
- return json(
266
- "You have verified your account and may login!", two_step_session.bearer.json
267
- )
262
+ return json("You have verified your account and may login!", two_step_session.json)
268
263
  ```
269
264
 
270
265
  * Login (with two-factor authentication)
@@ -286,7 +281,7 @@ async def on_login(request):
286
281
  ) # Custom method for emailing verification code.
287
282
  response = json(
288
283
  "Login successful! Two-factor authentication required.",
289
- authentication_session.bearer.json,
284
+ authentication_session.json,
290
285
  )
291
286
  authentication_session.encode(response)
292
287
  two_step_session.encode(response)
@@ -309,7 +304,7 @@ async def on_two_factor_authentication(request):
309
304
  authentication_session = await fulfill_second_factor(request)
310
305
  response = json(
311
306
  "Authentication session second-factor fulfilled! You are now authenticated.",
312
- authentication_session.bearer.json,
307
+ authentication_session.json,
313
308
  )
314
309
  return response
315
310
  ```
@@ -335,7 +330,9 @@ async def on_anonymous_login(request):
335
330
  @app.post("api/security/logout")
336
331
  async def on_logout(request):
337
332
  authentication_session = await logout(request)
338
- token_info = await oauth_revoke(request, google_oauth) # Remove if not utilizing OAuth
333
+ token_info = await oauth_revoke(
334
+ request, google_oauth
335
+ ) # Remove if not utilizing OAuth
339
336
  response = json(
340
337
  "Logout successful!",
341
338
  {"token_info": token_info, "auth_session": authentication_session.json},
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "sanic-security"
7
- version = "1.16.8"
7
+ version = "1.16.10"
8
8
  requires-python = ">=3.8"
9
9
  dependencies = [
10
10
  "tortoise-orm>=0.17.0",
@@ -1,4 +1,5 @@
1
1
  from os import environ
2
+ from types import SimpleNamespace
2
3
 
3
4
  from sanic.utils import str_to_bool
4
5
 
@@ -50,7 +51,7 @@ DEFAULT_CONFIG = {
50
51
  }
51
52
 
52
53
 
53
- class Config(dict):
54
+ class Config(SimpleNamespace):
54
55
  """
55
56
  Sanic Security configuration.
56
57
 
@@ -102,30 +103,23 @@ class Config(dict):
102
103
  INITIAL_ADMIN_PASSWORD: str
103
104
  TEST_DATABASE_URL: str
104
105
 
105
- def load_environment_variables(self, load_env="SANIC_SECURITY_") -> None:
106
- """
107
- Any environment variables defined with the prefix argument will be applied to the config.
106
+ def __init__(self, default_config: dict = None):
107
+ super().__init__(**(default_config or DEFAULT_CONFIG))
108
+ self.load_environment_variables()
108
109
 
109
- Args:
110
- load_env (str): Prefix being used to apply environment variables into the config.
111
- """
110
+ def load_environment_variables(self, env_prefix: str = "SANIC_SECURITY_"):
112
111
  for key, value in environ.items():
113
- if not key.startswith(load_env):
112
+ if not key.startswith(env_prefix):
114
113
  continue
115
114
 
116
- _, config_key = key.split(load_env, 1)
115
+ _, config_key = key.split(env_prefix, 1)
117
116
 
118
117
  for converter in (int, float, str_to_bool, str):
119
118
  try:
120
- self[config_key] = converter(value)
119
+ setattr(self, config_key, converter(value))
121
120
  break
122
121
  except ValueError:
123
122
  pass
124
123
 
125
- def __init__(self):
126
- super().__init__(DEFAULT_CONFIG)
127
- self.__dict__ = self
128
- self.load_environment_variables()
129
-
130
124
 
131
- config = Config()
125
+ config = Config(DEFAULT_CONFIG)
@@ -369,8 +369,7 @@ class Session(BaseModel):
369
369
  samesite=config.SESSION_SAMESITE,
370
370
  secure=config.SESSION_SECURE,
371
371
  domain=config.SESSION_DOMAIN,
372
- expires=getattr(self, "refresh_expiration_date", None)
373
- or self.expiration_date,
372
+ expires=getattr(self, "refresh_expiration_date", self.expiration_date),
374
373
  )
375
374
 
376
375
  @property
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.2
1
+ Metadata-Version: 2.4
2
2
  Name: sanic-security
3
- Version: 1.16.8
3
+ Version: 1.16.10
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/
@@ -29,6 +29,7 @@ Requires-Dist: pdoc3; extra == "dev"
29
29
  Requires-Dist: cryptography; extra == "dev"
30
30
  Provides-Extra: crypto
31
31
  Requires-Dist: cryptography>=3.3.1; extra == "crypto"
32
+ Dynamic: license-file
32
33
 
33
34
  [![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
34
35
  [![Downloads](https://static.pepy.tech/badge/sanic-security)](https://pepy.tech/project/sanic-security)
@@ -121,19 +122,16 @@ pip3 install sanic-security --upgrade
121
122
 
122
123
  ### Configuration
123
124
 
124
- Sanic Security configuration is merely an object that can be modified either using dot-notation or like a dictionary.
125
-
125
+ Sanic Security configuration is merely a `SimpleNamespace` that can be modified using dot-notation.
126
126
  For example:
127
127
 
128
128
  ```python
129
129
  from sanic_security.configuration import config as security_config
130
130
 
131
131
  security_config.SECRET = "This is a big secret. Shhhhh"
132
- security_config["CAPTCHA_FONT"] = "resources/captcha-font.ttf"
132
+ security_config.CAPTCHA_FONT = "resources/captcha-font.ttf"
133
133
  ```
134
134
 
135
- You can also use the update() method like on regular dictionaries.
136
-
137
135
  Any environment variables defined with the SANIC_SECURITY_ prefix will be applied to the config. For example, setting
138
136
  SANIC_SECURITY_SECRET will be loaded by the application automatically and fed into the SECRET config variable.
139
137
 
@@ -294,9 +292,7 @@ Verifies the client's account via two-step session code.
294
292
  @app.put("api/security/verify")
295
293
  async def on_verify(request):
296
294
  two_step_session = await verify_account(request)
297
- return json(
298
- "You have verified your account and may login!", two_step_session.bearer.json
299
- )
295
+ return json("You have verified your account and may login!", two_step_session.json)
300
296
  ```
301
297
 
302
298
  * Login (with two-factor authentication)
@@ -318,7 +314,7 @@ async def on_login(request):
318
314
  ) # Custom method for emailing verification code.
319
315
  response = json(
320
316
  "Login successful! Two-factor authentication required.",
321
- authentication_session.bearer.json,
317
+ authentication_session.json,
322
318
  )
323
319
  authentication_session.encode(response)
324
320
  two_step_session.encode(response)
@@ -341,7 +337,7 @@ async def on_two_factor_authentication(request):
341
337
  authentication_session = await fulfill_second_factor(request)
342
338
  response = json(
343
339
  "Authentication session second-factor fulfilled! You are now authenticated.",
344
- authentication_session.bearer.json,
340
+ authentication_session.json,
345
341
  )
346
342
  return response
347
343
  ```
@@ -367,7 +363,9 @@ async def on_anonymous_login(request):
367
363
  @app.post("api/security/logout")
368
364
  async def on_logout(request):
369
365
  authentication_session = await logout(request)
370
- token_info = await oauth_revoke(request, google_oauth) # Remove if not utilizing OAuth
366
+ token_info = await oauth_revoke(
367
+ request, google_oauth
368
+ ) # Remove if not utilizing OAuth
371
369
  response = json(
372
370
  "Logout successful!",
373
371
  {"token_info": token_info, "auth_session": authentication_session.json},