sandloom-identity 0.7.0a1__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.
- sandloom_identity-0.7.0a1/.gitignore +4 -0
- sandloom_identity-0.7.0a1/CHANGELOG.md +39 -0
- sandloom_identity-0.7.0a1/LICENSE +202 -0
- sandloom_identity-0.7.0a1/NOTICE +8 -0
- sandloom_identity-0.7.0a1/PKG-INFO +59 -0
- sandloom_identity-0.7.0a1/README.md +35 -0
- sandloom_identity-0.7.0a1/pyproject.toml +43 -0
- sandloom_identity-0.7.0a1/sandloom_identity/README.md +213 -0
- sandloom_identity-0.7.0a1/sandloom_identity/__init__.py +102 -0
- sandloom_identity-0.7.0a1/sandloom_identity/access/__init__.py +264 -0
- sandloom_identity-0.7.0a1/sandloom_identity/admin.py +151 -0
- sandloom_identity-0.7.0a1/sandloom_identity/api/__init__.py +22 -0
- sandloom_identity-0.7.0a1/sandloom_identity/api/auth.py +285 -0
- sandloom_identity-0.7.0a1/sandloom_identity/api/roles.py +176 -0
- sandloom_identity-0.7.0a1/sandloom_identity/api/sso.py +227 -0
- sandloom_identity-0.7.0a1/sandloom_identity/api/twofa.py +159 -0
- sandloom_identity-0.7.0a1/sandloom_identity/api/user_roles.py +59 -0
- sandloom_identity-0.7.0a1/sandloom_identity/api/user_safety.py +169 -0
- sandloom_identity-0.7.0a1/sandloom_identity/api/users.py +158 -0
- sandloom_identity-0.7.0a1/sandloom_identity/claims.py +82 -0
- sandloom_identity-0.7.0a1/sandloom_identity/consumers.py +39 -0
- sandloom_identity-0.7.0a1/sandloom_identity/contracts.py +193 -0
- sandloom_identity-0.7.0a1/sandloom_identity/contracts.snapshot.json +310 -0
- sandloom_identity-0.7.0a1/sandloom_identity/errors.py +59 -0
- sandloom_identity-0.7.0a1/sandloom_identity/events.py +380 -0
- sandloom_identity-0.7.0a1/sandloom_identity/integrations.py +719 -0
- sandloom_identity-0.7.0a1/sandloom_identity/lockout.py +225 -0
- sandloom_identity-0.7.0a1/sandloom_identity/migrations/env.py +23 -0
- sandloom_identity-0.7.0a1/sandloom_identity/migrations/script.py.mako +28 -0
- sandloom_identity-0.7.0a1/sandloom_identity/migrations/versions/.gitkeep +0 -0
- sandloom_identity-0.7.0a1/sandloom_identity/migrations/versions/0001_identity_identity_tables.py +193 -0
- sandloom_identity-0.7.0a1/sandloom_identity/migrations/versions/0002_identity_security_hardening.py +53 -0
- sandloom_identity-0.7.0a1/sandloom_identity/migrations/versions/0003_identity_drop_is_revoked_index.py +31 -0
- sandloom_identity-0.7.0a1/sandloom_identity/migrations/versions/0004_identity_refresh_token_auth_time.py +33 -0
- sandloom_identity-0.7.0a1/sandloom_identity/migrations/versions/0005_identity_twofa_backup_codes_user_id_index.py +36 -0
- sandloom_identity-0.7.0a1/sandloom_identity/migrations/versions/0006_identity_users_search_trgm.py +44 -0
- sandloom_identity-0.7.0a1/sandloom_identity/migrations/versions/0007_identity_drop_redundant_indexes.py +50 -0
- sandloom_identity-0.7.0a1/sandloom_identity/migrations/versions/0008_identity_password_reset_required.py +39 -0
- sandloom_identity-0.7.0a1/sandloom_identity/migrations/versions/0009_identity_timestamps_default_to_clock_timestamp.py +48 -0
- sandloom_identity-0.7.0a1/sandloom_identity/models/__init__.py +24 -0
- sandloom_identity-0.7.0a1/sandloom_identity/models/external_identity.py +50 -0
- sandloom_identity-0.7.0a1/sandloom_identity/models/permission.py +40 -0
- sandloom_identity-0.7.0a1/sandloom_identity/models/refresh_token.py +64 -0
- sandloom_identity-0.7.0a1/sandloom_identity/models/role.py +52 -0
- sandloom_identity-0.7.0a1/sandloom_identity/models/role_permission.py +47 -0
- sandloom_identity-0.7.0a1/sandloom_identity/models/twofa_backup_code.py +39 -0
- sandloom_identity-0.7.0a1/sandloom_identity/models/twofa_secret.py +42 -0
- sandloom_identity-0.7.0a1/sandloom_identity/models/user.py +102 -0
- sandloom_identity-0.7.0a1/sandloom_identity/models/user_role.py +48 -0
- sandloom_identity-0.7.0a1/sandloom_identity/module.snapshot.json +1342 -0
- sandloom_identity-0.7.0a1/sandloom_identity/password_policy.py +84 -0
- sandloom_identity-0.7.0a1/sandloom_identity/providers.py +15 -0
- sandloom_identity-0.7.0a1/sandloom_identity/rate_limit.py +0 -0
- sandloom_identity-0.7.0a1/sandloom_identity/routes.snapshot.json +644 -0
- sandloom_identity-0.7.0a1/sandloom_identity/schemas/__init__.py +86 -0
- sandloom_identity-0.7.0a1/sandloom_identity/schemas/auth.py +119 -0
- sandloom_identity-0.7.0a1/sandloom_identity/schemas/contact.py +32 -0
- sandloom_identity-0.7.0a1/sandloom_identity/schemas/rbac.py +112 -0
- sandloom_identity-0.7.0a1/sandloom_identity/schemas/safety.py +18 -0
- sandloom_identity-0.7.0a1/sandloom_identity/schemas/sso.py +71 -0
- sandloom_identity-0.7.0a1/sandloom_identity/schemas/twofa.py +105 -0
- sandloom_identity-0.7.0a1/sandloom_identity/schemas/user.py +90 -0
- sandloom_identity-0.7.0a1/sandloom_identity/services/__init__.py +16 -0
- sandloom_identity-0.7.0a1/sandloom_identity/services/auth_service.py +844 -0
- sandloom_identity-0.7.0a1/sandloom_identity/services/operations.py +23 -0
- sandloom_identity-0.7.0a1/sandloom_identity/services/reauth.py +69 -0
- sandloom_identity-0.7.0a1/sandloom_identity/services/role_service.py +549 -0
- sandloom_identity-0.7.0a1/sandloom_identity/services/sso_service.py +787 -0
- sandloom_identity-0.7.0a1/sandloom_identity/services/token_service.py +443 -0
- sandloom_identity-0.7.0a1/sandloom_identity/services/twofa_service.py +573 -0
- sandloom_identity-0.7.0a1/sandloom_identity/services/user_service.py +270 -0
- sandloom_identity-0.7.0a1/sandloom_identity/sessions.py +109 -0
- sandloom_identity-0.7.0a1/sandloom_identity/tasks.py +121 -0
- sandloom_identity-0.7.0a1/sandloom_identity/utils.py +345 -0
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# Changelog — sandloom-identity
|
|
2
|
+
|
|
3
|
+
All notable changes to the `sandloom-identity` distribution are documented here.
|
|
4
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
5
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
6
|
+
Per-package entries are aggregated in the repository-level [docs/changelog.md](../../docs/changelog.md).
|
|
7
|
+
|
|
8
|
+
## [Unreleased]
|
|
9
|
+
|
|
10
|
+
## [0.7.0a1] — 2026-10-28
|
|
11
|
+
|
|
12
|
+
Initial public alpha preparation; earlier version headings describe internal development.
|
|
13
|
+
|
|
14
|
+
- Breaking (packaging): an ecosystem module distribution. The import package
|
|
15
|
+
is `sandloom_identity` (formerly `sandloom.identity`); it registers the
|
|
16
|
+
`sandloom.modules` entry point `identity = "sandloom_identity"` and depends on
|
|
17
|
+
`sandloom>=0.7,<0.8` instead of `sandloom-framework` + `sandloom-shared`.
|
|
18
|
+
Its contract DTOs, stubs and event schemas stay in `sandloom.shared`
|
|
19
|
+
(shipped with `sandloom`, SANDLOOM-C012).
|
|
20
|
+
`itsdangerous` and `email-validator` are now its own dependencies.
|
|
21
|
+
- Preserve database/security infrastructure errors in authentication instead of
|
|
22
|
+
converting them to invalid tokens or anonymous optional users.
|
|
23
|
+
|
|
24
|
+
## [0.7.0] — 2026-10-13
|
|
25
|
+
|
|
26
|
+
First prepared release version; public publication is pending. While the framework is `0.x`, every Sandloom
|
|
27
|
+
distribution is released in lockstep with the framework release line
|
|
28
|
+
(see [Versioning & Stability](../../docs/contributing/versioning.md));
|
|
29
|
+
the change list since 0.6.0 is in [CHANGELOG.md](../../CHANGELOG.md)
|
|
30
|
+
and the current source API upgrade steps are in
|
|
31
|
+
[Upgrading to Public API 1.0](../../docs/guides/upgrading-1.0.md).
|
|
32
|
+
The historical 0.7 migration guide remains in the preparation archive.
|
|
33
|
+
|
|
34
|
+
### Fixed
|
|
35
|
+
- Source distributions include the package sources and build independently of the monorepo.
|
|
36
|
+
|
|
37
|
+
### Added
|
|
38
|
+
- Identity module: users, JWT authentication, RBAC, 2FA and SSO, shipped as a
|
|
39
|
+
standalone wheel over `sandloom-framework` + `sandloom-shared`.
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
Sandloom
|
|
2
|
+
Copyright 2026 Vasyl Cherniavskyi
|
|
3
|
+
|
|
4
|
+
The original Sandloom framework code, documentation and examples are licensed
|
|
5
|
+
under the Apache License, Version 2.0. See LICENSE for the full terms.
|
|
6
|
+
|
|
7
|
+
Third-party components and assets retain their own copyright notices and
|
|
8
|
+
licenses. This notice does not replace or modify those terms.
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: sandloom-identity
|
|
3
|
+
Version: 0.7.0a1
|
|
4
|
+
Summary: Sandloom identity module: users, JWT auth, RBAC, 2FA, SSO.
|
|
5
|
+
Project-URL: Homepage, https://sandloom.dev/
|
|
6
|
+
Project-URL: Documentation, https://sandloom.dev/docs/
|
|
7
|
+
Project-URL: Repository, https://github.com/Sandloom-dev/sandloom
|
|
8
|
+
Project-URL: Issues, https://github.com/Sandloom-dev/sandloom/issues
|
|
9
|
+
Project-URL: Changelog, https://github.com/Sandloom-dev/sandloom/blob/main/packages/sandloom-identity/CHANGELOG.md
|
|
10
|
+
Author: Vasyl Cherniavskyi
|
|
11
|
+
License-Expression: Apache-2.0
|
|
12
|
+
License-File: LICENSE
|
|
13
|
+
License-File: NOTICE
|
|
14
|
+
Classifier: Development Status :: 3 - Alpha
|
|
15
|
+
Requires-Python: >=3.11
|
|
16
|
+
Requires-Dist: authlib<2,>=1.8.0
|
|
17
|
+
Requires-Dist: email-validator<3,>=2.3.0
|
|
18
|
+
Requires-Dist: itsdangerous<3,>=2.2.0
|
|
19
|
+
Requires-Dist: pillow<14,>=13.0.0
|
|
20
|
+
Requires-Dist: pyotp<3,>=2.10.0
|
|
21
|
+
Requires-Dist: qrcode<9,>=8.2
|
|
22
|
+
Requires-Dist: sandloom<0.8,>=0.7.0a1
|
|
23
|
+
Description-Content-Type: text/markdown
|
|
24
|
+
|
|
25
|
+
# sandloom-identity
|
|
26
|
+
|
|
27
|
+
The Sandloom identity module: users, JWT authentication, RBAC, two-factor auth
|
|
28
|
+
and SSO. Import package `sandloom_identity`; it registers the
|
|
29
|
+
`sandloom.modules` entry point `identity = "sandloom_identity"`, so its module
|
|
30
|
+
name is `identity` (tables `identity_*`, migration chain
|
|
31
|
+
`alembic_version_identity`, channels and contracts `identity.*`). Depends on
|
|
32
|
+
`sandloom>=0.7.0a1,<0.8`, pyotp, authlib, qrcode, pillow, itsdangerous and
|
|
33
|
+
email-validator; on no other module.
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
pip install "sandloom[redis,celery]==0.7.0a1" sandloom-identity==0.7.0a1
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
`sandloom.main:app` composes it once installed; an app selects it with
|
|
40
|
+
`SANDLOOM_MODULES=identity` (or `sandloom new <app> --with identity`). Other
|
|
41
|
+
modules call it through its contracts; their DTOs, stubs and event schemas
|
|
42
|
+
live in `sandloom.shared` and ship with `sandloom`.
|
|
43
|
+
|
|
44
|
+
Source of truth lives in the monorepo at `src/sandloom_identity`; this package
|
|
45
|
+
builds the wheel and source archive.
|
|
46
|
+
|
|
47
|
+
## Project links
|
|
48
|
+
|
|
49
|
+
[Source](https://github.com/Sandloom-dev/sandloom) ·
|
|
50
|
+
[Documentation](https://sandloom.dev/docs/) ·
|
|
51
|
+
[Changelog](https://github.com/Sandloom-dev/sandloom/blob/main/packages/sandloom-identity/CHANGELOG.md)
|
|
52
|
+
|
|
53
|
+
This is the initial `0.7.0a1` alpha distribution. The canonical source
|
|
54
|
+
repository is private and awaiting transfer; the documentation website is
|
|
55
|
+
not deployed yet. The project links above are the planned public locations.
|
|
56
|
+
|
|
57
|
+
## License
|
|
58
|
+
|
|
59
|
+
Apache-2.0. Copyright 2026 Vasyl Cherniavskyi. See [LICENSE](LICENSE) and [NOTICE](NOTICE).
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# sandloom-identity
|
|
2
|
+
|
|
3
|
+
The Sandloom identity module: users, JWT authentication, RBAC, two-factor auth
|
|
4
|
+
and SSO. Import package `sandloom_identity`; it registers the
|
|
5
|
+
`sandloom.modules` entry point `identity = "sandloom_identity"`, so its module
|
|
6
|
+
name is `identity` (tables `identity_*`, migration chain
|
|
7
|
+
`alembic_version_identity`, channels and contracts `identity.*`). Depends on
|
|
8
|
+
`sandloom>=0.7.0a1,<0.8`, pyotp, authlib, qrcode, pillow, itsdangerous and
|
|
9
|
+
email-validator; on no other module.
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
pip install "sandloom[redis,celery]==0.7.0a1" sandloom-identity==0.7.0a1
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
`sandloom.main:app` composes it once installed; an app selects it with
|
|
16
|
+
`SANDLOOM_MODULES=identity` (or `sandloom new <app> --with identity`). Other
|
|
17
|
+
modules call it through its contracts; their DTOs, stubs and event schemas
|
|
18
|
+
live in `sandloom.shared` and ship with `sandloom`.
|
|
19
|
+
|
|
20
|
+
Source of truth lives in the monorepo at `src/sandloom_identity`; this package
|
|
21
|
+
builds the wheel and source archive.
|
|
22
|
+
|
|
23
|
+
## Project links
|
|
24
|
+
|
|
25
|
+
[Source](https://github.com/Sandloom-dev/sandloom) ·
|
|
26
|
+
[Documentation](https://sandloom.dev/docs/) ·
|
|
27
|
+
[Changelog](https://github.com/Sandloom-dev/sandloom/blob/main/packages/sandloom-identity/CHANGELOG.md)
|
|
28
|
+
|
|
29
|
+
This is the initial `0.7.0a1` alpha distribution. The canonical source
|
|
30
|
+
repository is private and awaiting transfer; the documentation website is
|
|
31
|
+
not deployed yet. The project links above are the planned public locations.
|
|
32
|
+
|
|
33
|
+
## License
|
|
34
|
+
|
|
35
|
+
Apache-2.0. Copyright 2026 Vasyl Cherniavskyi. See [LICENSE](LICENSE) and [NOTICE](NOTICE).
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "sandloom-identity"
|
|
3
|
+
version = "0.7.0a1"
|
|
4
|
+
classifiers = ["Development Status :: 3 - Alpha"]
|
|
5
|
+
description = "Sandloom identity module: users, JWT auth, RBAC, 2FA, SSO."
|
|
6
|
+
readme = "README.md"
|
|
7
|
+
license = "Apache-2.0"
|
|
8
|
+
license-files = ["LICENSE", "NOTICE"]
|
|
9
|
+
authors = [{ name = "Vasyl Cherniavskyi" }]
|
|
10
|
+
requires-python = ">=3.11"
|
|
11
|
+
# An ecosystem module like any third party's: a compatible framework range,
|
|
12
|
+
# never an exact pin. Contract calls to other modules are bound at runtime
|
|
13
|
+
# and use the consumer's own generated stubs: no module depends on another.
|
|
14
|
+
dependencies = [
|
|
15
|
+
"sandloom>=0.7.0a1,<0.8",
|
|
16
|
+
"pyotp>=2.10.0,<3",
|
|
17
|
+
"authlib>=1.8.0,<2",
|
|
18
|
+
"qrcode>=8.2,<9",
|
|
19
|
+
"pillow>=13.0.0,<14",
|
|
20
|
+
"itsdangerous>=2.2.0,<3",
|
|
21
|
+
"email-validator>=2.3.0,<3",
|
|
22
|
+
]
|
|
23
|
+
|
|
24
|
+
[project.urls]
|
|
25
|
+
Homepage = "https://sandloom.dev/"
|
|
26
|
+
Documentation = "https://sandloom.dev/docs/"
|
|
27
|
+
Repository = "https://github.com/Sandloom-dev/sandloom"
|
|
28
|
+
Issues = "https://github.com/Sandloom-dev/sandloom/issues"
|
|
29
|
+
Changelog = "https://github.com/Sandloom-dev/sandloom/blob/main/packages/sandloom-identity/CHANGELOG.md"
|
|
30
|
+
|
|
31
|
+
# The module name (`identity`: tables, migration chain, channels, contracts) and
|
|
32
|
+
# its import path; SANDLOOM_MODULES may name it by either.
|
|
33
|
+
[project.entry-points."sandloom.modules"]
|
|
34
|
+
identity = "sandloom_identity"
|
|
35
|
+
|
|
36
|
+
[build-system]
|
|
37
|
+
requires = [
|
|
38
|
+
"hatchling>=1.27",
|
|
39
|
+
]
|
|
40
|
+
build-backend = "hatchling.build"
|
|
41
|
+
|
|
42
|
+
[tool.hatch.build.targets.wheel]
|
|
43
|
+
packages = ["sandloom_identity"]
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
# Identity Module
|
|
2
|
+
|
|
3
|
+
Модуль аутентификации, авторизации и управления пользователями Sandloom Framework
|
|
4
|
+
(обязательный, `required=True`). Полное англоязычное описание:
|
|
5
|
+
[`docs/modules/identity.md`](../../../docs/modules/identity.md).
|
|
6
|
+
|
|
7
|
+
## Возможности
|
|
8
|
+
|
|
9
|
+
- Регистрация и вход по email/паролю; вход только после подтверждения email.
|
|
10
|
+
- JWT access-токены + refresh-токены с ротацией по семействам и детектом
|
|
11
|
+
повторного использования.
|
|
12
|
+
- Верификация email, одноразовые ссылки сброса пароля, смена пароля.
|
|
13
|
+
- Per-account lockout на пароль и второй фактор.
|
|
14
|
+
- 2FA (TOTP + резервные коды) с повторной аутентификацией для изменений.
|
|
15
|
+
- SSO: Google, GitHub, Microsoft, LinkedIn (PKCE, OIDC nonce, привязка flow к
|
|
16
|
+
клиенту).
|
|
17
|
+
- Нормализованный RBAC (глобальные роли/права), claims в access-токене.
|
|
18
|
+
- Отзыв сессий (`revoke_user_tokens` ядра) и доменные события `identity.*`
|
|
19
|
+
без PII; аудит чувствительных действий.
|
|
20
|
+
|
|
21
|
+
## Структура модуля
|
|
22
|
+
|
|
23
|
+
```
|
|
24
|
+
identity/
|
|
25
|
+
├── __init__.py # register(core): роутеры, схемы событий, claims-контрибьютор
|
|
26
|
+
├── access/ # зависимости: get_current_principal, session_not_revoked, is_self_or_admin, ...
|
|
27
|
+
├── api/ # auth, sso, twofa, users, roles, user_roles
|
|
28
|
+
├── models/ # User, Role, Permission, UserRole, RolePermission,
|
|
29
|
+
│ # ExternalIdentity, RefreshToken, TwoFASecret, TwoFABackupCode
|
|
30
|
+
├── schemas/ # Pydantic DTO
|
|
31
|
+
├── services/ # auth, token, user, role, sso, twofa, reauth
|
|
32
|
+
├── migrations/ # собственная цепочка миграций модуля
|
|
33
|
+
├── claims.py # contribute_identity_claims (roles/permissions)
|
|
34
|
+
├── events.py # события и их контракт
|
|
35
|
+
├── lockout.py # per-account блокировка подбора
|
|
36
|
+
├── sessions.py # revoke_sessions → identity.user_sessions_revoked.v1
|
|
37
|
+
├── integrations.py # OAuth-клиенты и отправка писем (notifier)
|
|
38
|
+
├── password_policy.py
|
|
39
|
+
├── utils.py # токены email/сброса, хэши, шифрование
|
|
40
|
+
└── tasks.py # @shared_task для воркера фреймворка (celery -A sandloom.core.worker)
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## API Endpoints
|
|
44
|
+
|
|
45
|
+
### Аутентификация (`/auth`)
|
|
46
|
+
|
|
47
|
+
```
|
|
48
|
+
POST /auth/register # 202 всегда одинаковый ответ (без перечисления аккаунтов)
|
|
49
|
+
POST /auth/login # 403 для неподтверждённого email; 401 + X-2FA-Required при нужном otp
|
|
50
|
+
POST /auth/refresh # ротация; повтор ≤10 с после ротации → 409 (гонка), позже → отзыв семейства (401)
|
|
51
|
+
POST /auth/logout
|
|
52
|
+
POST /auth/verify-email
|
|
53
|
+
POST /auth/resend-verification # всегда 204
|
|
54
|
+
POST /auth/request-password-reset # всегда 204
|
|
55
|
+
POST /auth/reset-password # одноразовая ссылка
|
|
56
|
+
POST /auth/change-password # current_password + new_password → новый TokenPair, остальные сессии отозваны
|
|
57
|
+
GET /auth/me
|
|
58
|
+
PATCH /auth/me
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
### Двухфакторная аутентификация (`/auth/2fa`)
|
|
62
|
+
|
|
63
|
+
```
|
|
64
|
+
GET /auth/2fa/status
|
|
65
|
+
POST /auth/2fa/init # нужен current_password
|
|
66
|
+
POST /auth/2fa/enable # otp + current_password
|
|
67
|
+
POST /auth/2fa/disable # otp + current_password
|
|
68
|
+
POST /auth/2fa/verify # с lockout
|
|
69
|
+
GET /auth/2fa/backup-codes
|
|
70
|
+
POST /auth/2fa/backup-codes/regenerate # otp + current_password
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
Для аккаунтов без пароля (только SSO) вместо `current_password` требуется
|
|
74
|
+
access-токен, выпущенный не более 300 секунд назад.
|
|
75
|
+
|
|
76
|
+
### Single Sign-On (`/auth/sso`)
|
|
77
|
+
|
|
78
|
+
```
|
|
79
|
+
GET /auth/sso/providers
|
|
80
|
+
GET /auth/sso/{provider}/redirect # JSON {auth_url, state, binding} + cookie sandloom_sso_binding
|
|
81
|
+
GET /auth/sso/{provider}/callback # нужен binding (cookie или X-SSO-Binding); TokenPair или MFA-челлендж
|
|
82
|
+
POST /auth/sso/mfa # завершение SSO-входа вторым фактором
|
|
83
|
+
GET /auth/sso/{provider}/link/redirect # начало привязки к текущему аккаунту
|
|
84
|
+
POST /auth/sso/{provider}/link
|
|
85
|
+
DELETE /auth/sso/{provider}/unlink
|
|
86
|
+
GET /auth/sso/me/linked
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
Автопривязка по email — только если email подтверждён провайдером И локальный
|
|
90
|
+
аккаунт подтверждён. Microsoft идентифицируется по `tid:oid` (email доверяется
|
|
91
|
+
только с claim `xms_edov`), GitHub — только verified primary email. Настройка:
|
|
92
|
+
[SSO setup](../../../docs/guides/sso-setup.md).
|
|
93
|
+
|
|
94
|
+
### Пользователи и роли (`/api/v1`)
|
|
95
|
+
|
|
96
|
+
```
|
|
97
|
+
GET /api/v1/users # admin
|
|
98
|
+
GET /api/v1/users/{user_id} # self или admin
|
|
99
|
+
PUT /api/v1/users/{user_id} # self или admin (is_active меняет только admin)
|
|
100
|
+
DELETE /api/v1/users/{user_id} # admin, soft delete
|
|
101
|
+
GET /api/v1/users/{user_id}/roles
|
|
102
|
+
|
|
103
|
+
GET /api/v1/roles
|
|
104
|
+
POST /api/v1/roles
|
|
105
|
+
GET /api/v1/roles/{role_id}
|
|
106
|
+
PUT /api/v1/roles/{role_id}
|
|
107
|
+
DELETE /api/v1/roles/{role_id}
|
|
108
|
+
GET /api/v1/permissions
|
|
109
|
+
POST /api/v1/permissions
|
|
110
|
+
POST /api/v1/roles/{role_id}/permissions/{permission_id}
|
|
111
|
+
DELETE /api/v1/roles/{role_id}/permissions/{permission_id}
|
|
112
|
+
POST /api/v1/users/{user_id}/roles/{role_id}
|
|
113
|
+
DELETE /api/v1/users/{user_id}/roles/{role_id}
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
## Использование из других модулей
|
|
117
|
+
|
|
118
|
+
Модуль подключается через `SANDLOOM_MODULES` (`register(core)`), а не импортом
|
|
119
|
+
роутера. Другие модули не импортируют `sandloom_identity`; они используют:
|
|
120
|
+
|
|
121
|
+
```python
|
|
122
|
+
from sandloom.sdk import CurrentUser, module_router, require
|
|
123
|
+
from sandloom.sdk.authz import Perm, Role
|
|
124
|
+
|
|
125
|
+
router = module_router()
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
@router.get("/admin-only", dependencies=[Depends(require(Role("admin")))])
|
|
129
|
+
async def admin_endpoint(user: CurrentUser): ... # JWT, без БД
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
Access-токен содержит `sub`, `email`, `email_verified`, `token_type: "access"`,
|
|
133
|
+
`roles`, `permissions` и claims других модулей; все проверки токена ядра
|
|
134
|
+
отклоняют отозванные токены (`401 "Token has been revoked"`).
|
|
135
|
+
|
|
136
|
+
## Безопасность
|
|
137
|
+
|
|
138
|
+
- **Пароли**: Argon2 (хэширование вне event loop).
|
|
139
|
+
- **JWT**: `JWT_ALGORITHM` (HS256/HS384/HS512), ротация через
|
|
140
|
+
`JWT_PREVIOUS_SECRETS` / `JWT_KID`.
|
|
141
|
+
- **Refresh-токены**: в БД хранится только SHA-256; семейства ротации.
|
|
142
|
+
- **Секреты 2FA**: шифруются ключом `TWOFA_ENCRYPTION_KEY` (список через
|
|
143
|
+
запятую для ротации, первый — актуальный); в prod ключ обязателен — без него
|
|
144
|
+
модуль не стартует.
|
|
145
|
+
- **Lockout** (два уровня): на входе 5 неудач за 15 минут блокируют пару
|
|
146
|
+
(аккаунт, IP клиента) — от 30 с до 15 мин, 429; атакующий блокирует только
|
|
147
|
+
себя, владелец с другого адреса входит. Поверх — мягкий per-account порог по
|
|
148
|
+
всем IP: от 20 неудач каждая попытка замедляется (0.5 с за неудачу сверх
|
|
149
|
+
порога, максимум 5 с), но не отклоняется. Компромисс: распределённый
|
|
150
|
+
атакующий получает 5 попыток на IP за окно (плюс rate limiter и задержка), зато
|
|
151
|
+
чужой аккаунт нельзя заблокировать. 2FA/смена пароля (первый фактор уже
|
|
152
|
+
пройден) — жёсткая блокировка на аккаунт. При недоступном кэше в prod — 503.
|
|
153
|
+
- **Ротация refresh-токенов**: повтор только что ротированного токена в течение
|
|
154
|
+
10 с при живом преемнике в семействе — безобидная гонка (409, ничего не
|
|
155
|
+
отзывается и не выдаётся); позже или без преемника — reuse, отзыв семейства.
|
|
156
|
+
- **Rate limiting** на чувствительных endpoint'ах.
|
|
157
|
+
- **Отзыв сессий** при деактивации, сбросе/смене пароля и отзыве роли
|
|
158
|
+
(`revoke_user_tokens_on_commit` ядра после коммита +
|
|
159
|
+
`identity.user_sessions_revoked.v1`).
|
|
160
|
+
- **SSO + 2FA**: автопривязка по email к аккаунту с 2FA записывается только
|
|
161
|
+
после успешного второго фактора; неверный binding не «сжигает» state.
|
|
162
|
+
|
|
163
|
+
## События
|
|
164
|
+
|
|
165
|
+
Все события — полный конверт `{event_id, event_type, actor, payload}`:
|
|
166
|
+
|
|
167
|
+
```
|
|
168
|
+
identity.user_registered.v1 # {user_id} — без email
|
|
169
|
+
identity.user_email_confirmed.v1
|
|
170
|
+
identity.user_logged_in.v1 # {user_id, method, provider?}
|
|
171
|
+
identity.user_logged_out.v1
|
|
172
|
+
identity.user_updated.v1
|
|
173
|
+
identity.user_deleted.v1
|
|
174
|
+
identity.user_password_reset.v1
|
|
175
|
+
identity.user_role_assigned.v1
|
|
176
|
+
identity.user_role_revoked.v1
|
|
177
|
+
identity.twofa_enabled.v1
|
|
178
|
+
identity.twofa_disabled.v1
|
|
179
|
+
identity.twofa_backup_codes_regenerated.v1
|
|
180
|
+
identity.sso_linked.v1
|
|
181
|
+
identity.sso_unlinked.v1
|
|
182
|
+
identity.user_sessions_revoked.v1 # {user_id, reason, tokens_valid_after}
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
## Конфигурация
|
|
186
|
+
|
|
187
|
+
```bash
|
|
188
|
+
JWT_SECRET=... # в prod — случайный, ≥32 символов
|
|
189
|
+
JWT_ALGORITHM=HS256
|
|
190
|
+
ACCESS_TOKEN_EXPIRE_MINUTES=15
|
|
191
|
+
REFRESH_TOKEN_EXPIRE_DAYS=14
|
|
192
|
+
TWOFA_ENCRYPTION_KEY=... # openssl rand -hex 32; обязателен в prod
|
|
193
|
+
AUTH_REVOCATION_FAIL_CLOSED= # по умолчанию true в prod
|
|
194
|
+
FRONTEND_URL=http://localhost:3000
|
|
195
|
+
SSO_ALLOWED_REDIRECT_URIS=...
|
|
196
|
+
GOOGLE_CLIENT_ID=... GOOGLE_CLIENT_SECRET=...
|
|
197
|
+
GITHUB_CLIENT_ID=... GITHUB_CLIENT_SECRET=...
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
## Миграции
|
|
201
|
+
|
|
202
|
+
Модуль владеет собственной цепочкой в `identity/migrations/`:
|
|
203
|
+
|
|
204
|
+
```bash
|
|
205
|
+
uv run sandloom migrate upgrade-module identity --apply
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
## Тестирование
|
|
209
|
+
|
|
210
|
+
```bash
|
|
211
|
+
docker compose -f deploy/compose/test.yml up -d --wait
|
|
212
|
+
uv run pytest src/sandloom_identity/tests -q
|
|
213
|
+
```
|