cadrumo.application.auth.sessions module¶
Persisted AEAT session discovery and verification.
ensure_authenticated_aeat_session() returns
AuthenticatedAeatSessionResult after coordinating
AuthProviderKind selection, SessionStoreProtocol persistence,
and PersistedAuthSession reuse.
See also
application.auth.acquisition_lockDefines the profile/provider
application.auth.acquisition_lock.AuthAcquisitionLockRecordused to serialize live authentication.application.live.sessionRead-only live-entry helper that calls this module only after
core.access_gate.gate.AeatAccessGateallows a live read.adapters.outbound.aeat.authConcrete providers and persisted-session store implementations.
- class StorageStatePaths(**data)[source]¶
Bases:
BaseModelLogical storage-state identifier for one provider’s persisted AEAT session.
- Parameters:
data (Any)
- storage_state: Path¶
- exception CorruptAuthSessionError(message=None, *, context=None, translated_message=None)[source]¶
Bases:
CadrumoErrorRaised when persisted session metadata cannot be parsed.
- Parameters:
- Return type:
None
- code¶
Bases:
CadrumoErrorRaised when no verified active AEAT session can be supplied.
- Parameters:
- Return type:
None
- exception SessionDeserializationError(message=None, *, context=None, translated_message=None)[source]¶
Bases:
AuthSessionUnavailableErrorRaised when a persisted session field cannot be deserialized to the expected type.
Replaces the bare
TypeErrorraised bysession_metadata_datetime()so callers catch a typed, registry-bound error that inherits fromAuthSessionUnavailableError.- Parameters:
- Return type:
None
- code¶
- exception AuthProfileIdentityMismatchError(message=None, *, context=None, translated_message=None)[source]¶
Bases:
CadrumoErrorRaised when the active profile identity cannot own the requested auth session.
- Parameters:
- Return type:
None
- code¶
- exception ClaveCredentialsIncompleteError(message=None, *, context=None, translated_message=None)[source]¶
Bases:
CadrumoErrorRaised when a Cl@ve mode lacks a credential half the AEAT flow needs.
Distinct from
AuthProfileIdentityMismatchError: nothing disagrees here, a credential is simply absent. The operator’s recovery is to record it rather than to switch profile, so the refusal names what is missing and points at the profile it belongs on.- Parameters:
- Return type:
None
- code¶
- class ClaveCredentials(**data)[source]¶
Bases:
BaseModelCl@ve credential halves for one provider kind, and where each came from.
dni_nieandnumero_soporteare the effective values: the active profile’s when it carries one, theSettingssurface’s otherwise, so an operator who configured Cl@ve through the environment keeps working. Theprofile_fields record what the profile itself held, because the provider adapters read their credentials fromSettings- a profile-borne value only reaches AEAT once it has been bound onto the settings the provider will read.- Parameters:
data (Any)
- provider_kind: AuthProviderKind¶
- dni_nie: str¶
- numero_soporte: str¶
- fecha_validez: str¶
- profile_tax_id: str¶
- profile_dni_nie: str¶
- profile_numero_soporte: str¶
- profile_fecha_validez: str¶
- class AuthenticatedAeatSessionResult(**data)[source]¶
Bases:
BaseModelOutcome of ensuring an authenticated AEAT session.
- Parameters:
provider_kind (AuthProviderKind)
session (Annotated[AeatSession, SkipValidation()])
assertion (Annotated[AeatLoginAssertion, SkipValidation()])
reused_persisted_session (bool)
acquired_lock (AuthAcquisitionLockRecord | None)
reset_lock (AuthAcquisitionLockStatus | None)
fresh (bool)
- provider_kind: AuthProviderKind¶
- session: SkipValidation[AeatSession]¶
- assertion: SkipValidation[AeatLoginAssertion]¶
- reused_persisted_session: bool¶
- acquired_lock: AuthAcquisitionLockRecord | None¶
- reset_lock: AuthAcquisitionLockStatus | None¶
- removed_sessions: tuple[Path, ...]¶
- fresh: bool¶
- class PersistedAuthSession(**data)[source]¶
Bases:
BaseModelProvider-neutral view of encrypted AEAT session metadata.
- Parameters:
data (Any)
- provider_kind: AuthProviderKind¶
- identity_nif: str¶
- authenticated_at: datetime¶
- idle_deadline: datetime¶
- storage_state_paths(kind=None, *, bucket_id=None)[source]¶
Return the logical storage-state identifier for
kind.Returns a
StorageStatePathscarrying the stable logical object key for the provider’s encrypted session state.- Return type:
- Parameters:
kind (AuthProviderKind | None)
bucket_id (str | None)
- load_persisted_session(settings, kind=None)[source]¶
Load persisted AEAT session metadata for
kindor the active provider.Returns a
PersistedAuthSession.- Return type:
- Parameters:
settings (Settings)
kind (AuthProviderKind | None)
- delete_persisted_session(settings, kind=None, *, bucket_id=None)[source]¶
Remove persisted encrypted sessions for
kindor every session-bearing provider.A
kindofNonesweeps every provider that actually persists a browser session (the_STEM_BY_KINDset). Reserved catalogue slots are notAuthProviderKindmembers and therefore never enter this storage loop; operator--allscope may name them for idempotent configuration cleanup without manufacturing session paths for unsupported providers.- Return type:
list[Path]- Parameters:
settings (Settings)
kind (AuthProviderKind | None)
bucket_id (str | None)
- persisted_session_exists(settings, kind, *, bucket_id=None)[source]¶
Return whether
kindhas persisted session state inbucket_id.- Return type:
- Parameters:
settings (Settings)
kind (AuthProviderKind)
bucket_id (str | None)
- async ensure_authenticated_aeat_session(settings, *, certificate_secret_backend_factory, kind=None, fresh=False, reset_lock=False, operation='auth-ensure-session', target_url=None, browser_session_factory, certificate_credentials=None, operator_scope_ports, profile_decode_context)[source]¶
Serialize and fail-close the central live-session writer.
- Return type:
- Parameters:
settings (Settings)
certificate_secret_backend_factory (CertificateSecretBackendFactory)
kind (AuthProviderKind | None)
fresh (bool)
reset_lock (bool)
operation (str)
target_url (str | None)
browser_session_factory (BrowserSessionFactoryPort)
certificate_credentials (ActiveCertificateCredentials | None)
operator_scope_ports (OperatorScopePorts)
profile_decode_context (ProfileDecodeContext)
- resolve_clave_credentials(provider_kind, *, settings, facts)[source]¶
Resolve the Cl@ve halves for
provider_kind, profile first.The single home for the profile-beats-settings precedence. Both the live session entry and the operator readiness surfaces resolve through here, so a status surface cannot report a credential as unconfigured that the session entry would happily authenticate with.
Returns
Nonefor the certificate provider, which authenticates with an installed certificate and needs neither Cl@ve field.- Return type:
- Parameters:
provider_kind (AuthProviderKind)
settings (Settings)
facts (ClaveAuthFacts)
- bind_clave_credentials_to_settings(settings, credentials, *, route)[source]¶
Return settings carrying the profile’s Cl@ve credentials.
The outbound providers read their credentials from
Settings, so a value the profile holds is inert until it is bound here. When the profile carries nothing the caller’s settings are returned unchanged, which keeps the environment-configured path byte-identical.- Return type:
- Parameters:
settings (Settings)
credentials (ClaveCredentials)
route (ClaveMovilRoute | None)
- class ClaveAuthFacts(**data)[source]¶
Bases:
BaseModelAuthentication facts read from the active profile record.
- Parameters:
data (Any)
- tax_id: str¶
- dni_nie: str¶
- numero_soporte: str¶
- fecha_validez: str¶
- clave_movil_route: ClaveMovilRoute | None¶
- profile_setup_state: ProfileSetupState | None¶
- clave_auth_facts_from_profile_values(values, *, profile_setup_state=None)[source]¶
Read the auth facts out of a profile’s schema-path value mapping.
The projection a readiness surface already holds is enough to resolve a credential, so this lets those surfaces reuse the resolver without opening the profile record a second time.
identity.tax_idis read here only in its canonical path form; the lifecycle reader applies the selector fallback before calling this.profile_statusdistinguishes a profile that has NOT YET recorded its fiscal identity from one whose identity was recorded and later cleared. Only the record carries that, so a caller holding just a value mapping leaves it unset and is treated as the stricter case.- Return type:
- Parameters:
profile_setup_state (ProfileSetupState | None)