Source code for cadrumo.adapters.outbound.aeat.auth.provider_selection
"""Concrete AEAT authentication provider selection.The selector is a public contract in its own defining module. Keeping itoutside the package initializer preserves the package's intentionally inertnamespace while giving application orchestration an exact import target."""from__future__importannotationsfromtypingimportTYPE_CHECKINGfrom.....application.auth.protocolsimportBrowserSessionFactoryPortfrom.....application.auth_credentialsimportActiveCertificateCredentialsfrom.....core.auth_providerimportAuthProviderKindfrom.errorsimportAuthConfigurationErrorifTYPE_CHECKING:from.....core.configimportSettingsfrom.authenticatorimportAeatAuthenticatorfrom.clave_movilimportClaveMovilAuthProviderfrom.clave_permanenteimportClavePermanenteAuthProvider__all__=["select_provider"]
[docs]defselect_provider(kind:AuthProviderKind,*,settings:Settings,browser_session_factory:BrowserSessionFactoryPort|None=None,certificate_credentials:ActiveCertificateCredentials|None=None,)->AeatAuthenticator|ClaveMovilAuthProvider|ClavePermanenteAuthProvider:"""Return the concrete outbound provider implementation for ``kind``. ``CERTIFICATE`` requires certificate credentials; browser-backed providers receive the optional shared browser-session factory. """ifkindisAuthProviderKind.CERTIFICATE:from.authenticatorimportAeatAuthenticatorifcertificate_credentialsisNone:raiseAuthConfigurationError("certificate provider construction requires ActiveCertificateCredentials",)returnAeatAuthenticator(settings,credentials=certificate_credentials,browser_session_factory=browser_session_factory,)ifkindisAuthProviderKind.CLAVE_MOVIL:from.clave_movilimportClaveMovilAuthProviderreturnClaveMovilAuthProvider(settings,browser_session_factory=browser_session_factory,)ifkindisAuthProviderKind.CLAVE_PERMANENTE:from.clave_permanenteimportClavePermanenteAuthProviderreturnClavePermanenteAuthProvider(settings,browser_session_factory=browser_session_factory,)raiseAuthConfigurationError(f"unsupported auth provider kind {kind!r}")