sanic-security 1.16.8__py3-none-any.whl → 1.16.10__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.
@@ -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)
sanic_security/models.py CHANGED
@@ -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},
@@ -1,17 +1,17 @@
1
1
  sanic_security/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
2
  sanic_security/authentication.py,sha256=APs_YkwQCAEKyQo76ukKazQLGcm9fYrve6CUNxK2yKU,13201
3
3
  sanic_security/authorization.py,sha256=Hj1TXWppq7KDH-BQXFNihpZTbaimxnVCbif_Zb5W1bA,8232
4
- sanic_security/configuration.py,sha256=2kWC4CZXvWR1wtBaqkMl58IA0VzxhI2ZbBTqd7LS_fE,6305
4
+ sanic_security/configuration.py,sha256=HxlKWe1vrQsxNtpoOx86RuHtkZz7Mjo88hMCMhTDvfo,6162
5
5
  sanic_security/exceptions.py,sha256=b_E6wbbtk9ziFfH3jZstp2E01hTm6V1yjTltANYAuMY,5582
6
- sanic_security/models.py,sha256=B6ZLvLqdn7ZWn1VjOylQN4ecGRfdGbtBrScVJmzIg_o,22097
6
+ sanic_security/models.py,sha256=nA4QqmYEMga4ufVTNggJiIuzZtTOYGOquOSlrKMeVdw,22076
7
7
  sanic_security/oauth.py,sha256=X1fx5KwvtWOa9ABGj7-MZ82ztlVeEuDz55yOh1Vtkes,8405
8
8
  sanic_security/utils.py,sha256=WlPOEEQGcfZk-GbPNu6OiysNXAo9mw80TitDV7XxWMc,3762
9
9
  sanic_security/verification.py,sha256=vr_64HLC7TfOwhki7B4Xn3XQJ0V6OoVgh8fR4DISZ44,8085
10
10
  sanic_security/test/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
11
11
  sanic_security/test/server.py,sha256=bVltV-AB_CEz9xrnVIft88FU6IYPgOOWuoSHDijeTDs,13717
12
12
  sanic_security/test/tests.py,sha256=YXyn9aJmYg7vCjUuAs8FcI_lGIgzhmMe4AYTzu47_18,22618
13
- sanic_security-1.16.8.dist-info/LICENSE,sha256=sXlJs9_mG-dCkPfWsDnuzydJWagS82E2gYtkVH9enHA,1100
14
- sanic_security-1.16.8.dist-info/METADATA,sha256=Ny74Sp3qqXu4piV_7DxNEOzQObdv6rwBOteQ5Epn6GQ,25622
15
- sanic_security-1.16.8.dist-info/WHEEL,sha256=jB7zZ3N9hIM9adW7qlTAyycLYW9npaWKLRzaoVcLKcM,91
16
- sanic_security-1.16.8.dist-info/top_level.txt,sha256=ZybkhHXSjfzhmv8XeqLvnNmLmv21Z0oPX6Ep4DJN8b0,15
17
- sanic_security-1.16.8.dist-info/RECORD,,
13
+ sanic_security-1.16.10.dist-info/licenses/LICENSE,sha256=sXlJs9_mG-dCkPfWsDnuzydJWagS82E2gYtkVH9enHA,1100
14
+ sanic_security-1.16.10.dist-info/METADATA,sha256=_3h-20wix8oJ_Aeyv7IFYJFh7Vjxh8YTkVwnpsOR-gY,25532
15
+ sanic_security-1.16.10.dist-info/WHEEL,sha256=ck4Vq1_RXyvS4Jt6SI0Vz6fyVs4GWg7AINwpsaGEgPE,91
16
+ sanic_security-1.16.10.dist-info/top_level.txt,sha256=ZybkhHXSjfzhmv8XeqLvnNmLmv21Z0oPX6Ep4DJN8b0,15
17
+ sanic_security-1.16.10.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (75.8.2)
2
+ Generator: setuptools (80.0.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5