Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Add OIDC debug logging #4658

Open
wants to merge 3 commits into
base: mealie-next
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions mealie/core/security/providers/openid_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ def authenticate(self) -> tuple[str, timedelta] | None:
self._logger.error("[OIDC] No claims in the id_token")
return None

# Log all claims for debugging
self._logger.debug("[OIDC] Received claims:")
for key, value in claims.items():
self._logger.debug("[OIDC] %s: %s", key, value)

if not self.required_claims.issubset(claims.keys()):
self._logger.error(
"[OIDC] Required claims not present. Expected: %s Actual: %s",
Expand All @@ -35,6 +40,12 @@ def authenticate(self) -> tuple[str, timedelta] | None:
)
return None

# Check for empty required claims
for claim in self.required_claims:
if not claims.get(claim):
self._logger.error("[OIDC] Required claim '%s' is empty", claim)
return None

repos = get_repositories(self.session, group_id=None, household_id=None)

is_admin = False
Expand Down
29 changes: 29 additions & 0 deletions tests/unit_tests/core/security/providers/test_openid_provider.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import pytest
from pytest import MonkeyPatch, Session
import logging

from mealie.core.config import get_app_settings
from mealie.core.security.providers.openid_provider import OpenIDProvider
Expand All @@ -20,6 +21,18 @@ def test_empty_claims():
assert auth_provider.authenticate() is None


def test_empty_required_claims():
data = {
"preferred_username": "dude1",
"email": "", # Empty required claim
"name": "Firstname Lastname",
"groups": ["mealie_user"],
}
auth_provider = OpenIDProvider(None, data)

assert auth_provider.authenticate() is None


def test_missing_claims():
data = {"preferred_username": "dude1"}
auth_provider = OpenIDProvider(None, data)
Expand Down Expand Up @@ -162,3 +175,19 @@ def test_ldap_user_creation_invalid_group_or_household(
assert user is not None
else:
assert user is None


def test_claims_logging(caplog, session: Session):
caplog.set_level(logging.DEBUG)
data = {
"preferred_username": "testuser",
"email": "[email protected]",
"name": "Test User",
"groups": ["mealie_user"],
}
auth_provider = OpenIDProvider(session, data)
auth_provider.authenticate()

# Verify that all claims are logged
for key, value in data.items():
assert f"{key}: {value}" in caplog.text
Loading