simple-module-auth 0.0.50__tar.gz → 0.0.51__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.
- {simple_module_auth-0.0.50 → simple_module_auth-0.0.51}/PKG-INFO +4 -4
- {simple_module_auth-0.0.50 → simple_module_auth-0.0.51}/auth/contracts/schemas.py +5 -4
- {simple_module_auth-0.0.50 → simple_module_auth-0.0.51}/auth/core/state.py +5 -3
- {simple_module_auth-0.0.50 → simple_module_auth-0.0.51}/auth/web/middleware.py +3 -0
- {simple_module_auth-0.0.50 → simple_module_auth-0.0.51}/pyproject.toml +4 -4
- simple_module_auth-0.0.51/tests/web/middleware/test_principal_guards.py +83 -0
- {simple_module_auth-0.0.50 → simple_module_auth-0.0.51}/.gitignore +0 -0
- {simple_module_auth-0.0.50 → simple_module_auth-0.0.51}/LICENSE +0 -0
- {simple_module_auth-0.0.50 → simple_module_auth-0.0.51}/README.md +0 -0
- {simple_module_auth-0.0.50 → simple_module_auth-0.0.51}/auth/__init__.py +0 -0
- {simple_module_auth-0.0.50 → simple_module_auth-0.0.51}/auth/contracts/__init__.py +0 -0
- {simple_module_auth-0.0.50 → simple_module_auth-0.0.51}/auth/contracts/events.py +0 -0
- {simple_module_auth-0.0.50 → simple_module_auth-0.0.51}/auth/contracts/provider.py +0 -0
- {simple_module_auth-0.0.50 → simple_module_auth-0.0.51}/auth/contracts/resolver.py +0 -0
- {simple_module_auth-0.0.50 → simple_module_auth-0.0.51}/auth/contracts/tokens.py +0 -0
- {simple_module_auth-0.0.50 → simple_module_auth-0.0.51}/auth/core/__init__.py +0 -0
- {simple_module_auth-0.0.50 → simple_module_auth-0.0.51}/auth/core/constants.py +0 -0
- {simple_module_auth-0.0.50 → simple_module_auth-0.0.51}/auth/locales/de.json +0 -0
- {simple_module_auth-0.0.50 → simple_module_auth-0.0.51}/auth/locales/en.json +0 -0
- {simple_module_auth-0.0.50 → simple_module_auth-0.0.51}/auth/locales/es.json +0 -0
- {simple_module_auth-0.0.50 → simple_module_auth-0.0.51}/auth/models.py +0 -0
- {simple_module_auth-0.0.50 → simple_module_auth-0.0.51}/auth/module.py +0 -0
- {simple_module_auth-0.0.50 → simple_module_auth-0.0.51}/auth/oidc_common/__init__.py +0 -0
- {simple_module_auth-0.0.50 → simple_module_auth-0.0.51}/auth/oidc_common/claims.py +0 -0
- {simple_module_auth-0.0.50 → simple_module_auth-0.0.51}/auth/oidc_common/directory.py +0 -0
- {simple_module_auth-0.0.50 → simple_module_auth-0.0.51}/auth/oidc_common/jwks.py +0 -0
- {simple_module_auth-0.0.50 → simple_module_auth-0.0.51}/auth/oidc_common/logout.py +0 -0
- {simple_module_auth-0.0.50 → simple_module_auth-0.0.51}/auth/oidc_common/persistence.py +0 -0
- {simple_module_auth-0.0.50 → simple_module_auth-0.0.51}/auth/oidc_common/renewal.py +0 -0
- {simple_module_auth-0.0.50 → simple_module_auth-0.0.51}/auth/oidc_common/renewal_outcomes.py +0 -0
- {simple_module_auth-0.0.50 → simple_module_auth-0.0.51}/auth/oidc_common/session.py +0 -0
- {simple_module_auth-0.0.50 → simple_module_auth-0.0.51}/auth/oidc_common/tenant.py +0 -0
- {simple_module_auth-0.0.50 → simple_module_auth-0.0.51}/auth/oidc_common/tokens.py +0 -0
- {simple_module_auth-0.0.50 → simple_module_auth-0.0.51}/auth/py.typed +0 -0
- {simple_module_auth-0.0.50 → simple_module_auth-0.0.51}/auth/web/__init__.py +0 -0
- {simple_module_auth-0.0.50 → simple_module_auth-0.0.51}/auth/web/_route_match.py +0 -0
- {simple_module_auth-0.0.50 → simple_module_auth-0.0.51}/auth/web/deps.py +0 -0
- {simple_module_auth-0.0.50 → simple_module_auth-0.0.51}/tests/conftest.py +0 -0
- {simple_module_auth-0.0.50 → simple_module_auth-0.0.51}/tests/contracts/events/test_auth_session_logout_events.py +0 -0
- {simple_module_auth-0.0.50 → simple_module_auth-0.0.51}/tests/contracts/provider/test_auth_provider_protocol.py +0 -0
- {simple_module_auth-0.0.50 → simple_module_auth-0.0.51}/tests/contracts/resolver/test_auth_resolver_registry.py +0 -0
- {simple_module_auth-0.0.50 → simple_module_auth-0.0.51}/tests/contracts/schemas/test_auth_user_context.py +0 -0
- {simple_module_auth-0.0.50 → simple_module_auth-0.0.51}/tests/contracts/tokens/test_auth_parse_bearer.py +0 -0
- {simple_module_auth-0.0.50 → simple_module_auth-0.0.51}/tests/core/audit/test_auth_audit_redaction.py +0 -0
- {simple_module_auth-0.0.50 → simple_module_auth-0.0.51}/tests/core/module/test_auth_module.py +0 -0
- {simple_module_auth-0.0.50 → simple_module_auth-0.0.51}/tests/oidc_common/authority/test_auth_oidc_authority.py +0 -0
- {simple_module_auth-0.0.50 → simple_module_auth-0.0.51}/tests/oidc_common/jwks/test_auth_oidc_jwks_cache.py +0 -0
- {simple_module_auth-0.0.50 → simple_module_auth-0.0.51}/tests/oidc_common/jwks/test_auth_oidc_jwt_hardening.py +0 -0
- {simple_module_auth-0.0.50 → simple_module_auth-0.0.51}/tests/oidc_common/renewal/test_auth_oidc_authority_outcomes.py +0 -0
- {simple_module_auth-0.0.50 → simple_module_auth-0.0.51}/tests/oidc_common/renewal/test_auth_oidc_concurrent_renewal.py +0 -0
- {simple_module_auth-0.0.50 → simple_module_auth-0.0.51}/tests/oidc_common/renewal/test_auth_oidc_outcome_logout.py +0 -0
- {simple_module_auth-0.0.50 → simple_module_auth-0.0.51}/tests/oidc_common/renewal/test_auth_oidc_outcome_migration.py +0 -0
- {simple_module_auth-0.0.50 → simple_module_auth-0.0.51}/tests/oidc_common/session/test_auth_oidc_session_resolution.py +0 -0
- {simple_module_auth-0.0.50 → simple_module_auth-0.0.51}/tests/oidc_common/session/test_auth_oidc_shared_helpers.py +0 -0
- {simple_module_auth-0.0.50 → simple_module_auth-0.0.51}/tests/oidc_common/session/test_auth_oidc_sign_in.py +0 -0
- {simple_module_auth-0.0.50 → simple_module_auth-0.0.51}/tests/oidc_common/tokens/test_auth_oidc_tokens.py +0 -0
- {simple_module_auth-0.0.50 → simple_module_auth-0.0.51}/tests/web/deps/test_auth_deps.py +0 -0
- {simple_module_auth-0.0.50 → simple_module_auth-0.0.51}/tests/web/middleware/test_auth_duck_typed_principal.py +0 -0
- {simple_module_auth-0.0.50 → simple_module_auth-0.0.51}/tests/web/middleware/test_auth_middleware.py +0 -0
- {simple_module_auth-0.0.50 → simple_module_auth-0.0.51}/tests/web/middleware/test_auth_next_target.py +0 -0
- {simple_module_auth-0.0.50 → simple_module_auth-0.0.51}/tests/web/middleware/test_auth_unknown_paths.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: simple_module_auth
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.51
|
|
4
4
|
Summary: Session-cookie authentication primitives — middleware, login/logout, redirect helpers for simple_module
|
|
5
5
|
Project-URL: Homepage, https://github.com/antosubash/simple_module_python
|
|
6
6
|
Project-URL: Repository, https://github.com/antosubash/simple_module_python
|
|
@@ -25,9 +25,9 @@ Requires-Dist: cryptography>=42
|
|
|
25
25
|
Requires-Dist: httpx<0.29,>=0.27
|
|
26
26
|
Requires-Dist: itsdangerous<3,>=2.2
|
|
27
27
|
Requires-Dist: pyjwt[crypto]<3,>=2.8
|
|
28
|
-
Requires-Dist: simple-module-core==0.0.
|
|
29
|
-
Requires-Dist: simple-module-db==0.0.
|
|
30
|
-
Requires-Dist: simple-module-hosting==0.0.
|
|
28
|
+
Requires-Dist: simple-module-core==0.0.51
|
|
29
|
+
Requires-Dist: simple-module-db==0.0.51
|
|
30
|
+
Requires-Dist: simple-module-hosting==0.0.51
|
|
31
31
|
Description-Content-Type: text/markdown
|
|
32
32
|
|
|
33
33
|
# simple_module_auth
|
|
@@ -21,7 +21,7 @@ class AccountLike(Protocol):
|
|
|
21
21
|
"""
|
|
22
22
|
|
|
23
23
|
id: Any
|
|
24
|
-
email: str
|
|
24
|
+
email: str | None
|
|
25
25
|
full_name: str | None
|
|
26
26
|
roles: Iterable[NamedRole]
|
|
27
27
|
|
|
@@ -87,11 +87,12 @@ class UserContext:
|
|
|
87
87
|
generic provider's claim path sets it).
|
|
88
88
|
The caller is responsible for eager-loading roles (selectinload).
|
|
89
89
|
"""
|
|
90
|
+
email = user.email or ""
|
|
90
91
|
return cls(
|
|
91
92
|
id=str(user.id),
|
|
92
|
-
email=
|
|
93
|
-
email_verified=getattr(user, "is_verified", False) is True,
|
|
94
|
-
name=user.full_name or
|
|
93
|
+
email=email,
|
|
94
|
+
email_verified=bool(email) and getattr(user, "is_verified", False) is True,
|
|
95
|
+
name=user.full_name or email,
|
|
95
96
|
roles=[r.name for r in user.roles],
|
|
96
97
|
auth_kind=auth_kind,
|
|
97
98
|
scopes=list(scopes) if scopes is not None else None,
|
|
@@ -9,7 +9,7 @@ principal-resolver registry. Apps register additional resolvers from their
|
|
|
9
9
|
|
|
10
10
|
from __future__ import annotations
|
|
11
11
|
|
|
12
|
-
from collections.abc import Callable
|
|
12
|
+
from collections.abc import Awaitable, Callable
|
|
13
13
|
from dataclasses import dataclass, field
|
|
14
14
|
from typing import TYPE_CHECKING
|
|
15
15
|
|
|
@@ -30,9 +30,11 @@ class AuthState:
|
|
|
30
30
|
principal_resolvers: list[PrincipalResolver] = field(default_factory=list)
|
|
31
31
|
# Run once a principal has resolved (any credential source), before downstream
|
|
32
32
|
# middleware; anonymous requests never reach them.
|
|
33
|
-
# A guard is a sync callable returning a refusal response or None to continue.
|
|
33
|
+
# A guard is a sync or async callable returning a refusal response or None to continue.
|
|
34
34
|
# An exception propagates (a 500), so a broken guard fails closed, never open.
|
|
35
|
-
principal_guards: list[Callable[[Request], Response | None]] =
|
|
35
|
+
principal_guards: list[Callable[[Request], Response | Awaitable[Response | None] | None]] = (
|
|
36
|
+
field(default_factory=list)
|
|
37
|
+
)
|
|
36
38
|
|
|
37
39
|
|
|
38
40
|
__all__ = ["AuthState"]
|
|
@@ -8,6 +8,7 @@ principal-resolver chain. Sets ``request.state.user`` and the
|
|
|
8
8
|
|
|
9
9
|
from __future__ import annotations
|
|
10
10
|
|
|
11
|
+
import inspect
|
|
11
12
|
import logging
|
|
12
13
|
from urllib.parse import urlsplit
|
|
13
14
|
|
|
@@ -177,6 +178,8 @@ class AuthMiddleware:
|
|
|
177
178
|
request.state.user = user_ctx
|
|
178
179
|
for guard in auth_state.principal_guards:
|
|
179
180
|
refusal = guard(request)
|
|
181
|
+
if inspect.isawaitable(refusal):
|
|
182
|
+
refusal = await refusal
|
|
180
183
|
if refusal is not None:
|
|
181
184
|
await refusal(scope, receive, send)
|
|
182
185
|
return
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "simple_module_auth"
|
|
3
|
-
version = "0.0.
|
|
3
|
+
version = "0.0.51"
|
|
4
4
|
description = "Session-cookie authentication primitives — middleware, login/logout, redirect helpers for simple_module"
|
|
5
5
|
readme = "README.md"
|
|
6
6
|
license = "MIT"
|
|
@@ -25,9 +25,9 @@ dependencies = [
|
|
|
25
25
|
"PyJWT[crypto]>=2.8,<3",
|
|
26
26
|
"cryptography>=42",
|
|
27
27
|
"httpx>=0.27,<0.29",
|
|
28
|
-
"simple_module_core==0.0.
|
|
29
|
-
"simple_module_db==0.0.
|
|
30
|
-
"simple_module_hosting==0.0.
|
|
28
|
+
"simple_module_core==0.0.51",
|
|
29
|
+
"simple_module_db==0.0.51",
|
|
30
|
+
"simple_module_hosting==0.0.51",
|
|
31
31
|
]
|
|
32
32
|
|
|
33
33
|
[project.entry-points.simple_module]
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"""Mixed sync and async principal_guards ordering and short-circuiting."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import httpx
|
|
6
|
+
from auth.contracts.schemas import UserContext
|
|
7
|
+
from auth.core.state import AuthState
|
|
8
|
+
from auth.web.middleware import AuthMiddleware
|
|
9
|
+
from fastapi import FastAPI
|
|
10
|
+
from simple_module_core.web.public_routes import PublicRouteRegistry
|
|
11
|
+
from starlette.middleware.sessions import SessionMiddleware
|
|
12
|
+
from starlette.responses import JSONResponse
|
|
13
|
+
|
|
14
|
+
_USER = UserContext(id="u-1", email="u@example.com", name="Test User", roles=["user"])
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class _Provider:
|
|
18
|
+
async def resolve_user(self, request):
|
|
19
|
+
return _USER
|
|
20
|
+
|
|
21
|
+
def get_login_url(self, request, next_url=None):
|
|
22
|
+
return "/login"
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def _make_app(guards):
|
|
26
|
+
app = FastAPI()
|
|
27
|
+
app.state.public_routes = PublicRouteRegistry()
|
|
28
|
+
app.state.auth = AuthState(auth_provider=_Provider(), principal_guards=list(guards))
|
|
29
|
+
|
|
30
|
+
@app.post("/api/action")
|
|
31
|
+
async def action():
|
|
32
|
+
return {"ok": True}
|
|
33
|
+
|
|
34
|
+
app.add_middleware(AuthMiddleware)
|
|
35
|
+
app.add_middleware(SessionMiddleware, secret_key="s" * 32)
|
|
36
|
+
return app
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
async def test_principal_guards_run_sync_and_async_in_order_and_short_circuit():
|
|
40
|
+
order: list[str] = []
|
|
41
|
+
|
|
42
|
+
def sync_allow(request):
|
|
43
|
+
order.append("sync_allow")
|
|
44
|
+
return
|
|
45
|
+
|
|
46
|
+
async def async_refuse(request):
|
|
47
|
+
order.append("async_refuse")
|
|
48
|
+
return JSONResponse({"detail": "BLOCKED"}, status_code=403)
|
|
49
|
+
|
|
50
|
+
def never_called(request):
|
|
51
|
+
order.append("never_called")
|
|
52
|
+
return
|
|
53
|
+
|
|
54
|
+
app = _make_app([sync_allow, async_refuse, never_called])
|
|
55
|
+
async with httpx.AsyncClient(
|
|
56
|
+
transport=httpx.ASGITransport(app=app), base_url="http://test"
|
|
57
|
+
) as client:
|
|
58
|
+
res = await client.post("/api/action")
|
|
59
|
+
|
|
60
|
+
assert res.status_code == 403
|
|
61
|
+
assert res.json() == {"detail": "BLOCKED"}
|
|
62
|
+
assert order == ["sync_allow", "async_refuse"]
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
async def test_principal_guards_pass_when_all_sync_and_async_return_none():
|
|
66
|
+
order: list[str] = []
|
|
67
|
+
|
|
68
|
+
async def async_ok(request):
|
|
69
|
+
order.append("async_ok")
|
|
70
|
+
return
|
|
71
|
+
|
|
72
|
+
def sync_ok(request):
|
|
73
|
+
order.append("sync_ok")
|
|
74
|
+
return
|
|
75
|
+
|
|
76
|
+
app = _make_app([async_ok, sync_ok])
|
|
77
|
+
async with httpx.AsyncClient(
|
|
78
|
+
transport=httpx.ASGITransport(app=app), base_url="http://test"
|
|
79
|
+
) as client:
|
|
80
|
+
res = await client.post("/api/action")
|
|
81
|
+
|
|
82
|
+
assert res.status_code == 200
|
|
83
|
+
assert order == ["async_ok", "sync_ok"]
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{simple_module_auth-0.0.50 → simple_module_auth-0.0.51}/auth/oidc_common/renewal_outcomes.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{simple_module_auth-0.0.50 → simple_module_auth-0.0.51}/tests/core/module/test_auth_module.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{simple_module_auth-0.0.50 → simple_module_auth-0.0.51}/tests/web/middleware/test_auth_middleware.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|