square-authentication 7.0.0__py3-none-any.whl → 8.0.0__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.
- square_authentication/configuration.py +31 -0
- square_authentication/data/config.sample.ini +11 -1
- square_authentication/data/config.testing.sample.ini +11 -1
- square_authentication/messages.py +2 -0
- square_authentication/pydantic_models/core.py +16 -0
- square_authentication/routes/core.py +964 -31
- square_authentication/routes/profile.py +10 -5
- square_authentication/utils/core.py +37 -0
- {square_authentication-7.0.0.dist-info → square_authentication-8.0.0.dist-info}/METADATA +31 -2
- square_authentication-8.0.0.dist-info/RECORD +21 -0
- square_authentication-7.0.0.dist-info/RECORD +0 -20
- {square_authentication-7.0.0.dist-info → square_authentication-8.0.0.dist-info}/WHEEL +0 -0
- {square_authentication-7.0.0.dist-info → square_authentication-8.0.0.dist-info}/top_level.txt +0 -0
@@ -30,6 +30,8 @@ from square_authentication.configuration import (
|
|
30
30
|
global_object_square_file_store_helper,
|
31
31
|
global_object_square_logger,
|
32
32
|
MAIL_GUN_API_KEY,
|
33
|
+
NUMBER_OF_DIGITS_IN_EMAIL_VERIFICATION_CODE,
|
34
|
+
EXPIRY_TIME_FOR_EMAIL_VERIFICATION_CODE_IN_SECONDS,
|
33
35
|
)
|
34
36
|
from square_authentication.messages import messages
|
35
37
|
from square_authentication.pydantic_models.profile import (
|
@@ -359,14 +361,17 @@ async def send_verification_email_v0(
|
|
359
361
|
"""
|
360
362
|
main process
|
361
363
|
"""
|
362
|
-
|
363
|
-
|
364
|
+
verification_code = random.randint(
|
365
|
+
10 ** (NUMBER_OF_DIGITS_IN_EMAIL_VERIFICATION_CODE - 1),
|
366
|
+
10**NUMBER_OF_DIGITS_IN_EMAIL_VERIFICATION_CODE - 1,
|
367
|
+
)
|
364
368
|
# hash the verification code
|
365
369
|
hashed_verification_code = bcrypt.hashpw(
|
366
370
|
str(verification_code).encode("utf-8"), bcrypt.gensalt()
|
367
371
|
).decode("utf-8")
|
368
|
-
|
369
|
-
|
372
|
+
expires_at = datetime.now(timezone.utc) + timedelta(
|
373
|
+
seconds=EXPIRY_TIME_FOR_EMAIL_VERIFICATION_CODE_IN_SECONDS
|
374
|
+
)
|
370
375
|
# add verification code to UserVerification code table
|
371
376
|
global_object_square_database_helper.insert_rows_v0(
|
372
377
|
database_name=global_string_database_name,
|
@@ -402,7 +407,7 @@ async def send_verification_email_v0(
|
|
402
407
|
to_email=user_profile_data[UserProfile.user_profile_email.name],
|
403
408
|
to_name=user_to_name,
|
404
409
|
subject="Email Verification",
|
405
|
-
body=f"Your verification code is {verification_code}. It will expire in
|
410
|
+
body=f"Your verification code is {verification_code}. It will expire in {EXPIRY_TIME_FOR_EMAIL_VERIFICATION_CODE_IN_SECONDS/60} minutes.",
|
406
411
|
api_key=MAIL_GUN_API_KEY,
|
407
412
|
domain_name="thepmsquare.com",
|
408
413
|
)
|
@@ -0,0 +1,37 @@
|
|
1
|
+
import random
|
2
|
+
import string
|
3
|
+
from typing import Optional
|
4
|
+
|
5
|
+
from square_database_helper import FiltersV0
|
6
|
+
from square_database_helper.pydantic_models import FilterConditionsV0
|
7
|
+
from square_database_structure.square import global_string_database_name
|
8
|
+
from square_database_structure.square.authentication import global_string_schema_name
|
9
|
+
from square_database_structure.square.authentication.tables import User
|
10
|
+
|
11
|
+
from square_authentication.configuration import global_object_square_database_helper
|
12
|
+
|
13
|
+
|
14
|
+
def generate_default_username_for_google_users(given_name: Optional[str], family_name: Optional[str]) -> str:
|
15
|
+
|
16
|
+
given = given_name.lower() if given_name else "user"
|
17
|
+
family = family_name.lower() if family_name else "user"
|
18
|
+
|
19
|
+
# sanitize (keep a-z, 0-9, _, -)
|
20
|
+
allowed_chars = set(string.ascii_lowercase + string.digits + "_-")
|
21
|
+
given = "".join(c for c in given if c in allowed_chars)
|
22
|
+
family = "".join(c for c in family if c in allowed_chars)
|
23
|
+
|
24
|
+
while True:
|
25
|
+
random_suffix = ''.join(random.choices(string.ascii_lowercase + string.digits, k=6))
|
26
|
+
username_candidate = f"{given}_{family}_{random_suffix}"
|
27
|
+
|
28
|
+
# check uniqueness
|
29
|
+
existing = global_object_square_database_helper.get_rows_v0(
|
30
|
+
database_name=global_string_database_name,
|
31
|
+
schema_name=global_string_schema_name,
|
32
|
+
table_name=User.__tablename__,
|
33
|
+
filters=FiltersV0(root={User.user_username.name: FilterConditionsV0(eq=username_candidate)}),
|
34
|
+
)["data"]["main"]
|
35
|
+
|
36
|
+
if not existing:
|
37
|
+
return username_candidate
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: square_authentication
|
3
|
-
Version:
|
3
|
+
Version: 8.0.0
|
4
4
|
Summary: authentication layer for my personal server.
|
5
5
|
Home-page: https://github.com/thepmsquare/square_authentication
|
6
6
|
Author: thePmSquare
|
@@ -19,13 +19,14 @@ Requires-Dist: bcrypt>=4.1.2
|
|
19
19
|
Requires-Dist: pyjwt>=2.8.0
|
20
20
|
Requires-Dist: requests>=2.32.3
|
21
21
|
Requires-Dist: cryptography>=42.0.7
|
22
|
-
Requires-Dist: square_commons>=
|
22
|
+
Requires-Dist: square_commons>=3.0.0
|
23
23
|
Requires-Dist: square_logger>=2.0.0
|
24
24
|
Requires-Dist: square_database_helper>=2.0.0
|
25
25
|
Requires-Dist: square_database_structure>=2.3.1
|
26
26
|
Requires-Dist: square_file_store_helper>=3.0.0
|
27
27
|
Requires-Dist: pytest>=8.0.0
|
28
28
|
Requires-Dist: httpx>=0.27.2
|
29
|
+
Requires-Dist: google-auth>=2.40.3
|
29
30
|
Dynamic: author
|
30
31
|
Dynamic: author-email
|
31
32
|
Dynamic: classifier
|
@@ -53,6 +54,34 @@ pip install square_authentication
|
|
53
54
|
|
54
55
|
## changelog
|
55
56
|
|
57
|
+
### v8.0.0
|
58
|
+
|
59
|
+
- env
|
60
|
+
- add GOOGLE section and GOOGLE_AUTH_PLATFORM_CLIENT_ID variable.
|
61
|
+
- add LOGIC section with NUMBER_OF_RECOVERY_CODES, EXPIRY_TIME_FOR_EMAIL_VERIFICATION_CODE_IN_SECONDS,
|
62
|
+
NUMBER_OF_DIGITS_IN_EMAIL_VERIFICATION_CODE, EXPIRY_TIME_FOR_EMAIL_PASSWORD_RESET_CODE_IN_SECONDS,
|
63
|
+
NUMBER_OF_DIGITS_IN_EMAIL_PASSWORD_RESET_CODE variables.
|
64
|
+
- dependencies
|
65
|
+
- add google-auth>=2.40.3.
|
66
|
+
- update square_commons to >=3.0.0.
|
67
|
+
- core
|
68
|
+
- add reset_password_and_login_using_reset_email_code_v0.
|
69
|
+
- **breaking change**: remove app_id from send_reset_password_email_v0.
|
70
|
+
- implement deletion of existing backup codes before generating new ones (generate_account_backup_codes_v0).
|
71
|
+
- implement deletion of existing backup codes before removing recovery method (update_user_recovery_methods_v0).
|
72
|
+
- implement logout_other_sessions in update_password_v0, reset_password_and_login_using_backup_code_v0 and
|
73
|
+
reset_password_and_login_using_reset_email_code_v0
|
74
|
+
- in update_password_v0, it will log out all other sessions except the current one if valid (optional)
|
75
|
+
refresh_token is passed in.
|
76
|
+
- add register_login_google_v0, **finally**.
|
77
|
+
- add validation in update_password_v0, reset_password_and_login_using_backup_code_v0, send_reset_password_email_v0,
|
78
|
+
reset_password_and_login_using_reset_email_code_v0 to check if user has credentials and has self as auth provider.
|
79
|
+
- remove profile_photo from file_store when user is deleted in delete_user_v0.
|
80
|
+
- utils
|
81
|
+
- add new core file with generate_default_username_for_google_users function.
|
82
|
+
- tests
|
83
|
+
- add test_login_fail_v0.
|
84
|
+
|
56
85
|
### v7.0.0
|
57
86
|
|
58
87
|
- internal support for UserAuthProvider.
|
@@ -0,0 +1,21 @@
|
|
1
|
+
square_authentication/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
2
|
+
square_authentication/configuration.py,sha256=6M_5Ua7HQblPdBDeywSyelkvhkrsaTmbqWyMKpVV5HU,6045
|
3
|
+
square_authentication/main.py,sha256=nhkv8U4E9b7VIH7Aaj8iMWIwA4VIL-vzRXjZaYEFWPw,1755
|
4
|
+
square_authentication/messages.py,sha256=yDyr3SpBKg5KHb7dUDIUnpuz21EEAg3dnoaLnvX0IcU,2812
|
5
|
+
square_authentication/data/config.sample.ini,sha256=3vn0s5USfksmjVERgk2fIF97Tvzrsjm8xNAOqt5zZoE,1523
|
6
|
+
square_authentication/data/config.testing.sample.ini,sha256=uXUq3Isz2x5fpRcRoQqY-U2t7ZIGgo5c5zoWBgJ8scI,1570
|
7
|
+
square_authentication/pydantic_models/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
8
|
+
square_authentication/pydantic_models/core.py,sha256=7H1N1y8VpPA_-NrudX8j0YG_YzpHnPXZuwtGaKRPSy0,1268
|
9
|
+
square_authentication/pydantic_models/profile.py,sha256=tq7RJMfbMBMi7FaRQksWJR3Iucr2l8P2ziKgQvV4owg,110
|
10
|
+
square_authentication/routes/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
11
|
+
square_authentication/routes/core.py,sha256=zGvG8cqwkZVUyxqPC7aT8g3IdIH7BKMnVqPEjwTY5ZU,131694
|
12
|
+
square_authentication/routes/profile.py,sha256=4J-_ulVW0bDkoDO1utdzv_2_OraGbtVnQmcpws3Ecu4,24466
|
13
|
+
square_authentication/routes/utility.py,sha256=KDr8KdkT0jAGPjfP-b5XXYG7p49WU7J1FiK6oSIckQI,1779
|
14
|
+
square_authentication/utils/__init__.py,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
|
15
|
+
square_authentication/utils/core.py,sha256=2jMPnbbURNIMiajYfWIlGNblI7DocWNPZcU_psAq4SE,1567
|
16
|
+
square_authentication/utils/encryption.py,sha256=WakaiEAgWpTJltxBzqOtv81_DCDKfzJqt60fWSPoNvo,2027
|
17
|
+
square_authentication/utils/token.py,sha256=t-RPBY4cYyT1ro3lkLBTOy2BeRGBfluBVBivL5DLmDg,680
|
18
|
+
square_authentication-8.0.0.dist-info/METADATA,sha256=WtZMjlnbh0o3HmTabQoQrFh_dC--5lfLmrjXzQbVYOo,8407
|
19
|
+
square_authentication-8.0.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
20
|
+
square_authentication-8.0.0.dist-info/top_level.txt,sha256=wDssVJIl9KIEJPj5rR3rv4uRI7yCndMBrvHd_6BGXQA,22
|
21
|
+
square_authentication-8.0.0.dist-info/RECORD,,
|
@@ -1,20 +0,0 @@
|
|
1
|
-
square_authentication/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
2
|
-
square_authentication/configuration.py,sha256=_6T9bGdQnoBMJvVOKU_AH6bL7g057GiP-bgsqFsbv-k,4934
|
3
|
-
square_authentication/main.py,sha256=nhkv8U4E9b7VIH7Aaj8iMWIwA4VIL-vzRXjZaYEFWPw,1755
|
4
|
-
square_authentication/messages.py,sha256=H0BS84UaE7OZkufpaf0mwSX3FzXQzmGx-TrrrJmm818,2649
|
5
|
-
square_authentication/data/config.sample.ini,sha256=bkQ71kpnBpw15yxW2mAinLaVU7QUoEWCNop6hqSUGzw,1204
|
6
|
-
square_authentication/data/config.testing.sample.ini,sha256=n0lNWLY7g7iIXtnzbm2BFSAeN8i-dYtNH1zdFlhUirU,1251
|
7
|
-
square_authentication/pydantic_models/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
8
|
-
square_authentication/pydantic_models/core.py,sha256=sy28oW71ptteX_2fuXPtCmAfSHcxE5MRYKPB_f4b7_I,825
|
9
|
-
square_authentication/pydantic_models/profile.py,sha256=tq7RJMfbMBMi7FaRQksWJR3Iucr2l8P2ziKgQvV4owg,110
|
10
|
-
square_authentication/routes/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
11
|
-
square_authentication/routes/core.py,sha256=wlXIjcqjPFzNhrDjzUssr64bUz4UyshWRj5f_4deTuA,90422
|
12
|
-
square_authentication/routes/profile.py,sha256=VhdGAg5VXxbQQSvfecx3cu3gFkfTrSXPrQq-4piXWus,24208
|
13
|
-
square_authentication/routes/utility.py,sha256=KDr8KdkT0jAGPjfP-b5XXYG7p49WU7J1FiK6oSIckQI,1779
|
14
|
-
square_authentication/utils/__init__.py,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
|
15
|
-
square_authentication/utils/encryption.py,sha256=WakaiEAgWpTJltxBzqOtv81_DCDKfzJqt60fWSPoNvo,2027
|
16
|
-
square_authentication/utils/token.py,sha256=t-RPBY4cYyT1ro3lkLBTOy2BeRGBfluBVBivL5DLmDg,680
|
17
|
-
square_authentication-7.0.0.dist-info/METADATA,sha256=gy62vYZfS7k_NeBx6K9xL8YKINcLbQqRa77nYPR8m60,6728
|
18
|
-
square_authentication-7.0.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
19
|
-
square_authentication-7.0.0.dist-info/top_level.txt,sha256=wDssVJIl9KIEJPj5rR3rv4uRI7yCndMBrvHd_6BGXQA,22
|
20
|
-
square_authentication-7.0.0.dist-info/RECORD,,
|
File without changes
|
{square_authentication-7.0.0.dist-info → square_authentication-8.0.0.dist-info}/top_level.txt
RENAMED
File without changes
|