auth-sdk-m8 0.1.0.2__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 (44) hide show
  1. auth_sdk_m8-0.1.0.2/.github/workflows/PiPy.yml +70 -0
  2. auth_sdk_m8-0.1.0.2/.gitignore +218 -0
  3. auth_sdk_m8-0.1.0.2/.vscode/settings.json +9 -0
  4. auth_sdk_m8-0.1.0.2/LICENSE +21 -0
  5. auth_sdk_m8-0.1.0.2/PKG-INFO +287 -0
  6. auth_sdk_m8-0.1.0.2/README.md +215 -0
  7. auth_sdk_m8-0.1.0.2/auth_sdk_m8/__init__.py +6 -0
  8. auth_sdk_m8-0.1.0.2/auth_sdk_m8/controllers/__init__.py +1 -0
  9. auth_sdk_m8-0.1.0.2/auth_sdk_m8/controllers/base.py +103 -0
  10. auth_sdk_m8-0.1.0.2/auth_sdk_m8/core/__init__.py +1 -0
  11. auth_sdk_m8-0.1.0.2/auth_sdk_m8/core/config.py +326 -0
  12. auth_sdk_m8-0.1.0.2/auth_sdk_m8/core/exceptions.py +5 -0
  13. auth_sdk_m8-0.1.0.2/auth_sdk_m8/core/security.py +160 -0
  14. auth_sdk_m8-0.1.0.2/auth_sdk_m8/models/__init__.py +1 -0
  15. auth_sdk_m8-0.1.0.2/auth_sdk_m8/models/shared.py +58 -0
  16. auth_sdk_m8-0.1.0.2/auth_sdk_m8/redis_events/__init__.py +1 -0
  17. auth_sdk_m8-0.1.0.2/auth_sdk_m8/redis_events/event_bus.py +88 -0
  18. auth_sdk_m8-0.1.0.2/auth_sdk_m8/redis_events/publisher.py +37 -0
  19. auth_sdk_m8-0.1.0.2/auth_sdk_m8/redis_events/subscriber.py +70 -0
  20. auth_sdk_m8-0.1.0.2/auth_sdk_m8/schemas/__init__.py +1 -0
  21. auth_sdk_m8-0.1.0.2/auth_sdk_m8/schemas/auth.py +88 -0
  22. auth_sdk_m8-0.1.0.2/auth_sdk_m8/schemas/base.py +107 -0
  23. auth_sdk_m8-0.1.0.2/auth_sdk_m8/schemas/redis_events.py +9 -0
  24. auth_sdk_m8-0.1.0.2/auth_sdk_m8/schemas/shared.py +67 -0
  25. auth_sdk_m8-0.1.0.2/auth_sdk_m8/schemas/user.py +45 -0
  26. auth_sdk_m8-0.1.0.2/auth_sdk_m8/schemas/user_events.py +14 -0
  27. auth_sdk_m8-0.1.0.2/auth_sdk_m8/utils/__init__.py +1 -0
  28. auth_sdk_m8-0.1.0.2/auth_sdk_m8/utils/errors_parser.py +92 -0
  29. auth_sdk_m8-0.1.0.2/auth_sdk_m8/utils/paths.py +34 -0
  30. auth_sdk_m8-0.1.0.2/pyproject.toml +95 -0
  31. auth_sdk_m8-0.1.0.2/tests/__init__.py +0 -0
  32. auth_sdk_m8-0.1.0.2/tests/conftest.py +98 -0
  33. auth_sdk_m8-0.1.0.2/tests/test_controllers.py +82 -0
  34. auth_sdk_m8-0.1.0.2/tests/test_core_config.py +260 -0
  35. auth_sdk_m8-0.1.0.2/tests/test_core_exceptions.py +27 -0
  36. auth_sdk_m8-0.1.0.2/tests/test_core_security.py +172 -0
  37. auth_sdk_m8-0.1.0.2/tests/test_models.py +32 -0
  38. auth_sdk_m8-0.1.0.2/tests/test_redis_events.py +397 -0
  39. auth_sdk_m8-0.1.0.2/tests/test_schemas.py +7 -0
  40. auth_sdk_m8-0.1.0.2/tests/test_schemas_auth.py +110 -0
  41. auth_sdk_m8-0.1.0.2/tests/test_schemas_base.py +135 -0
  42. auth_sdk_m8-0.1.0.2/tests/test_schemas_shared.py +140 -0
  43. auth_sdk_m8-0.1.0.2/tests/test_schemas_user.py +94 -0
  44. auth_sdk_m8-0.1.0.2/tests/test_utils.py +133 -0
@@ -0,0 +1,70 @@
1
+ # This workflow will upload a Python Package to PyPI when a release is created
2
+ # For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python#publishing-to-package-registries
3
+
4
+ # This workflow uses actions that are not certified by GitHub.
5
+ # They are provided by a third-party and are governed by
6
+ # separate terms of service, privacy policy, and support
7
+ # documentation.
8
+
9
+ name: Upload Python Package
10
+
11
+ on:
12
+ release:
13
+ types: [published]
14
+
15
+ permissions:
16
+ contents: read
17
+
18
+ jobs:
19
+ release-build:
20
+ runs-on: ubuntu-latest
21
+
22
+ steps:
23
+ - uses: actions/checkout@v4
24
+
25
+ - uses: actions/setup-python@v5
26
+ with:
27
+ python-version: "3.x"
28
+
29
+ - name: Build release distributions
30
+ run: |
31
+ # NOTE: put your own distribution build steps here.
32
+ python -m pip install build
33
+ python -m build
34
+
35
+ - name: Upload distributions
36
+ uses: actions/upload-artifact@v4
37
+ with:
38
+ name: release-dists
39
+ path: dist/
40
+
41
+ pypi-publish:
42
+ runs-on: ubuntu-latest
43
+ needs:
44
+ - release-build
45
+ permissions:
46
+ # IMPORTANT: this permission is mandatory for trusted publishing
47
+ id-token: write
48
+
49
+ # Dedicated environments with protections for publishing are strongly recommended.
50
+ # For more information, see: https://docs.github.com/en/actions/deployment/targeting-different-environments/using-environments-for-deployment#deployment-protection-rules
51
+ environment:
52
+ name: pypi
53
+ # OPTIONAL: uncomment and update to include your PyPI project URL in the deployment status:
54
+ #url: https://pypi.org/p/auth_sdk_m8
55
+ #
56
+ # ALTERNATIVE: if your GitHub Release name is the PyPI project version string
57
+ # ALTERNATIVE: exactly, uncomment the following line instead:
58
+ url: https://pypi.org/project/auth_sdk_m8/${{ github.event.release.name }}
59
+
60
+ steps:
61
+ - name: Retrieve release distributions
62
+ uses: actions/download-artifact@v4
63
+ with:
64
+ name: release-dists
65
+ path: dist/
66
+
67
+ - name: Publish release distributions to PyPI
68
+ uses: pypa/gh-action-pypi-publish@release/v1
69
+ with:
70
+ password: ${{ secrets.PYPI_API_TOKEN }}
@@ -0,0 +1,218 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[codz]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ share/python-wheels/
24
+ *.egg-info/
25
+ .installed.cfg
26
+ *.egg
27
+ MANIFEST
28
+
29
+ # PyInstaller
30
+ # Usually these files are written by a python script from a template
31
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
32
+ *.manifest
33
+ *.spec
34
+
35
+ # Installer logs
36
+ pip-log.txt
37
+ pip-delete-this-directory.txt
38
+
39
+ # Unit test / coverage reports
40
+ htmlcov/
41
+ .tox/
42
+ .nox/
43
+ .coverage
44
+ .coverage.*
45
+ .cache
46
+ nosetests.xml
47
+ coverage.xml
48
+ *.cover
49
+ *.py.cover
50
+ .hypothesis/
51
+ .pytest_cache/
52
+ cover/
53
+
54
+ # Translations
55
+ *.mo
56
+ *.pot
57
+
58
+ # Django stuff:
59
+ *.log
60
+ local_settings.py
61
+ db.sqlite3
62
+ db.sqlite3-journal
63
+
64
+ # Flask stuff:
65
+ instance/
66
+ .webassets-cache
67
+
68
+ # Scrapy stuff:
69
+ .scrapy
70
+
71
+ # Sphinx documentation
72
+ docs/_build/
73
+
74
+ # PyBuilder
75
+ .pybuilder/
76
+ target/
77
+
78
+ # Jupyter Notebook
79
+ .ipynb_checkpoints
80
+
81
+ # IPython
82
+ profile_default/
83
+ ipython_config.py
84
+
85
+ # pyenv
86
+ # For a library or package, you might want to ignore these files since the code is
87
+ # intended to run in multiple environments; otherwise, check them in:
88
+ # .python-version
89
+
90
+ # pipenv
91
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
93
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
94
+ # install all needed dependencies.
95
+ # Pipfile.lock
96
+
97
+ # UV
98
+ # Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
99
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
100
+ # commonly ignored for libraries.
101
+ # uv.lock
102
+
103
+ # poetry
104
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
105
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
106
+ # commonly ignored for libraries.
107
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
108
+ # poetry.lock
109
+ # poetry.toml
110
+
111
+ # pdm
112
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
113
+ # pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python.
114
+ # https://pdm-project.org/en/latest/usage/project/#working-with-version-control
115
+ # pdm.lock
116
+ # pdm.toml
117
+ .pdm-python
118
+ .pdm-build/
119
+
120
+ # pixi
121
+ # Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control.
122
+ # pixi.lock
123
+ # Pixi creates a virtual environment in the .pixi directory, just like venv module creates one
124
+ # in the .venv directory. It is recommended not to include this directory in version control.
125
+ .pixi
126
+
127
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
128
+ __pypackages__/
129
+
130
+ # Celery stuff
131
+ celerybeat-schedule
132
+ celerybeat.pid
133
+
134
+ # Redis
135
+ *.rdb
136
+ *.aof
137
+ *.pid
138
+
139
+ # RabbitMQ
140
+ mnesia/
141
+ rabbitmq/
142
+ rabbitmq-data/
143
+
144
+ # ActiveMQ
145
+ activemq-data/
146
+
147
+ # SageMath parsed files
148
+ *.sage.py
149
+
150
+ # Environments
151
+ .env
152
+ .envrc
153
+ .venv
154
+ env/
155
+ venv/
156
+ ENV/
157
+ env.bak/
158
+ venv.bak/
159
+
160
+ # Spyder project settings
161
+ .spyderproject
162
+ .spyproject
163
+
164
+ # Rope project settings
165
+ .ropeproject
166
+
167
+ # mkdocs documentation
168
+ /site
169
+
170
+ # mypy
171
+ .mypy_cache/
172
+ .dmypy.json
173
+ dmypy.json
174
+
175
+ # Pyre type checker
176
+ .pyre/
177
+
178
+ # pytype static type analyzer
179
+ .pytype/
180
+
181
+ # Cython debug symbols
182
+ cython_debug/
183
+
184
+ # PyCharm
185
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
186
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
187
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
188
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
189
+ # .idea/
190
+
191
+ # Abstra
192
+ # Abstra is an AI-powered process automation framework.
193
+ # Ignore directories containing user credentials, local state, and settings.
194
+ # Learn more at https://abstra.io/docs
195
+ .abstra/
196
+
197
+ # Visual Studio Code
198
+ # Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore
199
+ # that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
200
+ # and can be added to the global gitignore or merged into this file. However, if you prefer,
201
+ # you could uncomment the following to ignore the entire vscode folder
202
+ # .vscode/
203
+ # Temporary file for partial code execution
204
+ tempCodeRunnerFile.py
205
+
206
+ # Ruff stuff:
207
+ .ruff_cache/
208
+
209
+ # PyPI configuration file
210
+ .pypirc
211
+
212
+ # Marimo
213
+ marimo/_static/
214
+ marimo/_lsp/
215
+ __marimo__/
216
+
217
+ # Streamlit
218
+ .streamlit/secrets.toml
@@ -0,0 +1,9 @@
1
+ {
2
+ "python.testing.pytestArgs": [
3
+
4
+ ],
5
+ "python.testing.unittestEnabled": false,
6
+ "python.testing.pytestEnabled": true,
7
+ "python-envs.defaultEnvManager": "ms-python.python:conda",
8
+ "python-envs.defaultPackageManager": "ms-python.python:conda"
9
+ }
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Eli Serra
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,287 @@
1
+ Metadata-Version: 2.4
2
+ Name: auth-sdk-m8
3
+ Version: 0.1.0.2
4
+ Summary: Shared authentication schemas, JWT utilities and FastAPI base components for m8 microservices.
5
+ Project-URL: Homepage, https://gitlab.com/yourorg/auth-sdk-m8
6
+ Project-URL: Repository, https://gitlab.com/yourorg/auth-sdk-m8
7
+ Project-URL: Issue Tracker, https://gitlab.com/yourorg/auth-sdk-m8/-/issues
8
+ Author-email: Eli Serra <mex.serra@gmail.com>
9
+ License: MIT License
10
+
11
+ Copyright (c) 2026 Eli Serra
12
+
13
+ Permission is hereby granted, free of charge, to any person obtaining a copy
14
+ of this software and associated documentation files (the "Software"), to deal
15
+ in the Software without restriction, including without limitation the rights
16
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
17
+ copies of the Software, and to permit persons to whom the Software is
18
+ furnished to do so, subject to the following conditions:
19
+
20
+ The above copyright notice and this permission notice shall be included in all
21
+ copies or substantial portions of the Software.
22
+
23
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
26
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
28
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
29
+ SOFTWARE.
30
+ License-File: LICENSE
31
+ Keywords: auth,fastapi,jwt,microservices,pydantic
32
+ Classifier: Development Status :: 3 - Alpha
33
+ Classifier: Framework :: FastAPI
34
+ Classifier: Intended Audience :: Developers
35
+ Classifier: License :: OSI Approved :: MIT License
36
+ Classifier: Programming Language :: Python :: 3.11
37
+ Classifier: Programming Language :: Python :: 3.12
38
+ Classifier: Topic :: Software Development :: Libraries
39
+ Requires-Python: >=3.11
40
+ Requires-Dist: email-validator>=2.2.0
41
+ Requires-Dist: pydantic>=2.10.6
42
+ Provides-Extra: all
43
+ Requires-Dist: fastapi>=0.115.7; extra == 'all'
44
+ Requires-Dist: pydantic-settings>=2.7.1; extra == 'all'
45
+ Requires-Dist: pyjwt>=2.10.1; extra == 'all'
46
+ Requires-Dist: redis>=5.2.1; extra == 'all'
47
+ Requires-Dist: sqlalchemy>=2.0.38; extra == 'all'
48
+ Requires-Dist: sqlmodel>=0.0.22; extra == 'all'
49
+ Provides-Extra: config
50
+ Requires-Dist: pydantic-settings>=2.7.1; extra == 'config'
51
+ Provides-Extra: db
52
+ Requires-Dist: sqlalchemy>=2.0.38; extra == 'db'
53
+ Requires-Dist: sqlmodel>=0.0.22; extra == 'db'
54
+ Provides-Extra: dev
55
+ Requires-Dist: fastapi>=0.115.7; extra == 'dev'
56
+ Requires-Dist: pydantic-settings>=2.7.1; extra == 'dev'
57
+ Requires-Dist: pyjwt>=2.10.1; extra == 'dev'
58
+ Requires-Dist: pytest-asyncio>=0.23; extra == 'dev'
59
+ Requires-Dist: pytest-cov>=5.0; extra == 'dev'
60
+ Requires-Dist: pytest>=8.3; extra == 'dev'
61
+ Requires-Dist: redis>=5.2.1; extra == 'dev'
62
+ Requires-Dist: ruff>=0.9; extra == 'dev'
63
+ Requires-Dist: sqlalchemy>=2.0.38; extra == 'dev'
64
+ Requires-Dist: sqlmodel>=0.0.22; extra == 'dev'
65
+ Provides-Extra: fastapi
66
+ Requires-Dist: fastapi>=0.115.7; extra == 'fastapi'
67
+ Provides-Extra: redis
68
+ Requires-Dist: redis>=5.2.1; extra == 'redis'
69
+ Provides-Extra: security
70
+ Requires-Dist: pyjwt>=2.10.1; extra == 'security'
71
+ Description-Content-Type: text/markdown
72
+
73
+ # auth-sdk-m8
74
+
75
+ Shared authentication schemas, JWT utilities, and FastAPI base components for **m8 microservices**.
76
+
77
+ This package is extracted from `auth_user_service` and is intended to be installed by any service
78
+ that integrates with it via Docker Compose. It provides the Pydantic schemas matching the auth
79
+ service's API, JWT validation helpers, and optional FastAPI/SQLModel base classes.
80
+
81
+ ---
82
+
83
+ ## Installation
84
+
85
+ ### From GitLab Package Registry (recommended after first publish)
86
+
87
+ ```bash
88
+ pip install auth-sdk-m8 \
89
+ --index-url https://gitlab.com/api/v4/projects/<PROJECT_ID>/packages/pypi/simple \
90
+ --extra-index-url https://pypi.org/simple
91
+ ```
92
+
93
+ With a deploy token in `pip.conf` or `~/.netrc`:
94
+ ```ini
95
+ # pip.conf
96
+ [global]
97
+ index-url = https://gitlab.com/api/v4/projects/<PROJECT_ID>/packages/pypi/simple
98
+ extra-index-url = https://pypi.org/simple
99
+ ```
100
+
101
+ ### Directly from GitLab via git
102
+
103
+ ```bash
104
+ pip install "auth-sdk-m8 @ git+https://gitlab.com/yourorg/auth-sdk-m8.git@v0.1.0"
105
+ ```
106
+
107
+ ### For development (editable install)
108
+
109
+ ```bash
110
+ git clone https://gitlab.com/yourorg/auth-sdk-m8.git
111
+ cd auth-sdk-m8
112
+ pip install -e ".[all,dev]"
113
+ ```
114
+
115
+ ---
116
+
117
+ ## Optional dependency groups
118
+
119
+ Install only what your service needs:
120
+
121
+ | Extra | Installs | Use when |
122
+ |---|---|---|
123
+ | *(none)* | `pydantic`, `email-validator` | schemas only |
124
+ | `[security]` | `PyJWT` | local JWT validation |
125
+ | `[fastapi]` | `fastapi` | cookie helpers, `BaseController` |
126
+ | `[redis]` | `redis` | Redis event bus |
127
+ | `[config]` | `pydantic-settings` | `CommonSettings` base class |
128
+ | `[db]` | `sqlmodel`, `sqlalchemy` | `TimestampMixin`, DB error parsing |
129
+ | `[all]` | everything above | full feature set |
130
+
131
+ Examples:
132
+
133
+ ```bash
134
+ # A service that only validates tokens locally
135
+ pip install "auth-sdk-m8[security]"
136
+
137
+ # A FastAPI service using BaseController and JWT
138
+ pip install "auth-sdk-m8[security,fastapi,db]"
139
+
140
+ # A service that only listens to Redis events
141
+ pip install "auth-sdk-m8[redis]"
142
+ ```
143
+
144
+ ---
145
+
146
+ ## Quick start
147
+
148
+ ### Validate a JWT from auth_user_service
149
+
150
+ ```python
151
+ from auth_sdk_m8.core.security import ComSecurityHelper
152
+ from auth_sdk_m8.core.exceptions import InvalidToken
153
+ from auth_sdk_m8.schemas.auth import TokenDecodeProps
154
+ from pydantic import SecretStr
155
+
156
+ try:
157
+ user = ComSecurityHelper.decode_access_token(
158
+ TokenDecodeProps(
159
+ access_token=bearer_token,
160
+ secret_key=SecretStr(ACCESS_SECRET_KEY),
161
+ algorithm="HS256",
162
+ )
163
+ )
164
+ print(user.email, user.role)
165
+ except InvalidToken:
166
+ # token expired or invalid signature
167
+ ...
168
+ ```
169
+
170
+ ### FastAPI dependency for token validation
171
+
172
+ ```python
173
+ from fastapi import Depends, HTTPException
174
+ from fastapi.security import OAuth2PasswordBearer
175
+ from auth_sdk_m8.core.security import ComSecurityHelper
176
+ from auth_sdk_m8.core.exceptions import InvalidToken
177
+ from auth_sdk_m8.schemas.auth import TokenDecodeProps
178
+ from auth_sdk_m8.schemas.user import UserModel
179
+ from pydantic import SecretStr
180
+
181
+ oauth2 = OAuth2PasswordBearer(tokenUrl="/auth/login/access-token")
182
+
183
+ def get_current_user(token: str = Depends(oauth2)) -> UserModel:
184
+ try:
185
+ payload = ComSecurityHelper.decode_access_token(
186
+ TokenDecodeProps(
187
+ access_token=token,
188
+ secret_key=SecretStr(settings.ACCESS_SECRET_KEY),
189
+ algorithm=settings.TOKEN_ALGORITHM,
190
+ )
191
+ )
192
+ except InvalidToken as exc:
193
+ raise HTTPException(status_code=403, detail="Could not validate credentials.") from exc
194
+ return UserModel(id=payload.sub, **payload.model_dump(exclude={"sub", "jti", "exp", "type"}))
195
+ ```
196
+
197
+ ### Extend CommonSettings for your service
198
+
199
+ ```python
200
+ from pathlib import Path
201
+ from auth_sdk_m8.core.config import CommonSettings
202
+ from auth_sdk_m8.utils.paths import find_dotenv
203
+ from pydantic_settings import SettingsConfigDict
204
+
205
+ class Settings(CommonSettings):
206
+ ENV_FILE_DIR = Path(__file__).resolve().parent
207
+ model_config = SettingsConfigDict(
208
+ env_file=find_dotenv(ENV_FILE_DIR),
209
+ env_file_encoding="utf-8",
210
+ )
211
+ # add service-specific fields here
212
+ MY_SERVICE_SECRET: str
213
+
214
+ settings = Settings()
215
+ ```
216
+
217
+ ### Listen to Redis events from auth_user_service
218
+
219
+ ```python
220
+ import asyncio
221
+ from auth_sdk_m8.redis_events.event_bus import EventBus
222
+ from auth_sdk_m8.schemas.user_events import UserDeletedEvent
223
+
224
+ bus = EventBus(redis_url="redis://localhost:6379")
225
+
226
+ async def on_user_deleted(event: UserDeletedEvent) -> None:
227
+ print(f"User {event.user_id} was deleted — cleaning up local data.")
228
+
229
+ async def main():
230
+ await bus.subscribe("user.deleted", UserDeletedEvent, on_user_deleted)
231
+ await asyncio.sleep(3600) # keep running
232
+
233
+ asyncio.run(main())
234
+ ```
235
+
236
+ ---
237
+
238
+ ## Package layout
239
+
240
+ ```
241
+ src/auth_sdk_m8/
242
+ ├── schemas/
243
+ │ ├── auth.py # JWT payload schemas (TokenUserData, TokenAccessData, …)
244
+ │ ├── base.py # Enums (AuthProviderType, RoleType, Period) + response models
245
+ │ ├── shared.py # ValidationConstants (regex patterns)
246
+ │ ├── user.py # UserModel, SessionModel
247
+ │ ├── redis_events.py # EventBase
248
+ │ └── user_events.py # UserDeletedEvent
249
+ ├── core/
250
+ │ ├── config.py # CommonSettings (pydantic-settings base class)
251
+ │ ├── exceptions.py # InvalidToken
252
+ │ └── security.py # ComSecurityHelper: JWT decode, PKCE, token hashing
253
+ ├── redis_events/
254
+ │ ├── event_bus.py # EventBus (typed pub/sub)
255
+ │ ├── publisher.py # EventPublisher
256
+ │ └── subscriber.py # EventSubscriber
257
+ ├── controllers/
258
+ │ └── base.py # BaseController: unified exception → JSONResponse
259
+ ├── models/
260
+ │ └── shared.py # TimestampMixin, Message, Token, TokenPayload (SQLModel)
261
+ └── utils/
262
+ ├── errors_parser.py # parse_integrity_error, parse_pydantic_errors
263
+ └── paths.py # find_dotenv
264
+ ```
265
+
266
+ ---
267
+
268
+ ## Publishing a new version
269
+
270
+ 1. Bump `version` in `pyproject.toml`
271
+ 2. Add an entry to `CHANGELOG.md`
272
+ 3. Commit and push
273
+ 4. Create a git tag: `git tag v0.2.0 && git push origin v0.2.0`
274
+ 5. GitLab CI builds and publishes automatically to the Package Registry
275
+
276
+ ---
277
+
278
+ ## Architecture note
279
+
280
+ This SDK is intentionally thin. It contains **no business logic** — only schemas,
281
+ validation helpers, and infrastructure base classes. Each consuming service validates
282
+ JWTs locally using `ComSecurityHelper` (no network call per request). The `auth_user_service`
283
+ remains the sole authority for issuing tokens; this SDK only provides the tools to
284
+ **read** them.
285
+
286
+ For production deployments with multiple teams, consider switching to **RS256** asymmetric
287
+ signing so consuming services only need the public key (never the secret).