Coverage for src/lexigram/auth/di/sub_providers/oauth_provider.py: 75%
4 statements
« prev ^ index » next coverage.py v7.15.4, created at 2026-08-25 12:26 +0800
« prev ^ index » next coverage.py v7.15.4, created at 2026-08-25 12:26 +0800
1"""OAuth provider config helpers for provider presets.
3Provider configurations are declared under ``auth.oauth2_providers`` in
4``application.yaml`` and are loaded by the config system. Call
5:func:`detect_oauth_providers_from_config` to filter a pre-loaded
6:attr:`~lexigram.auth.config.AuthConfig.oauth2_providers` mapping before
7passing it to a provider.
8"""
10from __future__ import annotations
13def detect_oauth_providers_from_config(
14 oauth2_providers: dict[str, dict[str, str]],
15) -> dict[str, dict[str, str]]:
16 """Return valid OAuth2 providers from a pre-loaded config mapping.
18 This is the config-based replacement for env-variable auto-detection.
19 Providers are declared under ``auth.oauth2_providers`` in
20 ``application.yaml`` (or via the ``LEX_AUTH__OAUTH2_PROVIDERS__*``
21 env-var hierarchy processed by the config system), so no direct
22 ``os.environ`` reads are needed here.
24 Args:
25 oauth2_providers: Raw provider mapping from
26 :attr:`~lexigram.auth.config.AuthConfig.oauth2_providers`.
28 Returns:
29 A copy of the mapping filtered to non-empty entries.
30 """
31 return {name: cfg for name, cfg in oauth2_providers.items() if name and cfg}
34__all__ = [
35 "detect_oauth_providers_from_config",
36]