Skip to content

Commit e7effd2

Browse files
olivermeyerclaude
andcommitted
refactor(auth): drop redundant session_enabled field
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 9f6a3be commit e7effd2

3 files changed

Lines changed: 8 additions & 27 deletions

File tree

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,8 +217,7 @@ activates several cross-field requirements. Only needed when using
217217
| Variable | Required | Default | Description |
218218
|---|---|---|---|
219219
| `{PREFIX}AUTH_ENABLED` | no | `false` | Enable Auth0 authentication. When `true`, several other fields become required. |
220-
| `{PREFIX}AUTH_SESSION_ENABLED` | when enabled | `false` | Enable session cookies. Required when `AUTH_ENABLED=true`. |
221-
| `{PREFIX}AUTH_SESSION_SECRET` | when session enabled | `""` | Secret to sign session cookies. Required when `AUTH_SESSION_ENABLED=true`. |
220+
| `{PREFIX}AUTH_SESSION_SECRET` | when enabled | `""` | Secret to sign session cookies. Required when `AUTH_ENABLED=true`. |
222221
| `{PREFIX}AUTH_SESSION_EXPIRATION` | no | `86400` | Session cookie expiration in seconds (range: 61–31536000). |
223222
| `{PREFIX}AUTH_DOMAIN` | when enabled | `""` | Auth0 domain (e.g. `myapp.eu.auth0.com`). Required when `AUTH_ENABLED=true`. |
224223
| `{PREFIX}AUTH_CLIENT_ID` | when enabled | `""` | Auth0 client ID (max 32 chars). Required when `AUTH_ENABLED=true`. |

src/aignostics_foundry_core/api/auth.py

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ class AuthSettings(OpaqueSettings):
4141
4242
Fields:
4343
enabled: Enable Auth0 authentication (AUTH_ENABLED).
44-
session_enabled: Enable session cookies (AUTH_SESSION_ENABLED).
4544
session_secret: Secret used to sign session cookies (AUTH_SESSION_SECRET).
4645
session_expiration: Session cookie expiration in seconds (AUTH_SESSION_EXPIRATION).
4746
domain: Auth0 domain (AUTH_DOMAIN).
@@ -51,16 +50,13 @@ class AuthSettings(OpaqueSettings):
5150
role_claim: JWT claim name containing the user's role (AUTH_ROLE_CLAIM).
5251
5352
Cross-field rules (validated after field assignment):
54-
- enabled=True requires session_enabled=True
55-
- session_enabled=True requires session_secret not None
56-
- enabled=True requires client_secret not None, non-empty domain, client_id,
57-
internal_org_id, and role_claim
53+
- enabled=True requires session_secret not None, client_secret not None,
54+
non-empty domain, client_id, internal_org_id, and role_claim
5855
"""
5956

6057
model_config = SettingsConfigDict(extra="ignore")
6158

6259
enabled: bool = Field(default=False)
63-
session_enabled: bool = Field(default=False)
6460
session_secret: Annotated[
6561
SecretStr | None,
6662
PlainSerializer(func=OpaqueSettings.serialize_sensitive_info, return_type=str, when_used="always"),
@@ -90,11 +86,8 @@ def validate_auth_dependencies(self) -> "AuthSettings":
9086
Raises:
9187
ValueError: If any cross-field dependency is violated.
9288
"""
93-
if self.enabled and not self.session_enabled:
94-
msg = "AUTH_SESSION_ENABLED must be True when AUTH_ENABLED is True"
95-
raise ValueError(msg)
96-
if self.session_enabled and self.session_secret is None:
97-
msg = "AUTH_SESSION_SECRET must not be None when AUTH_SESSION_ENABLED is True"
89+
if self.enabled and self.session_secret is None:
90+
msg = "AUTH_SESSION_SECRET must not be None when AUTH_ENABLED is True"
9891
raise ValueError(msg)
9992
if self.enabled and self.client_secret is None:
10093
msg = "AUTH_CLIENT_SECRET must not be None when AUTH_ENABLED is True"

tests/aignostics_foundry_core/api/auth_test.py

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ def test_auth_settings_defaults(self) -> None:
9292
"""AuthSettings has correct defaults when no env vars are set."""
9393
settings = AuthSettings()
9494
assert settings.enabled is False
95-
assert settings.session_enabled is False
9695
assert not settings.internal_org_id
9796
assert not settings.role_claim
9897
assert not settings.domain
@@ -111,22 +110,16 @@ def test_auth_settings_uses_context_env_prefix(self, monkeypatch: pytest.MonkeyP
111110
settings = AuthSettings()
112111
assert settings.role_claim == "https://custom/role"
113112

114-
def test_enabled_requires_session_enabled(self) -> None:
115-
"""enabled=True with session_enabled=False raises ValidationError."""
113+
def test_enabled_requires_session_secret(self) -> None:
114+
"""enabled=True with session_secret=None raises ValidationError."""
116115
with pytest.raises(pydantic.ValidationError):
117-
AuthSettings(enabled=True, session_enabled=False)
118-
119-
def test_session_enabled_requires_session_secret(self) -> None:
120-
"""session_enabled=True with session_secret=None raises ValidationError."""
121-
with pytest.raises(pydantic.ValidationError):
122-
AuthSettings(session_enabled=True, session_secret=None)
116+
AuthSettings(enabled=True, session_secret=None)
123117

124118
def test_enabled_requires_client_secret(self) -> None:
125119
"""enabled=True with client_secret=None raises ValidationError."""
126120
with pytest.raises(pydantic.ValidationError):
127121
AuthSettings(
128122
enabled=True,
129-
session_enabled=True,
130123
session_secret=_TEST_SESSION_SECRET,
131124
client_secret=None,
132125
)
@@ -136,7 +129,6 @@ def test_enabled_requires_non_empty_domain(self) -> None:
136129
with pytest.raises(pydantic.ValidationError):
137130
AuthSettings(
138131
enabled=True,
139-
session_enabled=True,
140132
session_secret=_TEST_SESSION_SECRET,
141133
client_secret=_TEST_CLIENT_SECRET,
142134
domain="",
@@ -147,7 +139,6 @@ def test_enabled_requires_non_empty_client_id(self) -> None:
147139
with pytest.raises(pydantic.ValidationError):
148140
AuthSettings(
149141
enabled=True,
150-
session_enabled=True,
151142
session_secret=_TEST_SESSION_SECRET,
152143
client_secret=_TEST_CLIENT_SECRET,
153144
domain=_TEST_DOMAIN,
@@ -159,7 +150,6 @@ def test_enabled_requires_non_empty_internal_org_id(self) -> None:
159150
with pytest.raises(pydantic.ValidationError):
160151
AuthSettings(
161152
enabled=True,
162-
session_enabled=True,
163153
session_secret=_TEST_SESSION_SECRET,
164154
client_secret=_TEST_CLIENT_SECRET,
165155
domain=_TEST_DOMAIN,
@@ -172,7 +162,6 @@ def test_enabled_requires_non_empty_role_claim(self) -> None:
172162
with pytest.raises(pydantic.ValidationError):
173163
AuthSettings(
174164
enabled=True,
175-
session_enabled=True,
176165
session_secret=_TEST_SESSION_SECRET,
177166
client_secret=_TEST_CLIENT_SECRET,
178167
domain=_TEST_DOMAIN,

0 commit comments

Comments
 (0)