sanic-security 1.15.0__py3-none-any.whl → 1.15.1__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.
- sanic_security/models.py +12 -6
- sanic_security/utils.py +7 -14
- {sanic_security-1.15.0.dist-info → sanic_security-1.15.1.dist-info}/METADATA +1 -1
- {sanic_security-1.15.0.dist-info → sanic_security-1.15.1.dist-info}/RECORD +7 -7
- {sanic_security-1.15.0.dist-info → sanic_security-1.15.1.dist-info}/LICENSE +0 -0
- {sanic_security-1.15.0.dist-info → sanic_security-1.15.1.dist-info}/WHEEL +0 -0
- {sanic_security-1.15.0.dist-info → sanic_security-1.15.1.dist-info}/top_level.txt +0 -0
sanic_security/models.py
CHANGED
@@ -2,6 +2,7 @@ import base64
|
|
2
2
|
import datetime
|
3
3
|
import logging
|
4
4
|
import re
|
5
|
+
import uuid
|
5
6
|
from typing import Union
|
6
7
|
|
7
8
|
import jwt
|
@@ -20,7 +21,6 @@ from sanic_security.utils import (
|
|
20
21
|
get_expiration_date,
|
21
22
|
image_generator,
|
22
23
|
audio_generator,
|
23
|
-
get_id,
|
24
24
|
is_expired,
|
25
25
|
)
|
26
26
|
|
@@ -58,7 +58,9 @@ class BaseModel(Model):
|
|
58
58
|
deleted (bool): Renders the model filterable without removing from the database.
|
59
59
|
"""
|
60
60
|
|
61
|
-
id: str = fields.CharField(
|
61
|
+
id: str = fields.CharField(
|
62
|
+
pk=True, max_length=36, default=lambda: str(uuid.uuid4())
|
63
|
+
)
|
62
64
|
date_created: datetime.datetime = fields.DatetimeField(auto_now_add=True)
|
63
65
|
date_updated: datetime.datetime = fields.DatetimeField(auto_now=True)
|
64
66
|
deleted: bool = fields.BooleanField(default=False)
|
@@ -540,9 +542,13 @@ class VerificationSession(Session):
|
|
540
542
|
class TwoStepSession(VerificationSession):
|
541
543
|
"""Validates a client using a code sent via email or text."""
|
542
544
|
|
545
|
+
code: str = fields.CharField(
|
546
|
+
max_length=6, default=lambda: get_code(True), null=True
|
547
|
+
)
|
548
|
+
|
543
549
|
@classmethod
|
544
550
|
async def new(cls, request: Request, account: Account, **kwargs):
|
545
|
-
return await
|
551
|
+
return await cls.create(
|
546
552
|
**kwargs,
|
547
553
|
ip=get_ip(request),
|
548
554
|
bearer=account,
|
@@ -560,7 +566,7 @@ class CaptchaSession(VerificationSession):
|
|
560
566
|
|
561
567
|
@classmethod
|
562
568
|
async def new(cls, request: Request, **kwargs):
|
563
|
-
return await
|
569
|
+
return await cls.create(
|
564
570
|
**kwargs,
|
565
571
|
ip=get_ip(request),
|
566
572
|
expiration_date=get_expiration_date(
|
@@ -639,7 +645,7 @@ class AuthenticationSession(Session):
|
|
639
645
|
if not is_expired(self.refresh_expiration_date):
|
640
646
|
self.active = False
|
641
647
|
await self.save(update_fields=["active"])
|
642
|
-
logging.
|
648
|
+
logging.info(
|
643
649
|
f"Client {get_ip(request)} has refreshed authentication session {self.id}."
|
644
650
|
)
|
645
651
|
return await self.new(request, self.bearer, True)
|
@@ -650,7 +656,7 @@ class AuthenticationSession(Session):
|
|
650
656
|
async def new(
|
651
657
|
cls, request: Request, account: Account = None, is_refresh=False, **kwargs
|
652
658
|
):
|
653
|
-
authentication_session = await
|
659
|
+
authentication_session = await cls.create(
|
654
660
|
**kwargs,
|
655
661
|
bearer=account,
|
656
662
|
ip=get_ip(request),
|
sanic_security/utils.py
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
import datetime
|
2
2
|
import random
|
3
|
-
import
|
4
|
-
import uuid
|
3
|
+
from string import ascii_uppercase, digits
|
5
4
|
|
6
5
|
from argon2 import PasswordHasher
|
7
6
|
from captcha.audio import AudioCaptcha
|
@@ -53,28 +52,22 @@ def get_ip(request: Request) -> str:
|
|
53
52
|
return request.remote_addr or request.ip
|
54
53
|
|
55
54
|
|
56
|
-
def get_code() -> str:
|
55
|
+
def get_code(digits_only: bool = False) -> str:
|
57
56
|
"""
|
58
57
|
Generates random code to be used for verification.
|
59
58
|
|
59
|
+
Args:
|
60
|
+
digits_only: Determines if code should only contain digits.
|
61
|
+
|
60
62
|
Returns:
|
61
63
|
code
|
62
64
|
"""
|
63
65
|
return "".join(
|
64
|
-
random.choice(
|
66
|
+
random.choice(("" if digits_only else ascii_uppercase) + digits)
|
67
|
+
for _ in range(6)
|
65
68
|
)
|
66
69
|
|
67
70
|
|
68
|
-
def get_id() -> str:
|
69
|
-
"""
|
70
|
-
Generates uuid to be used for primary key.
|
71
|
-
|
72
|
-
Returns:
|
73
|
-
id
|
74
|
-
"""
|
75
|
-
return str(uuid.uuid4())
|
76
|
-
|
77
|
-
|
78
71
|
def is_expired(date):
|
79
72
|
"""
|
80
73
|
Checks if current date has surpassed the date passed into the function.
|
@@ -3,14 +3,14 @@ sanic_security/authentication.py,sha256=3Pit1B4PN_MRvwAlhYPHl_6DGD9JVpdPjgjiyKQJ
|
|
3
3
|
sanic_security/authorization.py,sha256=jAxfDT9cHN_zpMKcA3oYFZ5Eu2KItnMJZ7oPcqmMwrw,7537
|
4
4
|
sanic_security/configuration.py,sha256=_E66ts5g9t_XHW9ZAnr48rWVcZmGNu_DWGDxm_AVVWE,5681
|
5
5
|
sanic_security/exceptions.py,sha256=9zISLyAvP6qN8sNR8e5qxKP__FA4NLIXCun_fEKndOw,5297
|
6
|
-
sanic_security/models.py,sha256=
|
7
|
-
sanic_security/utils.py,sha256=
|
6
|
+
sanic_security/models.py,sha256=TytuQTjfKslPr893-mCYSzsRK7gfJtXmDz656iCCM0k,22530
|
7
|
+
sanic_security/utils.py,sha256=Il5MjFzVe975yx_CV2HV_LVQYl2W3XYDRGtCG5CQA8Q,3531
|
8
8
|
sanic_security/verification.py,sha256=9bi8-NZ8GE3rcuELZ63yh18zDg8RxvxGPkhAu5SzLn0,8692
|
9
9
|
sanic_security/test/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
10
10
|
sanic_security/test/server.py,sha256=RjL9Kfvkfqpm5TXWwFQKKa0J4hfTKgwI6U0s_TAKO8w,11984
|
11
11
|
sanic_security/test/tests.py,sha256=bW5fHJfsCrg8eBmcSqVMLm0R5XRL1ou-XJJRgz09GOE,21993
|
12
|
-
sanic_security-1.15.
|
13
|
-
sanic_security-1.15.
|
14
|
-
sanic_security-1.15.
|
15
|
-
sanic_security-1.15.
|
16
|
-
sanic_security-1.15.
|
12
|
+
sanic_security-1.15.1.dist-info/LICENSE,sha256=sXlJs9_mG-dCkPfWsDnuzydJWagS82E2gYtkVH9enHA,1100
|
13
|
+
sanic_security-1.15.1.dist-info/METADATA,sha256=EINxdSgG_LLkPu3QqXo1CMe_-GTQk5QDhO3b3909quI,23247
|
14
|
+
sanic_security-1.15.1.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
|
15
|
+
sanic_security-1.15.1.dist-info/top_level.txt,sha256=ZybkhHXSjfzhmv8XeqLvnNmLmv21Z0oPX6Ep4DJN8b0,15
|
16
|
+
sanic_security-1.15.1.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|