diff --git a/docs/docs/documentation/getting-started/installation/backend-config.md b/docs/docs/documentation/getting-started/installation/backend-config.md index e9e8ce26ceaf..bcea9f41e0e7 100644 --- a/docs/docs/documentation/getting-started/installation/backend-config.md +++ b/docs/docs/documentation/getting-started/installation/backend-config.md @@ -96,6 +96,7 @@ For usage, see [Usage - OpenID Connect](../authentication/oidc.md) | OIDC_PROVIDER_NAME | OAuth | The provider name is shown in SSO login button. "Login with " | | OIDC_REMEMBER_ME | False | Because redirects bypass the login screen, you cant extend your session by clicking the "Remember Me" checkbox. By setting this value to true, a session will be extended as if "Remember Me" was checked | | OIDC_SIGNING_ALGORITHM | RS256 | The algorithm used to sign the id token (examples: RS256, HS256) | +| OIDC_USER_CLAIM | email | Optional: 'email', 'preferred_username' ### Themeing diff --git a/mealie/core/security/providers/openid_provider.py b/mealie/core/security/providers/openid_provider.py index 15e66573b868..c9b157f1abe2 100644 --- a/mealie/core/security/providers/openid_provider.py +++ b/mealie/core/security/providers/openid_provider.py @@ -34,7 +34,7 @@ class OpenIDProvider(AuthProvider[OIDCRequest]): repos = get_repositories(self.session) - user = self.try_get_user(claims.get("email")) + user = self.try_get_user(claims.get(settings.OIDC_USER_CLAIM)) group_claim = claims.get("groups", []) is_admin = settings.OIDC_ADMIN_GROUP in group_claim if settings.OIDC_ADMIN_GROUP else False is_valid_user = settings.OIDC_USER_GROUP in group_claim if settings.OIDC_USER_GROUP else True diff --git a/mealie/core/settings/settings.py b/mealie/core/settings/settings.py index e16e121dac66..ba52432d023c 100644 --- a/mealie/core/settings/settings.py +++ b/mealie/core/settings/settings.py @@ -183,6 +183,7 @@ class AppSettings(BaseSettings): OIDC_PROVIDER_NAME: str = "OAuth" OIDC_REMEMBER_ME: bool = False OIDC_SIGNING_ALGORITHM: str = "RS256" + OIDC_USER_CLAIM: str = "email" @property def OIDC_READY(self) -> bool: @@ -190,7 +191,9 @@ class AppSettings(BaseSettings): required = {self.OIDC_CLIENT_ID, self.OIDC_CONFIGURATION_URL} not_none = None not in required - return self.OIDC_AUTH_ENABLED and not_none + valid_user_claim = self.OIDC_USER_CLAIM in ["email", "preferred_username"] + + return self.OIDC_AUTH_ENABLED and not_none and valid_user_claim # =============================================== # Testing Config