ab-auth-client-service 0.1.3__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.
@@ -0,0 +1,197 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
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.lock
114
+ # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
115
+ # in version control.
116
+ # https://pdm.fming.dev/latest/usage/project/#working-with-version-control
117
+ .pdm.toml
118
+ .pdm-python
119
+ .pdm-build/
120
+
121
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
122
+ __pypackages__/
123
+
124
+ # Celery stuff
125
+ celerybeat-schedule
126
+ celerybeat.pid
127
+
128
+ # SageMath parsed files
129
+ *.sage.py
130
+
131
+ # Environments
132
+ .env
133
+ .venv
134
+ env/
135
+ venv/
136
+ ENV/
137
+ env.bak/
138
+ venv.bak/
139
+
140
+ # Spyder project settings
141
+ .spyderproject
142
+ .spyproject
143
+
144
+ # Rope project settings
145
+ .ropeproject
146
+
147
+ # mkdocs documentation
148
+ /site
149
+
150
+ # mypy
151
+ .mypy_cache/
152
+ .dmypy.json
153
+ dmypy.json
154
+
155
+ # Pyre type checker
156
+ .pyre/
157
+
158
+ # pytype static type analyzer
159
+ .pytype/
160
+
161
+ # Cython debug symbols
162
+ cython_debug/
163
+
164
+ # PyCharm
165
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
166
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
167
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
168
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
169
+ #.idea/
170
+
171
+ # Abstra
172
+ # Abstra is an AI-powered process automation framework.
173
+ # Ignore directories containing user credentials, local state, and settings.
174
+ # Learn more at https://abstra.io/docs
175
+ .abstra/
176
+
177
+ # Visual Studio Code
178
+ # Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore
179
+ # that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
180
+ # and can be added to the global gitignore or merged into this file. However, if you prefer,
181
+ # you could uncomment the following to ignore the entire vscode folder
182
+ # .vscode/
183
+
184
+ # Ruff stuff:
185
+ .ruff_cache/
186
+
187
+ # PyPI configuration file
188
+ .pypirc
189
+
190
+ # Cursor
191
+ # Cursor is an AI-powered code editor. `.cursorignore` specifies files/directories to
192
+ # exclude from AI features like autocomplete and code analysis. Recommended for sensitive data
193
+ # refer to https://docs.cursor.com/context/ignore-files
194
+ .cursorignore
195
+ .cursorindexingignore
196
+
197
+ data
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Matthew Coulter
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,16 @@
1
+ Metadata-Version: 2.4
2
+ Name: ab-auth-client-service
3
+ Version: 0.1.3
4
+ Author-email: Matthew Coulter <53892067+mattcoulter7@users.noreply.github.com>
5
+ License-File: LICENSE
6
+ Requires-Python: <4,>=3.12
7
+ Requires-Dist: ab-auth-client<2,>=0.1.2
8
+ Requires-Dist: ab-cache<2,>=0.1.2
9
+ Requires-Dist: fastapi<0.116,>=0.115.14
10
+ Requires-Dist: pydantic<3,>=2.11.7
11
+ Requires-Dist: uvicorn<0.36,>=0.35.0
12
+ Description-Content-Type: text/markdown
13
+
14
+ # Open Banking, Opened | Token Client Service
15
+
16
+ Token Client Service for Open Banking, Opened API services.
@@ -0,0 +1,3 @@
1
+ # Open Banking, Opened | Token Client Service
2
+
3
+ Token Client Service for Open Banking, Opened API services.
@@ -0,0 +1,71 @@
1
+ [build-system]
2
+ build-backend = "hatchling.build"
3
+ requires = ["hatchling"]
4
+
5
+ [dependency-groups]
6
+ dev = [
7
+ "ab-test-fixtures>=0.1.2,<2",
8
+ "debugpy>=1.8.14,<2",
9
+ "isort>=6.0.1,<7",
10
+ "pre-commit>=4.2.0,<5",
11
+ "pytest-asyncio>=1.0.0,<2",
12
+ "pytest-cov>=6.2.1,<7",
13
+ "pytest>=8.4.1,<9",
14
+ "ruff>=0.12.3,<0.13",
15
+ "tox>=4.27.0,<5"
16
+ ]
17
+
18
+ [project]
19
+ authors = [{email = "53892067+mattcoulter7@users.noreply.github.com", name = "Matthew Coulter"}]
20
+ dependencies = [
21
+ "ab-auth-client>=0.1.2,<2",
22
+ "ab-cache>=0.1.2,<2",
23
+ "fastapi>=0.115.14,<0.116",
24
+ "pydantic>=2.11.7,<3",
25
+ "uvicorn>=0.35.0,<0.36"
26
+ ]
27
+ description = ""
28
+ name = "ab-auth-client-service"
29
+ readme = "README.md"
30
+ requires-python = ">=3.12, <4"
31
+ version = "0.1.3"
32
+
33
+ [tool.hatch.build.targets.sdist]
34
+ include = ["src/ab_service"]
35
+
36
+ [tool.hatch.build.targets.wheel]
37
+ include = ["src/ab_service"]
38
+
39
+ [tool.hatch.build.targets.wheel.sources]
40
+ "src/ab_service" = "ab_service"
41
+
42
+ [tool.pytest.ini_options]
43
+ asyncio_default_fixture_loop_scope = "session"
44
+ asyncio_mode = "auto"
45
+ markers = [
46
+ "integration: Assigns the test to the integration test suite.",
47
+ "regression: Assigns the test to the regression test suite"
48
+ ]
49
+
50
+ [tool.ruff]
51
+ line-length = 120
52
+ src = ["src"]
53
+ target-version = "py312"
54
+
55
+ [tool.ruff.lint]
56
+ exclude = [".git", ".venv", "__pycache__", "proto"]
57
+ fixable = ["ALL"]
58
+ ignore = [
59
+ "D104" # missing docstring in public package
60
+ ]
61
+ select = [
62
+ "ARG001", # unused arguments
63
+ "B", # flake8-bugbear
64
+ "C4", # flake8-comprehensions
65
+ "D", # pydocstyle (docstring checks)
66
+ "E", # pycodestyle errors
67
+ "F", # pyflakes
68
+ "I", # isort
69
+ "UP", # pyupgrade
70
+ "W" # pycodestyle warnings
71
+ ]
@@ -0,0 +1,10 @@
1
+ """Main application for the auth client service."""
2
+
3
+ from fastapi import FastAPI
4
+
5
+ from ab_service.auth_client.routes.callback import router as callback_router
6
+ from ab_service.auth_client.routes.login import router as login_router
7
+
8
+ app = FastAPI()
9
+ app.include_router(login_router)
10
+ app.include_router(callback_router)
@@ -0,0 +1,53 @@
1
+ """Handle Login Callback."""
2
+
3
+ from typing import Annotated
4
+
5
+ from ab_core.auth_client.oauth2.client import OAuth2Client
6
+ from ab_core.auth_client.oauth2.client.pkce import PKCEOAuth2Client
7
+ from ab_core.auth_client.oauth2.client.standard import StandardOAuth2Client
8
+ from ab_core.auth_client.oauth2.schema.exchange import (
9
+ OAuth2ExchangeFromRedirectUrlRequest,
10
+ PKCEExchangeFromRedirectUrlRequest,
11
+ )
12
+ from ab_core.auth_client.oauth2.schema.token import OAuth2Token
13
+ from ab_core.cache.caches.base import CacheSession
14
+ from ab_core.cache.session_context import cache_session_sync
15
+ from ab_core.dependency import Depends
16
+ from fastapi import APIRouter, Request
17
+
18
+ router = APIRouter(prefix="/callback", tags=["Auth"])
19
+
20
+
21
+ @router.get("", response_model=OAuth2Token)
22
+ async def callback(
23
+ request: Request,
24
+ auth_client: Annotated[OAuth2Client, Depends(OAuth2Client, persist=True)],
25
+ cache_session: Annotated[CacheSession, Depends(cache_session_sync, persist=True)],
26
+ ):
27
+ """Exchange the authorization code for tokens using the full redirect URL.
28
+
29
+ For PKCE, the verifier is auto-fetched from cache via `state` (or falls back to the verifier
30
+ included in the /login response if the caller passes it back).
31
+ """
32
+ redirect_url = str(request.url)
33
+
34
+ if isinstance(auth_client, PKCEOAuth2Client):
35
+ exch = PKCEExchangeFromRedirectUrlRequest(
36
+ redirect_url=redirect_url,
37
+ enforce_redirect_uri_match=True, # optional, validates against client.config.redirect_uri
38
+ expected_state=None, # set to a value you stored server-side if you want CSRF check here
39
+ code_verifier=None, # prefer cache lookup by state; pass fallback if you kept it client-side
40
+ delete_after=True,
41
+ )
42
+ return auth_client.exchange_from_redirect_url(exch, cache_session=cache_session)
43
+
44
+ elif isinstance(auth_client, StandardOAuth2Client):
45
+ exch = OAuth2ExchangeFromRedirectUrlRequest(
46
+ redirect_url=redirect_url,
47
+ enforce_redirect_uri_match=True,
48
+ expected_state=None,
49
+ delete_after=True, # no-op for standard, but field exists for parity
50
+ )
51
+ return auth_client.exchange_from_redirect_url(exch, cache_session=cache_session)
52
+
53
+ raise TypeError(f"Unsupported OAuth2 client type: {type(auth_client).__name__}")
@@ -0,0 +1,59 @@
1
+ """Generate login url."""
2
+
3
+ from typing import Annotated
4
+
5
+ from ab_core.auth_client.oauth2.client import OAuth2Client
6
+ from ab_core.auth_client.oauth2.client.pkce import PKCEOAuth2Client
7
+ from ab_core.auth_client.oauth2.client.standard import StandardOAuth2Client
8
+ from ab_core.auth_client.oauth2.schema.authorize import (
9
+ OAuth2AuthorizeResponse,
10
+ OAuth2BuildAuthorizeRequest,
11
+ PKCEAuthorizeResponse,
12
+ PKCEBuildAuthorizeRequest,
13
+ )
14
+ from ab_core.cache.caches.base import CacheSession
15
+ from ab_core.cache.session_context import cache_session_sync # your DI dep that yields a session
16
+ from ab_core.dependency import Depends
17
+ from fastapi import APIRouter
18
+ from fastapi import Depends as FDepends
19
+
20
+ router = APIRouter(prefix="/login", tags=["Auth"])
21
+
22
+
23
+ @router.get(
24
+ "",
25
+ response_model=OAuth2AuthorizeResponse | PKCEAuthorizeResponse,
26
+ )
27
+ async def get_login_url(
28
+ auth_client: Annotated[OAuth2Client, Depends(OAuth2Client, persist=True)],
29
+ cache_session: Annotated[CacheSession, FDepends(cache_session_sync)],
30
+ # optional knobs (you can also load these from env/settings if you prefer)
31
+ scope: str = "openid email profile",
32
+ response_type: str = "code",
33
+ identity_provider: str | None = "Google",
34
+ ):
35
+ """Build an OIDC authorize URL (Standard or PKCE) using the shared auth client.
36
+
37
+ If PKCE, a fresh verifier/challenge is generated and (optionally) persisted to cache keyed by `state`.
38
+ """
39
+ extra = {"identity_provider": identity_provider} if identity_provider else None
40
+
41
+ if isinstance(auth_client, PKCEOAuth2Client):
42
+ req = PKCEBuildAuthorizeRequest(
43
+ scope=scope,
44
+ response_type=response_type,
45
+ extra_params=extra,
46
+ pkce=None, # per-request PKCE generated by the client
47
+ )
48
+ return auth_client.build_authorize_request(req, cache_session=cache_session)
49
+
50
+ elif isinstance(auth_client, StandardOAuth2Client):
51
+ req = OAuth2BuildAuthorizeRequest(
52
+ scope=scope,
53
+ response_type=response_type,
54
+ extra_params=extra,
55
+ )
56
+ return auth_client.build_authorize_request(req, cache_session=cache_session)
57
+
58
+ # If you later add more client types, handle them here
59
+ raise TypeError(f"Unsupported OAuth2 client type: {type(auth_client).__name__}")