simple-module-oidc 0.0.48__tar.gz → 0.0.50__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_oidc-0.0.48 → simple_module_oidc-0.0.50}/PKG-INFO +5 -5
- {simple_module_oidc-0.0.48 → simple_module_oidc-0.0.50}/oidc/core/settings.py +4 -4
- {simple_module_oidc-0.0.48 → simple_module_oidc-0.0.50}/oidc/identity/provider.py +10 -16
- simple_module_oidc-0.0.50/oidc/locales/de.json +84 -0
- simple_module_oidc-0.0.50/oidc/locales/en.json +84 -0
- {simple_module_oidc-0.0.48 → simple_module_oidc-0.0.50}/oidc/models.py +2 -2
- {simple_module_oidc-0.0.48 → simple_module_oidc-0.0.50}/oidc/module.py +5 -5
- simple_module_oidc-0.0.50/oidc/pages/i18n.generated.ts +138 -0
- {simple_module_oidc-0.0.48 → simple_module_oidc-0.0.50}/oidc/web/endpoints/api.py +1 -1
- {simple_module_oidc-0.0.48 → simple_module_oidc-0.0.50}/oidc/web/endpoints/views.py +20 -7
- {simple_module_oidc-0.0.48 → simple_module_oidc-0.0.50}/pyproject.toml +5 -5
- {simple_module_oidc-0.0.48 → simple_module_oidc-0.0.50}/tests/conftest.py +6 -6
- {simple_module_oidc-0.0.48 → simple_module_oidc-0.0.50}/tests/core/module/test_oidc_module.py +1 -1
- {simple_module_oidc-0.0.48 → simple_module_oidc-0.0.50}/tests/core/runtime/test_oidc_settings_runtime.py +1 -1
- {simple_module_oidc-0.0.48 → simple_module_oidc-0.0.50}/tests/identity/directory/test_oidc_directory.py +2 -2
- {simple_module_oidc-0.0.48 → simple_module_oidc-0.0.50}/tests/identity/renewal/test_oidc_session_transaction.py +3 -3
- {simple_module_oidc-0.0.48 → simple_module_oidc-0.0.50}/tests/web/endpoints/test_oidc_keycloak_flow.py +1 -1
- {simple_module_oidc-0.0.48 → simple_module_oidc-0.0.50}/tests/web/endpoints/test_oidc_logout.py +35 -1
- simple_module_oidc-0.0.50/tests/web/endpoints/test_oidc_logout_event_identity.py +253 -0
- simple_module_oidc-0.0.48/oidc/locales/de.json +0 -14
- simple_module_oidc-0.0.48/oidc/locales/en.json +0 -14
- simple_module_oidc-0.0.48/oidc/pages/i18n.generated.ts +0 -34
- {simple_module_oidc-0.0.48 → simple_module_oidc-0.0.50}/.gitignore +0 -0
- {simple_module_oidc-0.0.48 → simple_module_oidc-0.0.50}/README.md +0 -0
- {simple_module_oidc-0.0.48 → simple_module_oidc-0.0.50}/oidc/__init__.py +0 -0
- {simple_module_oidc-0.0.48 → simple_module_oidc-0.0.50}/oidc/contracts/__init__.py +0 -0
- {simple_module_oidc-0.0.48 → simple_module_oidc-0.0.50}/oidc/core/__init__.py +0 -0
- {simple_module_oidc-0.0.48 → simple_module_oidc-0.0.50}/oidc/core/constants.py +0 -0
- {simple_module_oidc-0.0.48 → simple_module_oidc-0.0.50}/oidc/core/presets.py +0 -0
- {simple_module_oidc-0.0.48 → simple_module_oidc-0.0.50}/oidc/core/runtime.py +0 -0
- {simple_module_oidc-0.0.48 → simple_module_oidc-0.0.50}/oidc/core/state.py +0 -0
- {simple_module_oidc-0.0.48 → simple_module_oidc-0.0.50}/oidc/identity/__init__.py +0 -0
- {simple_module_oidc-0.0.48 → simple_module_oidc-0.0.50}/oidc/identity/client.py +0 -0
- {simple_module_oidc-0.0.48 → simple_module_oidc-0.0.50}/oidc/identity/directory.py +0 -0
- {simple_module_oidc-0.0.48 → simple_module_oidc-0.0.50}/oidc/identity/discovery.py +0 -0
- {simple_module_oidc-0.0.48 → simple_module_oidc-0.0.50}/oidc/identity/jwks.py +0 -0
- {simple_module_oidc-0.0.48 → simple_module_oidc-0.0.50}/oidc/identity/persistence.py +0 -0
- {simple_module_oidc-0.0.48 → simple_module_oidc-0.0.50}/oidc/identity/renewal.py +0 -0
- {simple_module_oidc-0.0.48 → simple_module_oidc-0.0.50}/oidc/identity/tokens.py +0 -0
- {simple_module_oidc-0.0.48 → simple_module_oidc-0.0.50}/oidc/pages/LoggedOut.tsx +0 -0
- {simple_module_oidc-0.0.48 → simple_module_oidc-0.0.50}/oidc/pages/Login.tsx +0 -0
- {simple_module_oidc-0.0.48 → simple_module_oidc-0.0.50}/oidc/py.typed +0 -0
- {simple_module_oidc-0.0.48 → simple_module_oidc-0.0.50}/oidc/web/__init__.py +0 -0
- {simple_module_oidc-0.0.48 → simple_module_oidc-0.0.50}/oidc/web/endpoints/__init__.py +0 -0
- {simple_module_oidc-0.0.48 → simple_module_oidc-0.0.50}/package.json +0 -0
- {simple_module_oidc-0.0.48 → simple_module_oidc-0.0.50}/tests/core/module/test_oidc_boot.py +0 -0
- {simple_module_oidc-0.0.48 → simple_module_oidc-0.0.50}/tests/core/module/test_oidc_migration.py +0 -0
- {simple_module_oidc-0.0.48 → simple_module_oidc-0.0.50}/tests/core/settings/test_oidc_settings_presets.py +0 -0
- {simple_module_oidc-0.0.48 → simple_module_oidc-0.0.50}/tests/identity/client/test_oidc_client.py +0 -0
- {simple_module_oidc-0.0.48 → simple_module_oidc-0.0.50}/tests/identity/discovery/test_oidc_discovery.py +0 -0
- {simple_module_oidc-0.0.48 → simple_module_oidc-0.0.50}/tests/identity/jwks/test_oidc_jwks.py +0 -0
- {simple_module_oidc-0.0.48 → simple_module_oidc-0.0.50}/tests/identity/jwks/test_oidc_jwks_resilience.py +0 -0
- {simple_module_oidc-0.0.48 → simple_module_oidc-0.0.50}/tests/identity/persistence/test_oidc_cache_persistence.py +0 -0
- {simple_module_oidc-0.0.48 → simple_module_oidc-0.0.50}/tests/identity/provider/test_oidc_bearer_policy.py +0 -0
- {simple_module_oidc-0.0.48 → simple_module_oidc-0.0.50}/tests/identity/provider/test_oidc_jwt_policy.py +0 -0
- {simple_module_oidc-0.0.48 → simple_module_oidc-0.0.50}/tests/identity/provider/test_oidc_legacy_authority.py +0 -0
- {simple_module_oidc-0.0.48 → simple_module_oidc-0.0.50}/tests/identity/provider/test_oidc_provider.py +0 -0
- {simple_module_oidc-0.0.48 → simple_module_oidc-0.0.50}/tests/identity/provider/test_oidc_sign_in_from_claims.py +0 -0
- {simple_module_oidc-0.0.48 → simple_module_oidc-0.0.50}/tests/identity/provider/test_oidc_tenant_resolver.py +0 -0
- {simple_module_oidc-0.0.48 → simple_module_oidc-0.0.50}/tests/identity/renewal/test_oidc_refresh.py +0 -0
- {simple_module_oidc-0.0.48 → simple_module_oidc-0.0.50}/tests/oidc_flow_helpers.py +0 -0
- {simple_module_oidc-0.0.48 → simple_module_oidc-0.0.50}/tests/web/endpoints/test_oidc_authorization.py +0 -0
- {simple_module_oidc-0.0.48 → simple_module_oidc-0.0.50}/tests/web/endpoints/test_oidc_authorization_query.py +0 -0
- {simple_module_oidc-0.0.48 → simple_module_oidc-0.0.50}/tests/web/endpoints/test_oidc_endpoint_auth.py +0 -0
- {simple_module_oidc-0.0.48 → simple_module_oidc-0.0.50}/tests/web/endpoints/test_oidc_flow.py +0 -0
- {simple_module_oidc-0.0.48 → simple_module_oidc-0.0.50}/tests-js/oidc-login.test.tsx +0 -0
- {simple_module_oidc-0.0.48 → simple_module_oidc-0.0.50}/tests-js/oidc-translations.test.tsx +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: simple_module_oidc
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.50
|
|
4
4
|
Summary: Generic OIDC authentication provider for simple_module — native Microsoft Entra ID, Auth0, Okta, Keycloak, and any OpenID Connect identity provider
|
|
5
5
|
Project-URL: Homepage, https://github.com/antosubash/simple_module_python
|
|
6
6
|
Project-URL: Repository, https://github.com/antosubash/simple_module_python
|
|
@@ -21,10 +21,10 @@ Requires-Python: >=3.12
|
|
|
21
21
|
Requires-Dist: cryptography>=42
|
|
22
22
|
Requires-Dist: httpx<0.29,>=0.27
|
|
23
23
|
Requires-Dist: pyjwt[crypto]<3,>=2.8
|
|
24
|
-
Requires-Dist: simple-module-auth==0.0.
|
|
25
|
-
Requires-Dist: simple-module-core==0.0.
|
|
26
|
-
Requires-Dist: simple-module-db==0.0.
|
|
27
|
-
Requires-Dist: simple-module-hosting==0.0.
|
|
24
|
+
Requires-Dist: simple-module-auth==0.0.50
|
|
25
|
+
Requires-Dist: simple-module-core==0.0.50
|
|
26
|
+
Requires-Dist: simple-module-db==0.0.50
|
|
27
|
+
Requires-Dist: simple-module-hosting==0.0.50
|
|
28
28
|
Description-Content-Type: text/markdown
|
|
29
29
|
|
|
30
30
|
# simple_module_oidc
|
|
@@ -11,10 +11,10 @@ import os
|
|
|
11
11
|
|
|
12
12
|
from pydantic import Field, model_validator
|
|
13
13
|
from pydantic_settings import SettingsConfigDict
|
|
14
|
-
from simple_module_core.dotenv import env_str
|
|
15
|
-
from simple_module_core.environments import NON_PROD_ENVIRONMENTS
|
|
16
|
-
from simple_module_core.settings_base import DbBackedSettings
|
|
17
|
-
from simple_module_core.stored_settings import field_error
|
|
14
|
+
from simple_module_core.settings.dotenv import env_str
|
|
15
|
+
from simple_module_core.settings.environments import NON_PROD_ENVIRONMENTS
|
|
16
|
+
from simple_module_core.settings.settings_base import DbBackedSettings
|
|
17
|
+
from simple_module_core.settings.stored_settings import field_error
|
|
18
18
|
|
|
19
19
|
from oidc.core.presets import get_preset
|
|
20
20
|
|
|
@@ -8,8 +8,9 @@ from typing import TYPE_CHECKING, Any
|
|
|
8
8
|
from auth.contracts.schemas import UserContext
|
|
9
9
|
from auth.contracts.tokens import AUTH_KIND_BEARER, is_api_token, parse_bearer
|
|
10
10
|
from auth.oidc_common.claims import extract_nested as _extract_nested
|
|
11
|
+
from auth.oidc_common.session import SessionResolution
|
|
11
12
|
from auth.oidc_common.tenant import trusted_tenant, without_tenant_roles
|
|
12
|
-
from simple_module_hosting.session import SESSION_EXPIRES_AT_KEY
|
|
13
|
+
from simple_module_hosting.pipeline.session import SESSION_EXPIRES_AT_KEY
|
|
13
14
|
from starlette.requests import Request
|
|
14
15
|
|
|
15
16
|
from oidc.core.constants import LOGIN_PATH, LOGOUT_PATH, SESSION_USER_KEY
|
|
@@ -28,10 +29,11 @@ class IdentityUnavailableError(Exception):
|
|
|
28
29
|
"""The user cache could not record the signed-in identity."""
|
|
29
30
|
|
|
30
31
|
|
|
31
|
-
class OidcAuthProvider(CachePersistence, SessionRenewal):
|
|
32
|
+
class OidcAuthProvider(SessionResolution, CachePersistence, SessionRenewal):
|
|
32
33
|
"""Generic OIDC authentication with issuer-scoped identities."""
|
|
33
34
|
|
|
34
35
|
name = "oidc"
|
|
36
|
+
_session_user_key = SESSION_USER_KEY
|
|
35
37
|
|
|
36
38
|
def __init__(
|
|
37
39
|
self, settings: OidcSettings | None = None, *, state: OidcState | None = None
|
|
@@ -58,20 +60,12 @@ class OidcAuthProvider(CachePersistence, SessionRenewal):
|
|
|
58
60
|
return None
|
|
59
61
|
return await self._resolve_bearer(request, credential)
|
|
60
62
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
ctx = UserContext.from_session_dict(session.get(SESSION_USER_KEY))
|
|
68
|
-
if ctx is not None:
|
|
69
|
-
# The cookie froze what was decided at login; re-decide with the
|
|
70
|
-
# current settings, so turning trust_tenant_claim off takes effect
|
|
71
|
-
# on sessions that already exist.
|
|
72
|
-
ctx.tenant_id = self._trusted_tenant(ctx.tenant_id)
|
|
73
|
-
ctx.roles = self._without_tenant_roles(ctx.roles)
|
|
74
|
-
return ctx
|
|
63
|
+
return await self.resolve_session(request)
|
|
64
|
+
|
|
65
|
+
def _session_needs_renewal(self, session: dict[str, Any]) -> bool:
|
|
66
|
+
return type(
|
|
67
|
+
session.get(SESSION_EXPIRES_AT_KEY)
|
|
68
|
+
) is not int or super()._session_needs_renewal(session)
|
|
75
69
|
|
|
76
70
|
def get_login_url(self, request: Request | None, next_url: str | None = None) -> str:
|
|
77
71
|
return LOGIN_PATH
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
{
|
|
2
|
+
"login": {
|
|
3
|
+
"redirecting": "Weiterleitung zum Identitätsanbieter…",
|
|
4
|
+
"manual": "Keine Weiterleitung? Manuell fortfahren"
|
|
5
|
+
},
|
|
6
|
+
"logout": {
|
|
7
|
+
"title": "Abgemeldet",
|
|
8
|
+
"message": "Sie wurden erfolgreich von dieser App abgemeldet.",
|
|
9
|
+
"sign_in_again": "Erneut anmelden"
|
|
10
|
+
},
|
|
11
|
+
"nav": {
|
|
12
|
+
"logout": "Abmelden"
|
|
13
|
+
},
|
|
14
|
+
"settings_form": {
|
|
15
|
+
"title": "Anmeldung (OIDC)",
|
|
16
|
+
"description": "Verbindung zu Ihrem OpenID-Connect-Anbieter, Claim-Zuordnung und API-Zugriff.",
|
|
17
|
+
"fields": {
|
|
18
|
+
"provider": {
|
|
19
|
+
"label": "Anbieter",
|
|
20
|
+
"help": "Welche Anbieter-Vorlage verwendet wird, etwa Entra oder ein generischer OIDC-Anbieter. Eine Änderung erfordert einen Neustart."
|
|
21
|
+
},
|
|
22
|
+
"discovery_url": {
|
|
23
|
+
"label": "Discovery-URL",
|
|
24
|
+
"help": "Adresse des Discovery-Dokuments des Anbieters. Leer: wird, wo der Anbieter es unterstützt, aus der Tenant-ID abgeleitet."
|
|
25
|
+
},
|
|
26
|
+
"tenant_id": {
|
|
27
|
+
"label": "Tenant-ID",
|
|
28
|
+
"help": "ID des Verzeichnisses (Tenant) für Anbieter wie Entra. Nur Single-Tenant."
|
|
29
|
+
},
|
|
30
|
+
"client_id": {
|
|
31
|
+
"label": "Client-ID",
|
|
32
|
+
"help": "ID des Clients, der für diese Anwendung beim Anbieter registriert ist."
|
|
33
|
+
},
|
|
34
|
+
"client_secret": {
|
|
35
|
+
"label": "Client-Secret",
|
|
36
|
+
"help": "Geheimnis dieses Clients. Nach dem Speichern wird es ausgeblendet."
|
|
37
|
+
},
|
|
38
|
+
"api_audience": {
|
|
39
|
+
"label": "API-Audience",
|
|
40
|
+
"help": "Audience, die Bearer-Tokens für die API haben müssen. Leer lassen, um die Bearer-Authentifizierung auszuschalten."
|
|
41
|
+
},
|
|
42
|
+
"api_allowed_client_ids": {
|
|
43
|
+
"label": "Erlaubte API-Clients",
|
|
44
|
+
"help": "Client-IDs außer dem der Anwendung selbst, die die API mit einem Bearer-Token aufrufen dürfen. Leer: nur der Client dieser Anwendung."
|
|
45
|
+
},
|
|
46
|
+
"trust_tenant_claim": {
|
|
47
|
+
"label": "Mandanten-Claim in Tokens vertrauen",
|
|
48
|
+
"help": "Den im Token genannten Mandanten verwenden. Nur aktivieren, wenn Benutzer diesen Claim nicht beeinflussen können."
|
|
49
|
+
},
|
|
50
|
+
"scope": {
|
|
51
|
+
"label": "Scopes",
|
|
52
|
+
"help": "Beim Anmelden angeforderte Scopes. Unverändert lassen, um die Vorgabe des Anbieters zu nutzen."
|
|
53
|
+
},
|
|
54
|
+
"uid_claim": {
|
|
55
|
+
"label": "Claim für die Benutzer-ID",
|
|
56
|
+
"help": "Token-Claim, der den Benutzer eindeutig identifiziert."
|
|
57
|
+
},
|
|
58
|
+
"username_claim": {
|
|
59
|
+
"label": "Claim für den Benutzernamen",
|
|
60
|
+
"help": "Token-Claim, der zuerst für den angezeigten Namen geprüft wird."
|
|
61
|
+
},
|
|
62
|
+
"email_claim": {
|
|
63
|
+
"label": "Claim für die E-Mail-Adresse",
|
|
64
|
+
"help": "Token-Claim mit der E-Mail-Adresse."
|
|
65
|
+
},
|
|
66
|
+
"name_claim": {
|
|
67
|
+
"label": "Claim für den Anzeigenamen",
|
|
68
|
+
"help": "Token-Claim für den angezeigten Namen, wenn der Benutzername-Claim fehlt oder leer ist."
|
|
69
|
+
},
|
|
70
|
+
"roles_claim_path": {
|
|
71
|
+
"label": "Pfad des Rollen-Claims",
|
|
72
|
+
"help": "Wo die Rollenliste im Token steht, als Punkt-Pfad angegeben."
|
|
73
|
+
},
|
|
74
|
+
"jwks_cache_ttl_seconds": {
|
|
75
|
+
"label": "Cache-Dauer der Signaturschlüssel (Sekunden)",
|
|
76
|
+
"help": "Wie lange die Signaturschlüssel des Anbieters wiederverwendet werden, bevor sie neu geladen werden. Bei 0 werden sie bei Bedarf neu geladen, höchstens alle 30 Sekunden; schlägt das fehl, bleibt der letzte gültige Satz in Gebrauch."
|
|
77
|
+
},
|
|
78
|
+
"role_mapping": {
|
|
79
|
+
"label": "Rollenzuordnung",
|
|
80
|
+
"help": "Ordnet Rollennamen des Anbieters den anwendungsweiten Rollen dieser App zu. Mandantenrollen kommen aus Mitgliedschaften."
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
{
|
|
2
|
+
"login": {
|
|
3
|
+
"redirecting": "Redirecting to identity provider\u2026",
|
|
4
|
+
"manual": "Not redirected? Continue manually"
|
|
5
|
+
},
|
|
6
|
+
"logout": {
|
|
7
|
+
"title": "Signed Out",
|
|
8
|
+
"message": "You have been signed out successfully.",
|
|
9
|
+
"sign_in_again": "Sign in again"
|
|
10
|
+
},
|
|
11
|
+
"nav": {
|
|
12
|
+
"logout": "Logout"
|
|
13
|
+
},
|
|
14
|
+
"settings_form": {
|
|
15
|
+
"title": "Sign-in (OIDC)",
|
|
16
|
+
"description": "Connection to your OpenID Connect provider, claim mapping and API access.",
|
|
17
|
+
"fields": {
|
|
18
|
+
"provider": {
|
|
19
|
+
"label": "Provider",
|
|
20
|
+
"help": "Which provider preset to use, such as Entra or a generic OIDC provider. Changing it needs a restart."
|
|
21
|
+
},
|
|
22
|
+
"discovery_url": {
|
|
23
|
+
"label": "Discovery URL",
|
|
24
|
+
"help": "Address of the provider's discovery document. If blank, it is derived from the tenant ID where the provider supports that."
|
|
25
|
+
},
|
|
26
|
+
"tenant_id": {
|
|
27
|
+
"label": "Tenant ID",
|
|
28
|
+
"help": "Directory (tenant) ID for providers such as Entra. Single-tenant only."
|
|
29
|
+
},
|
|
30
|
+
"client_id": {
|
|
31
|
+
"label": "Client ID",
|
|
32
|
+
"help": "ID of the client registered for this app at the provider."
|
|
33
|
+
},
|
|
34
|
+
"client_secret": {
|
|
35
|
+
"label": "Client secret",
|
|
36
|
+
"help": "Secret of that client. It is hidden once saved."
|
|
37
|
+
},
|
|
38
|
+
"api_audience": {
|
|
39
|
+
"label": "API audience",
|
|
40
|
+
"help": "Audience that bearer tokens for the API must have. Leave blank to turn off bearer authentication."
|
|
41
|
+
},
|
|
42
|
+
"api_allowed_client_ids": {
|
|
43
|
+
"label": "Allowed API clients",
|
|
44
|
+
"help": "Client IDs besides this app's own that may call the API with a bearer token. Empty: only this app's client."
|
|
45
|
+
},
|
|
46
|
+
"trust_tenant_claim": {
|
|
47
|
+
"label": "Trust tenant claim in tokens",
|
|
48
|
+
"help": "Use the tenant named in the token. Only enable if users cannot influence that claim."
|
|
49
|
+
},
|
|
50
|
+
"scope": {
|
|
51
|
+
"label": "Scopes",
|
|
52
|
+
"help": "Scopes requested at sign-in. Leave as is to use the provider preset."
|
|
53
|
+
},
|
|
54
|
+
"uid_claim": {
|
|
55
|
+
"label": "User ID claim",
|
|
56
|
+
"help": "Token claim that uniquely identifies the user."
|
|
57
|
+
},
|
|
58
|
+
"username_claim": {
|
|
59
|
+
"label": "Username claim",
|
|
60
|
+
"help": "Token claim checked first for the name the app displays."
|
|
61
|
+
},
|
|
62
|
+
"email_claim": {
|
|
63
|
+
"label": "Email claim",
|
|
64
|
+
"help": "Token claim holding the email address."
|
|
65
|
+
},
|
|
66
|
+
"name_claim": {
|
|
67
|
+
"label": "Display name claim",
|
|
68
|
+
"help": "Token claim used for the displayed name when the username claim is missing or empty."
|
|
69
|
+
},
|
|
70
|
+
"roles_claim_path": {
|
|
71
|
+
"label": "Roles claim path",
|
|
72
|
+
"help": "Where the list of roles sits inside the token, written as a dotted path."
|
|
73
|
+
},
|
|
74
|
+
"jwks_cache_ttl_seconds": {
|
|
75
|
+
"label": "Signing key cache lifetime (seconds)",
|
|
76
|
+
"help": "How long the provider's signing keys are reused before being fetched again. With 0 they are refetched on demand, at most every 30 seconds, and the last good set is kept if a fetch fails."
|
|
77
|
+
},
|
|
78
|
+
"role_mapping": {
|
|
79
|
+
"label": "Role mapping",
|
|
80
|
+
"help": "Maps role names from the provider to this app's app-wide roles. Tenant roles come from memberships."
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
@@ -5,8 +5,8 @@ from __future__ import annotations
|
|
|
5
5
|
import uuid as uuid_mod
|
|
6
6
|
from datetime import datetime
|
|
7
7
|
|
|
8
|
-
from simple_module_db.base import create_module_base
|
|
9
|
-
from simple_module_db.types import AwareDateTime
|
|
8
|
+
from simple_module_db.models.base import create_module_base
|
|
9
|
+
from simple_module_db.models.types import AwareDateTime
|
|
10
10
|
from sqlalchemy import UniqueConstraint
|
|
11
11
|
from sqlmodel import Field
|
|
12
12
|
|
|
@@ -4,11 +4,11 @@ from __future__ import annotations
|
|
|
4
4
|
|
|
5
5
|
from typing import TYPE_CHECKING
|
|
6
6
|
|
|
7
|
-
from simple_module_core.
|
|
8
|
-
from simple_module_core.
|
|
9
|
-
from simple_module_core.
|
|
10
|
-
from simple_module_core.
|
|
11
|
-
from simple_module_core.
|
|
7
|
+
from simple_module_core.access.role_directory import MappedRoleDirectory, set_role_directory
|
|
8
|
+
from simple_module_core.access.user_directory import set_user_directory
|
|
9
|
+
from simple_module_core.modules.module import ModuleBase, ModuleMeta
|
|
10
|
+
from simple_module_core.settings.module_settings import register_module_settings
|
|
11
|
+
from simple_module_core.web.menu import MenuItem, MenuRegistry, MenuSection
|
|
12
12
|
|
|
13
13
|
from oidc.core.constants import (
|
|
14
14
|
_MODULE_AUTH,
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import '@simple-module-py/i18n';
|
|
2
|
+
|
|
3
|
+
// AUTO-GENERATED by simple_module_hosting.i18n.i18n_manifest — do not edit by hand.
|
|
4
|
+
// Regenerate by booting the host in development mode or `make gen-i18n`.
|
|
5
|
+
|
|
6
|
+
export const keys = {
|
|
7
|
+
oidc: {
|
|
8
|
+
login: {
|
|
9
|
+
manual: 'oidc.login.manual',
|
|
10
|
+
redirecting: 'oidc.login.redirecting',
|
|
11
|
+
},
|
|
12
|
+
logout: {
|
|
13
|
+
message: 'oidc.logout.message',
|
|
14
|
+
sign_in_again: 'oidc.logout.sign_in_again',
|
|
15
|
+
title: 'oidc.logout.title',
|
|
16
|
+
},
|
|
17
|
+
nav: {
|
|
18
|
+
logout: 'oidc.nav.logout',
|
|
19
|
+
},
|
|
20
|
+
settings_form: {
|
|
21
|
+
description: 'oidc.settings_form.description',
|
|
22
|
+
fields: {
|
|
23
|
+
api_allowed_client_ids: {
|
|
24
|
+
help: 'oidc.settings_form.fields.api_allowed_client_ids.help',
|
|
25
|
+
label: 'oidc.settings_form.fields.api_allowed_client_ids.label',
|
|
26
|
+
},
|
|
27
|
+
api_audience: {
|
|
28
|
+
help: 'oidc.settings_form.fields.api_audience.help',
|
|
29
|
+
label: 'oidc.settings_form.fields.api_audience.label',
|
|
30
|
+
},
|
|
31
|
+
client_id: {
|
|
32
|
+
help: 'oidc.settings_form.fields.client_id.help',
|
|
33
|
+
label: 'oidc.settings_form.fields.client_id.label',
|
|
34
|
+
},
|
|
35
|
+
client_secret: {
|
|
36
|
+
help: 'oidc.settings_form.fields.client_secret.help',
|
|
37
|
+
label: 'oidc.settings_form.fields.client_secret.label',
|
|
38
|
+
},
|
|
39
|
+
discovery_url: {
|
|
40
|
+
help: 'oidc.settings_form.fields.discovery_url.help',
|
|
41
|
+
label: 'oidc.settings_form.fields.discovery_url.label',
|
|
42
|
+
},
|
|
43
|
+
email_claim: {
|
|
44
|
+
help: 'oidc.settings_form.fields.email_claim.help',
|
|
45
|
+
label: 'oidc.settings_form.fields.email_claim.label',
|
|
46
|
+
},
|
|
47
|
+
jwks_cache_ttl_seconds: {
|
|
48
|
+
help: 'oidc.settings_form.fields.jwks_cache_ttl_seconds.help',
|
|
49
|
+
label: 'oidc.settings_form.fields.jwks_cache_ttl_seconds.label',
|
|
50
|
+
},
|
|
51
|
+
name_claim: {
|
|
52
|
+
help: 'oidc.settings_form.fields.name_claim.help',
|
|
53
|
+
label: 'oidc.settings_form.fields.name_claim.label',
|
|
54
|
+
},
|
|
55
|
+
provider: {
|
|
56
|
+
help: 'oidc.settings_form.fields.provider.help',
|
|
57
|
+
label: 'oidc.settings_form.fields.provider.label',
|
|
58
|
+
},
|
|
59
|
+
role_mapping: {
|
|
60
|
+
help: 'oidc.settings_form.fields.role_mapping.help',
|
|
61
|
+
label: 'oidc.settings_form.fields.role_mapping.label',
|
|
62
|
+
},
|
|
63
|
+
roles_claim_path: {
|
|
64
|
+
help: 'oidc.settings_form.fields.roles_claim_path.help',
|
|
65
|
+
label: 'oidc.settings_form.fields.roles_claim_path.label',
|
|
66
|
+
},
|
|
67
|
+
scope: {
|
|
68
|
+
help: 'oidc.settings_form.fields.scope.help',
|
|
69
|
+
label: 'oidc.settings_form.fields.scope.label',
|
|
70
|
+
},
|
|
71
|
+
tenant_id: {
|
|
72
|
+
help: 'oidc.settings_form.fields.tenant_id.help',
|
|
73
|
+
label: 'oidc.settings_form.fields.tenant_id.label',
|
|
74
|
+
},
|
|
75
|
+
trust_tenant_claim: {
|
|
76
|
+
help: 'oidc.settings_form.fields.trust_tenant_claim.help',
|
|
77
|
+
label: 'oidc.settings_form.fields.trust_tenant_claim.label',
|
|
78
|
+
},
|
|
79
|
+
uid_claim: {
|
|
80
|
+
help: 'oidc.settings_form.fields.uid_claim.help',
|
|
81
|
+
label: 'oidc.settings_form.fields.uid_claim.label',
|
|
82
|
+
},
|
|
83
|
+
username_claim: {
|
|
84
|
+
help: 'oidc.settings_form.fields.username_claim.help',
|
|
85
|
+
label: 'oidc.settings_form.fields.username_claim.label',
|
|
86
|
+
},
|
|
87
|
+
},
|
|
88
|
+
title: 'oidc.settings_form.title',
|
|
89
|
+
},
|
|
90
|
+
},
|
|
91
|
+
} as const;
|
|
92
|
+
|
|
93
|
+
type ModuleTranslationResources = {
|
|
94
|
+
readonly 'oidc.login.manual': '';
|
|
95
|
+
readonly 'oidc.login.redirecting': '';
|
|
96
|
+
readonly 'oidc.logout.message': '';
|
|
97
|
+
readonly 'oidc.logout.sign_in_again': '';
|
|
98
|
+
readonly 'oidc.logout.title': '';
|
|
99
|
+
readonly 'oidc.nav.logout': '';
|
|
100
|
+
readonly 'oidc.settings_form.description': '';
|
|
101
|
+
readonly 'oidc.settings_form.fields.api_allowed_client_ids.help': '';
|
|
102
|
+
readonly 'oidc.settings_form.fields.api_allowed_client_ids.label': '';
|
|
103
|
+
readonly 'oidc.settings_form.fields.api_audience.help': '';
|
|
104
|
+
readonly 'oidc.settings_form.fields.api_audience.label': '';
|
|
105
|
+
readonly 'oidc.settings_form.fields.client_id.help': '';
|
|
106
|
+
readonly 'oidc.settings_form.fields.client_id.label': '';
|
|
107
|
+
readonly 'oidc.settings_form.fields.client_secret.help': '';
|
|
108
|
+
readonly 'oidc.settings_form.fields.client_secret.label': '';
|
|
109
|
+
readonly 'oidc.settings_form.fields.discovery_url.help': '';
|
|
110
|
+
readonly 'oidc.settings_form.fields.discovery_url.label': '';
|
|
111
|
+
readonly 'oidc.settings_form.fields.email_claim.help': '';
|
|
112
|
+
readonly 'oidc.settings_form.fields.email_claim.label': '';
|
|
113
|
+
readonly 'oidc.settings_form.fields.jwks_cache_ttl_seconds.help': '';
|
|
114
|
+
readonly 'oidc.settings_form.fields.jwks_cache_ttl_seconds.label': '';
|
|
115
|
+
readonly 'oidc.settings_form.fields.name_claim.help': '';
|
|
116
|
+
readonly 'oidc.settings_form.fields.name_claim.label': '';
|
|
117
|
+
readonly 'oidc.settings_form.fields.provider.help': '';
|
|
118
|
+
readonly 'oidc.settings_form.fields.provider.label': '';
|
|
119
|
+
readonly 'oidc.settings_form.fields.role_mapping.help': '';
|
|
120
|
+
readonly 'oidc.settings_form.fields.role_mapping.label': '';
|
|
121
|
+
readonly 'oidc.settings_form.fields.roles_claim_path.help': '';
|
|
122
|
+
readonly 'oidc.settings_form.fields.roles_claim_path.label': '';
|
|
123
|
+
readonly 'oidc.settings_form.fields.scope.help': '';
|
|
124
|
+
readonly 'oidc.settings_form.fields.scope.label': '';
|
|
125
|
+
readonly 'oidc.settings_form.fields.tenant_id.help': '';
|
|
126
|
+
readonly 'oidc.settings_form.fields.tenant_id.label': '';
|
|
127
|
+
readonly 'oidc.settings_form.fields.trust_tenant_claim.help': '';
|
|
128
|
+
readonly 'oidc.settings_form.fields.trust_tenant_claim.label': '';
|
|
129
|
+
readonly 'oidc.settings_form.fields.uid_claim.help': '';
|
|
130
|
+
readonly 'oidc.settings_form.fields.uid_claim.label': '';
|
|
131
|
+
readonly 'oidc.settings_form.fields.username_claim.help': '';
|
|
132
|
+
readonly 'oidc.settings_form.fields.username_claim.label': '';
|
|
133
|
+
readonly 'oidc.settings_form.title': '';
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
declare module '@simple-module-py/i18n' {
|
|
137
|
+
interface TranslationResources extends ModuleTranslationResources {}
|
|
138
|
+
}
|
|
@@ -8,7 +8,7 @@ import time
|
|
|
8
8
|
|
|
9
9
|
from auth.oidc_common.session import sign_in, stale_callback
|
|
10
10
|
from fastapi import APIRouter, HTTPException, Request
|
|
11
|
-
from simple_module_hosting.auth_policy import login_redirect_url
|
|
11
|
+
from simple_module_hosting.auth.auth_policy import login_redirect_url
|
|
12
12
|
from starlette.responses import RedirectResponse
|
|
13
13
|
|
|
14
14
|
from oidc.core.constants import (
|
|
@@ -2,11 +2,15 @@
|
|
|
2
2
|
|
|
3
3
|
import logging
|
|
4
4
|
|
|
5
|
+
from auth.oidc_common.logout import logout_event_for
|
|
5
6
|
from auth.oidc_common.renewal_outcomes import forget_outcomes
|
|
6
|
-
from fastapi import APIRouter, Request
|
|
7
|
-
from simple_module_hosting.
|
|
8
|
-
from simple_module_hosting.
|
|
9
|
-
from
|
|
7
|
+
from fastapi import APIRouter, Depends, Request
|
|
8
|
+
from simple_module_hosting.auth.api_equivalent import EXEMPT_LOGOUT, api_exempt
|
|
9
|
+
from simple_module_hosting.auth.auth_policy import login_redirect_url
|
|
10
|
+
from simple_module_hosting.auth.csrf import require_browser_origin
|
|
11
|
+
from simple_module_hosting.frontend.inertia_deps import InertiaDep, is_inertia_request
|
|
12
|
+
from simple_module_inertia.protocol.response import location
|
|
13
|
+
from starlette.background import BackgroundTask
|
|
10
14
|
from starlette.responses import RedirectResponse
|
|
11
15
|
|
|
12
16
|
from oidc.core.constants import (
|
|
@@ -16,6 +20,7 @@ from oidc.core.constants import (
|
|
|
16
20
|
SESSION_REFRESH_TOKEN_KEY,
|
|
17
21
|
)
|
|
18
22
|
from oidc.core.runtime import is_signed_in
|
|
23
|
+
from oidc.identity.provider import OidcAuthProvider
|
|
19
24
|
from oidc.identity.renewal import _KEYS
|
|
20
25
|
from oidc.identity.tokens import open_refresh_token
|
|
21
26
|
|
|
@@ -37,8 +42,12 @@ async def logged_out_page(request: Request, inertia: InertiaDep):
|
|
|
37
42
|
return await inertia.render(_PAGE_LOGGED_OUT)
|
|
38
43
|
|
|
39
44
|
|
|
40
|
-
@router.post(
|
|
45
|
+
@router.post(
|
|
46
|
+
"/logout",
|
|
47
|
+
dependencies=[Depends(require_browser_origin), Depends(api_exempt(EXEMPT_LOGOUT))],
|
|
48
|
+
)
|
|
41
49
|
async def logout(request: Request):
|
|
50
|
+
event = await logout_event_for(request, OidcAuthProvider)
|
|
42
51
|
client = request.app.state.oidc.client
|
|
43
52
|
if client is not None:
|
|
44
53
|
try:
|
|
@@ -61,5 +70,9 @@ async def logout(request: Request):
|
|
|
61
70
|
except Exception:
|
|
62
71
|
logger.warning("OIDC logout unavailable; local session cleared")
|
|
63
72
|
if is_inertia_request(request.scope):
|
|
64
|
-
|
|
65
|
-
|
|
73
|
+
response = location(destination)
|
|
74
|
+
else:
|
|
75
|
+
response = RedirectResponse(destination, status_code=303)
|
|
76
|
+
if event is not None:
|
|
77
|
+
response.background = BackgroundTask(request.app.state.sm.event_bus.publish, event)
|
|
78
|
+
return response
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "simple_module_oidc"
|
|
3
|
-
version = "0.0.
|
|
3
|
+
version = "0.0.50"
|
|
4
4
|
description = "Generic OIDC authentication provider for simple_module — native Microsoft Entra ID, Auth0, Okta, Keycloak, and any OpenID Connect identity provider"
|
|
5
5
|
readme = "README.md"
|
|
6
6
|
license = "MIT"
|
|
@@ -20,10 +20,10 @@ classifiers = [
|
|
|
20
20
|
"Typing :: Typed",
|
|
21
21
|
]
|
|
22
22
|
dependencies = [
|
|
23
|
-
"simple_module_core==0.0.
|
|
24
|
-
"simple_module_db==0.0.
|
|
25
|
-
"simple_module_hosting==0.0.
|
|
26
|
-
"simple_module_auth==0.0.
|
|
23
|
+
"simple_module_core==0.0.50",
|
|
24
|
+
"simple_module_db==0.0.50",
|
|
25
|
+
"simple_module_hosting==0.0.50",
|
|
26
|
+
"simple_module_auth==0.0.50",
|
|
27
27
|
"PyJWT[crypto]>=2.8,<3",
|
|
28
28
|
"cryptography>=42",
|
|
29
29
|
"httpx>=0.27,<0.29",
|
|
@@ -8,11 +8,11 @@ from cryptography.hazmat.primitives.asymmetric import rsa
|
|
|
8
8
|
from jwt.algorithms import RSAAlgorithm
|
|
9
9
|
from oidc.core.settings import OidcSettings
|
|
10
10
|
from oidc_flow_helpers import _AUDIENCE, _KID, _PRIVATE_KEY
|
|
11
|
-
from simple_module_core.discovery import discover_modules
|
|
12
|
-
from simple_module_db.base import all_module_bases
|
|
13
|
-
from simple_module_hosting.app_builder import create_app
|
|
14
|
-
from simple_module_hosting.migrations import resolve_head_revisions
|
|
15
|
-
from simple_module_hosting.settings import Settings
|
|
11
|
+
from simple_module_core.modules.discovery import discover_modules
|
|
12
|
+
from simple_module_db.models.base import all_module_bases
|
|
13
|
+
from simple_module_hosting.boot.app_builder import create_app
|
|
14
|
+
from simple_module_hosting.boot.migrations import resolve_head_revisions
|
|
15
|
+
from simple_module_hosting.config.settings import Settings
|
|
16
16
|
from sqlalchemy import text
|
|
17
17
|
|
|
18
18
|
|
|
@@ -81,7 +81,7 @@ async def oidc_app(httpx_mock, request):
|
|
|
81
81
|
endpoint_base = "https://idp"
|
|
82
82
|
authorization_url = f"{endpoint_base}/authorize"
|
|
83
83
|
keys_url = "https://idp/keys"
|
|
84
|
-
from simple_module_db.stored_settings import Setting
|
|
84
|
+
from simple_module_db.queries.stored_settings import Setting
|
|
85
85
|
|
|
86
86
|
async with app.state.sm.db.session_factory() as db:
|
|
87
87
|
for name, value in oidc_settings.model_dump().items():
|
{simple_module_oidc-0.0.48 → simple_module_oidc-0.0.50}/tests/core/module/test_oidc_module.py
RENAMED
|
@@ -25,7 +25,7 @@ def test_oidc_provider_satisfies_protocol():
|
|
|
25
25
|
|
|
26
26
|
def test_public_routes():
|
|
27
27
|
from oidc.module import OidcModule
|
|
28
|
-
from simple_module_core.public_routes import PublicRouteRegistry
|
|
28
|
+
from simple_module_core.web.public_routes import PublicRouteRegistry
|
|
29
29
|
|
|
30
30
|
registry = PublicRouteRegistry()
|
|
31
31
|
OidcModule().register_public_routes(registry)
|
|
@@ -4,7 +4,7 @@ from oidc.core.settings import OidcSettings
|
|
|
4
4
|
from settings.core.invalidation import reload_package
|
|
5
5
|
from settings.core.service import SettingService
|
|
6
6
|
from settings.module_settings.store import SettingsStore
|
|
7
|
-
from simple_module_core.module_settings import module_settings_registry
|
|
7
|
+
from simple_module_core.settings.module_settings import module_settings_registry
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
async def test_boot_hydrates_db_settings_without_settings_ui(oidc_app):
|
|
@@ -4,7 +4,7 @@ import uuid
|
|
|
4
4
|
from datetime import UTC, datetime, timedelta
|
|
5
5
|
|
|
6
6
|
from oidc.models import OidcUserCache
|
|
7
|
-
from simple_module_core.user_directory import get_user_directory
|
|
7
|
+
from simple_module_core.access.user_directory import get_user_directory
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
async def _cached(db, email, **kw):
|
|
@@ -68,7 +68,7 @@ def test_module_installs_directory_during_registration():
|
|
|
68
68
|
|
|
69
69
|
from fastapi import FastAPI
|
|
70
70
|
from oidc.module import OidcModule
|
|
71
|
-
from simple_module_core.user_directory import NullUserDirectory
|
|
71
|
+
from simple_module_core.access.user_directory import NullUserDirectory
|
|
72
72
|
|
|
73
73
|
app = FastAPI()
|
|
74
74
|
app.state.auth = SimpleNamespace()
|
|
@@ -12,9 +12,9 @@ from oidc.core.settings import OidcSettings
|
|
|
12
12
|
from oidc.identity.provider import OidcAuthProvider
|
|
13
13
|
from oidc.identity.tokens import open_refresh_token
|
|
14
14
|
from oidc.web.endpoints import api
|
|
15
|
-
from simple_module_hosting.csrf import get_csrf_token
|
|
16
|
-
from simple_module_hosting.host_settings import HostSettings
|
|
17
|
-
from simple_module_hosting.session import SessionMiddleware, preserve_across_sign_in
|
|
15
|
+
from simple_module_hosting.auth.csrf import get_csrf_token
|
|
16
|
+
from simple_module_hosting.config.host_settings import HostSettings
|
|
17
|
+
from simple_module_hosting.pipeline.session import SessionMiddleware, preserve_across_sign_in
|
|
18
18
|
from starlette.requests import Request
|
|
19
19
|
from starlette.responses import Response
|
|
20
20
|
|
|
@@ -9,7 +9,7 @@ import pytest
|
|
|
9
9
|
from itsdangerous import TimestampSigner
|
|
10
10
|
from oidc.models import OidcUserCache
|
|
11
11
|
from oidc_flow_helpers import _sign_id_token
|
|
12
|
-
from simple_module_test.session_cookie import forge_session_cookie
|
|
12
|
+
from simple_module_test.web.session_cookie import forge_session_cookie
|
|
13
13
|
from sqlalchemy import select
|
|
14
14
|
|
|
15
15
|
_ISSUER = "https://keycloak.test/realms/example"
|
{simple_module_oidc-0.0.48 → simple_module_oidc-0.0.50}/tests/web/endpoints/test_oidc_logout.py
RENAMED
|
@@ -6,7 +6,7 @@ from urllib.parse import parse_qs, urlsplit
|
|
|
6
6
|
|
|
7
7
|
import pytest
|
|
8
8
|
from itsdangerous import TimestampSigner
|
|
9
|
-
from simple_module_test.session_cookie import forge_session_cookie
|
|
9
|
+
from simple_module_test.web.session_cookie import forge_session_cookie
|
|
10
10
|
|
|
11
11
|
_INERTIA = {"X-Inertia": "true", "X-Inertia-Version": "1.0"}
|
|
12
12
|
|
|
@@ -94,3 +94,37 @@ async def test_logout_drops_the_sessions_shared_renewal_outcome(oidc_app, flow_c
|
|
|
94
94
|
assert (await flow_client.post("/oidc/logout")).status_code == 303
|
|
95
95
|
async with independent_session(oidc_app) as db:
|
|
96
96
|
assert (await db.execute(select(RefreshOutcome))).scalars().all() == []
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
async def test_cross_site_logout_is_refused_without_clearing_session(flow_client):
|
|
100
|
+
flow_client.cookies.set(
|
|
101
|
+
"session", forge_session_cookie("test-secret-key", {"marker": "retained"})
|
|
102
|
+
)
|
|
103
|
+
response = await flow_client.post("/oidc/logout", headers={"Sec-Fetch-Site": "cross-site"})
|
|
104
|
+
assert response.status_code == 403
|
|
105
|
+
cookie = response.cookies.get("session") or flow_client.cookies.get("session")
|
|
106
|
+
assert json.loads(base64.b64decode(TimestampSigner("test-secret-key").unsign(cookie))) == {
|
|
107
|
+
"marker": "retained"
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
async def test_logout_publishes_only_for_an_authenticated_session(oidc_app, flow_client):
|
|
112
|
+
from simple_module_core.user_events import UserLoggedOut
|
|
113
|
+
|
|
114
|
+
observed = []
|
|
115
|
+
|
|
116
|
+
async def observe(event):
|
|
117
|
+
observed.append(event)
|
|
118
|
+
|
|
119
|
+
oidc_app.state.sm.event_bus.subscribe(UserLoggedOut, observe)
|
|
120
|
+
assert (await flow_client.post("/oidc/logout")).status_code == 303
|
|
121
|
+
assert observed == []
|
|
122
|
+
|
|
123
|
+
signed_in = {
|
|
124
|
+
"user_ctx": {"id": "cache-id", "email": "a@example.com", "name": "A", "roles": []},
|
|
125
|
+
"expires_at": 4_102_444_800,
|
|
126
|
+
"oidc_identity": [oidc_app.state.oidc.metadata.issuer, "subject"],
|
|
127
|
+
}
|
|
128
|
+
flow_client.cookies.set("session", forge_session_cookie("test-secret-key", signed_in))
|
|
129
|
+
assert (await flow_client.post("/oidc/logout")).status_code == 303
|
|
130
|
+
assert observed == [UserLoggedOut(user_id="cache-id", email="a@example.com")]
|
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
"""Logout identifies the validated browser session even with a bearer principal."""
|
|
2
|
+
|
|
3
|
+
from types import SimpleNamespace
|
|
4
|
+
from unittest.mock import AsyncMock
|
|
5
|
+
from urllib.parse import parse_qs
|
|
6
|
+
|
|
7
|
+
import httpx
|
|
8
|
+
import pytest
|
|
9
|
+
from auth.contracts.schemas import UserContext
|
|
10
|
+
from oidc.core.settings import OidcSettings
|
|
11
|
+
from oidc.core.state import OidcState
|
|
12
|
+
from oidc.identity.client import OIDCClient
|
|
13
|
+
from oidc.identity.provider import OidcAuthProvider
|
|
14
|
+
from oidc.identity.tokens import seal_refresh_token
|
|
15
|
+
from oidc.web.endpoints import views
|
|
16
|
+
from simple_module_core.eventing.events import EventBus
|
|
17
|
+
from simple_module_core.user_events import UserLoggedOut
|
|
18
|
+
from simple_module_hosting.pipeline.session import SessionMiddleware
|
|
19
|
+
from simple_module_test import forge_session_cookie
|
|
20
|
+
from starlette.requests import Request
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
@pytest.fixture
|
|
24
|
+
async def logout_client(monkeypatch):
|
|
25
|
+
settings = OidcSettings(
|
|
26
|
+
provider="generic",
|
|
27
|
+
discovery_url="https://idp.test/.well-known/openid-configuration",
|
|
28
|
+
client_id="app",
|
|
29
|
+
api_audience="api",
|
|
30
|
+
)
|
|
31
|
+
state = OidcState(settings=settings)
|
|
32
|
+
state.client = OIDCClient(
|
|
33
|
+
client_id="app",
|
|
34
|
+
client_secret="secret",
|
|
35
|
+
token_endpoint="https://idp.test/token",
|
|
36
|
+
authorization_endpoint="https://idp.test/auth",
|
|
37
|
+
end_session_endpoint="https://idp.test/logout",
|
|
38
|
+
revocation_endpoint="https://idp.test/revoke",
|
|
39
|
+
)
|
|
40
|
+
provider = OidcAuthProvider(state=state)
|
|
41
|
+
state.jwks_cache = provider.jwks_cache = SimpleNamespace(
|
|
42
|
+
issuer="https://idp.test",
|
|
43
|
+
validate_jwt=AsyncMock(
|
|
44
|
+
side_effect=lambda token, **kw: {
|
|
45
|
+
"sub": token,
|
|
46
|
+
"email": f"{token}@example.test",
|
|
47
|
+
"azp": "app",
|
|
48
|
+
}
|
|
49
|
+
),
|
|
50
|
+
)
|
|
51
|
+
# Keep credential selection real; replace only the cache's database write.
|
|
52
|
+
monkeypatch.setattr(
|
|
53
|
+
provider,
|
|
54
|
+
"_upsert_user_cache",
|
|
55
|
+
AsyncMock(side_effect=lambda req, claims, **kw: claims["sub"]),
|
|
56
|
+
)
|
|
57
|
+
app = SimpleNamespace(
|
|
58
|
+
state=SimpleNamespace(
|
|
59
|
+
oidc=state,
|
|
60
|
+
auth=SimpleNamespace(auth_provider=provider),
|
|
61
|
+
sm=SimpleNamespace(
|
|
62
|
+
settings=SimpleNamespace(secret_key="test-secret-key"), event_bus=EventBus()
|
|
63
|
+
),
|
|
64
|
+
)
|
|
65
|
+
)
|
|
66
|
+
observed = []
|
|
67
|
+
sessions = []
|
|
68
|
+
|
|
69
|
+
async def observe(event):
|
|
70
|
+
observed.append(event)
|
|
71
|
+
assert sessions[-1] == {}
|
|
72
|
+
|
|
73
|
+
app.state.sm.event_bus.subscribe(UserLoggedOut, observe)
|
|
74
|
+
|
|
75
|
+
async def dispatch(scope, receive, send):
|
|
76
|
+
scope["app"] = app
|
|
77
|
+
request = Request(scope, receive)
|
|
78
|
+
request.state.user = await provider.resolve_user(request)
|
|
79
|
+
sessions.append(request.session)
|
|
80
|
+
response = await views.logout(request)
|
|
81
|
+
await response(scope, receive, send)
|
|
82
|
+
|
|
83
|
+
async with httpx.AsyncClient(
|
|
84
|
+
transport=httpx.ASGITransport(
|
|
85
|
+
app=SessionMiddleware(dispatch, secret_key="test-secret-key")
|
|
86
|
+
),
|
|
87
|
+
base_url="https://app.test",
|
|
88
|
+
) as client:
|
|
89
|
+
yield client, app, observed, sessions
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def _session():
|
|
93
|
+
return {
|
|
94
|
+
"user_ctx": UserContext(
|
|
95
|
+
id="session-user", email="session-user@example.test", name="Session"
|
|
96
|
+
).to_session_dict(),
|
|
97
|
+
"oidc_identity": ["https://idp.test", "session-subject"],
|
|
98
|
+
"expires_at": 4_102_444_800,
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
@pytest.mark.parametrize("bearer_user", [None, "session-user", "different-user"])
|
|
103
|
+
@pytest.mark.parametrize("user_id", ["session-user", "AAAAAAAA-0000-0000-0000-000000000001"])
|
|
104
|
+
async def test_logout_event_names_session_user(logout_client, bearer_user, user_id):
|
|
105
|
+
client, _, observed, sessions = logout_client
|
|
106
|
+
payload = _session()
|
|
107
|
+
payload["user_ctx"]["id"] = user_id
|
|
108
|
+
client.cookies.set("session", forge_session_cookie("test-secret-key", payload))
|
|
109
|
+
headers = {"Authorization": f"Bearer {bearer_user}"} if bearer_user else {}
|
|
110
|
+
assert (await client.post("/oidc/logout", headers=headers)).status_code == 303
|
|
111
|
+
assert observed == [UserLoggedOut(user_id=user_id, email="session-user@example.test")]
|
|
112
|
+
assert sessions[-1] == {}
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
@pytest.mark.parametrize(
|
|
116
|
+
"session_kind", ["absent", "bad-signature", "wrong-authority", "malformed", "expired"]
|
|
117
|
+
)
|
|
118
|
+
async def test_logout_without_valid_session_publishes_nothing(logout_client, session_kind):
|
|
119
|
+
client, _, observed, sessions = logout_client
|
|
120
|
+
payload = _session()
|
|
121
|
+
if session_kind == "wrong-authority":
|
|
122
|
+
payload["oidc_authority"] = "another-provider"
|
|
123
|
+
elif session_kind == "malformed":
|
|
124
|
+
payload["user_ctx"] = {"id": "invalid"}
|
|
125
|
+
elif session_kind == "expired":
|
|
126
|
+
payload["expires_at"] = 1
|
|
127
|
+
if session_kind != "absent":
|
|
128
|
+
cookie = forge_session_cookie("test-secret-key", payload)
|
|
129
|
+
client.cookies.set(
|
|
130
|
+
"session", cookie + "tampered" if session_kind == "bad-signature" else cookie
|
|
131
|
+
)
|
|
132
|
+
response = await client.post("/oidc/logout", headers={"Authorization": "Bearer different-user"})
|
|
133
|
+
assert response.status_code == 303
|
|
134
|
+
assert observed == []
|
|
135
|
+
assert sessions[-1] == {}
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
async def test_logout_still_cleans_up_when_validation_raises(
|
|
139
|
+
logout_client, monkeypatch, httpx_mock, caplog
|
|
140
|
+
):
|
|
141
|
+
client, app, observed, sessions = logout_client
|
|
142
|
+
payload = _session()
|
|
143
|
+
payload["oidc_refresh_token"] = seal_refresh_token(app, "refresh-secret")
|
|
144
|
+
client.cookies.set("session", forge_session_cookie("test-secret-key", payload))
|
|
145
|
+
httpx_mock.add_response(method="POST", status_code=200)
|
|
146
|
+
forgotten = []
|
|
147
|
+
|
|
148
|
+
async def unavailable(self, request, *, renew):
|
|
149
|
+
raise RuntimeError("private identity details")
|
|
150
|
+
|
|
151
|
+
async def forget(app, keys, session):
|
|
152
|
+
forgotten.append(dict(session))
|
|
153
|
+
|
|
154
|
+
monkeypatch.setattr(OidcAuthProvider, "resolve_session", unavailable, raising=False)
|
|
155
|
+
monkeypatch.setattr(views, "forget_outcomes", forget)
|
|
156
|
+
response = await client.post("/oidc/logout", headers={"Authorization": "Bearer different-user"})
|
|
157
|
+
assert response.status_code == 303
|
|
158
|
+
assert observed == []
|
|
159
|
+
assert sessions[-1] == {}
|
|
160
|
+
assert forgotten[0]["oidc_refresh_token"] == payload["oidc_refresh_token"]
|
|
161
|
+
assert b"refresh-secret" in httpx_mock.get_request().content
|
|
162
|
+
assert "session validation failed" in caplog.text
|
|
163
|
+
assert "private identity details" not in caplog.text
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
async def test_logout_does_not_swallow_cancellation(logout_client, monkeypatch):
|
|
167
|
+
from asyncio import CancelledError
|
|
168
|
+
|
|
169
|
+
client, _, _, _ = logout_client
|
|
170
|
+
|
|
171
|
+
async def cancelled(self, request, *, renew):
|
|
172
|
+
raise CancelledError
|
|
173
|
+
|
|
174
|
+
monkeypatch.setattr(OidcAuthProvider, "resolve_session", cancelled)
|
|
175
|
+
with pytest.raises(CancelledError):
|
|
176
|
+
await client.post("/oidc/logout", headers={"Authorization": "Bearer different-user"})
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
async def test_expired_logout_never_renews_and_revokes_original_token(
|
|
180
|
+
logout_client, monkeypatch, httpx_mock
|
|
181
|
+
):
|
|
182
|
+
from auth.oidc_common import renewal_outcomes
|
|
183
|
+
|
|
184
|
+
client, app, observed, sessions = logout_client
|
|
185
|
+
monkeypatch.setattr(renewal_outcomes, "_load", AsyncMock(return_value=None))
|
|
186
|
+
monkeypatch.setattr(renewal_outcomes, "_publish", AsyncMock())
|
|
187
|
+
forgotten = []
|
|
188
|
+
|
|
189
|
+
async def forget(app, keys, session):
|
|
190
|
+
forgotten.append(dict(session))
|
|
191
|
+
|
|
192
|
+
monkeypatch.setattr(views, "forget_outcomes", forget)
|
|
193
|
+
app.state.oidc.jwks_cache = SimpleNamespace(
|
|
194
|
+
issuer="https://idp.test",
|
|
195
|
+
validate_jwt=AsyncMock(
|
|
196
|
+
return_value={
|
|
197
|
+
"iss": "https://idp.test",
|
|
198
|
+
"sub": "session-subject",
|
|
199
|
+
"email": "renewed@example.test",
|
|
200
|
+
"exp": 4_102_444_800,
|
|
201
|
+
}
|
|
202
|
+
),
|
|
203
|
+
)
|
|
204
|
+
payload = _session()
|
|
205
|
+
payload["oidc_session_id"] = "browser-session"
|
|
206
|
+
payload["expires_at"] = 1
|
|
207
|
+
payload["oidc_refresh_token"] = seal_refresh_token(app, "refresh-old")
|
|
208
|
+
client.cookies.set("session", forge_session_cookie("test-secret-key", payload))
|
|
209
|
+
httpx_mock.add_response(
|
|
210
|
+
url="https://idp.test/token",
|
|
211
|
+
is_optional=True,
|
|
212
|
+
json={"id_token": "id-new", "refresh_token": "refresh-new"},
|
|
213
|
+
)
|
|
214
|
+
httpx_mock.add_response(url="https://idp.test/revoke", status_code=200)
|
|
215
|
+
response = await client.post("/oidc/logout", headers={"Authorization": "Bearer different-user"})
|
|
216
|
+
assert response.status_code == 303
|
|
217
|
+
assert sessions[-1] == {}
|
|
218
|
+
assert httpx_mock.get_requests(url="https://idp.test/token") == []
|
|
219
|
+
renewal_outcomes._load.assert_not_awaited()
|
|
220
|
+
assert observed == []
|
|
221
|
+
assert parse_qs(httpx_mock.get_requests()[-1].content.decode())["token"] == ["refresh-old"]
|
|
222
|
+
assert forgotten[0]["oidc_session_id"] == "browser-session"
|
|
223
|
+
assert forgotten[0]["oidc_refresh_token"] == payload["oidc_refresh_token"]
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
@pytest.mark.parametrize("failure", ["wrong-authority", "expired-without-cache"])
|
|
227
|
+
async def test_rejected_session_still_revokes_and_forgets_outcomes(
|
|
228
|
+
logout_client, monkeypatch, httpx_mock, failure
|
|
229
|
+
):
|
|
230
|
+
client, app, observed, sessions = logout_client
|
|
231
|
+
payload = _session()
|
|
232
|
+
payload["oidc_session_id"] = "browser-session"
|
|
233
|
+
payload["oidc_refresh_token"] = seal_refresh_token(app, "refresh-secret")
|
|
234
|
+
if failure == "wrong-authority":
|
|
235
|
+
payload["oidc_authority"] = "another-provider"
|
|
236
|
+
else:
|
|
237
|
+
payload["expires_at"] = 1
|
|
238
|
+
app.state.oidc.jwks_cache = None
|
|
239
|
+
client.cookies.set("session", forge_session_cookie("test-secret-key", payload))
|
|
240
|
+
httpx_mock.add_response(method="POST", status_code=200)
|
|
241
|
+
forgotten = []
|
|
242
|
+
|
|
243
|
+
async def forget(app, keys, session):
|
|
244
|
+
forgotten.append(dict(session))
|
|
245
|
+
|
|
246
|
+
monkeypatch.setattr(views, "forget_outcomes", forget)
|
|
247
|
+
response = await client.post("/oidc/logout", headers={"Authorization": "Bearer different-user"})
|
|
248
|
+
assert response.status_code == 303
|
|
249
|
+
assert sessions[-1] == {}
|
|
250
|
+
assert observed == []
|
|
251
|
+
assert forgotten[0]["oidc_session_id"] == "browser-session"
|
|
252
|
+
assert forgotten[0]["oidc_refresh_token"] == payload["oidc_refresh_token"]
|
|
253
|
+
assert b"refresh-secret" in httpx_mock.get_request().content
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"login": {
|
|
3
|
-
"redirecting": "Weiterleitung zum Identitätsanbieter…",
|
|
4
|
-
"manual": "Keine Weiterleitung? Manuell fortfahren"
|
|
5
|
-
},
|
|
6
|
-
"logout": {
|
|
7
|
-
"title": "Abgemeldet",
|
|
8
|
-
"message": "Sie wurden erfolgreich von dieser App abgemeldet.",
|
|
9
|
-
"sign_in_again": "Erneut anmelden"
|
|
10
|
-
},
|
|
11
|
-
"nav": {
|
|
12
|
-
"logout": "Abmelden"
|
|
13
|
-
}
|
|
14
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"login": {
|
|
3
|
-
"redirecting": "Redirecting to identity provider\u2026",
|
|
4
|
-
"manual": "Not redirected? Continue manually"
|
|
5
|
-
},
|
|
6
|
-
"logout": {
|
|
7
|
-
"title": "Signed Out",
|
|
8
|
-
"message": "You have been signed out successfully.",
|
|
9
|
-
"sign_in_again": "Sign in again"
|
|
10
|
-
},
|
|
11
|
-
"nav": {
|
|
12
|
-
"logout": "Logout"
|
|
13
|
-
}
|
|
14
|
-
}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import '@simple-module-py/i18n';
|
|
2
|
-
|
|
3
|
-
// AUTO-GENERATED by simple_module_hosting.i18n_manifest — do not edit by hand.
|
|
4
|
-
// Regenerate by booting the host in development mode or `make gen-i18n`.
|
|
5
|
-
|
|
6
|
-
export const keys = {
|
|
7
|
-
oidc: {
|
|
8
|
-
login: {
|
|
9
|
-
manual: 'oidc.login.manual',
|
|
10
|
-
redirecting: 'oidc.login.redirecting',
|
|
11
|
-
},
|
|
12
|
-
logout: {
|
|
13
|
-
message: 'oidc.logout.message',
|
|
14
|
-
sign_in_again: 'oidc.logout.sign_in_again',
|
|
15
|
-
title: 'oidc.logout.title',
|
|
16
|
-
},
|
|
17
|
-
nav: {
|
|
18
|
-
logout: 'oidc.nav.logout',
|
|
19
|
-
},
|
|
20
|
-
},
|
|
21
|
-
} as const;
|
|
22
|
-
|
|
23
|
-
type ModuleTranslationResources = {
|
|
24
|
-
readonly 'oidc.login.manual': '';
|
|
25
|
-
readonly 'oidc.login.redirecting': '';
|
|
26
|
-
readonly 'oidc.logout.message': '';
|
|
27
|
-
readonly 'oidc.logout.sign_in_again': '';
|
|
28
|
-
readonly 'oidc.logout.title': '';
|
|
29
|
-
readonly 'oidc.nav.logout': '';
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
declare module '@simple-module-py/i18n' {
|
|
33
|
-
interface TranslationResources extends ModuleTranslationResources {}
|
|
34
|
-
}
|
|
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
|
|
File without changes
|
{simple_module_oidc-0.0.48 → simple_module_oidc-0.0.50}/tests/core/module/test_oidc_migration.py
RENAMED
|
File without changes
|
|
File without changes
|
{simple_module_oidc-0.0.48 → simple_module_oidc-0.0.50}/tests/identity/client/test_oidc_client.py
RENAMED
|
File without changes
|
|
File without changes
|
{simple_module_oidc-0.0.48 → simple_module_oidc-0.0.50}/tests/identity/jwks/test_oidc_jwks.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
|
{simple_module_oidc-0.0.48 → simple_module_oidc-0.0.50}/tests/identity/renewal/test_oidc_refresh.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{simple_module_oidc-0.0.48 → simple_module_oidc-0.0.50}/tests/web/endpoints/test_oidc_flow.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|