# Authentication Module
`auth.rs` (388 lines) — Proton SRP authentication using the `proton-srp` crate.
## Status
`auth.rs` implements a complete SRP authentication flow but is **not currently wired into `main.rs`** — there is no `mod auth;` declaration. It may be intended for future integration or was designed as a standalone library module.
## SRP Authentication Flow
sequenceDiagram
participant Client as auth.rs (AuthManager)
participant API as Proton API (mail.proton.me)
Client->>API: POST /api/auth/v4/info
Note over Client,API: Send username, get SRP parameters
API-->>Client: modulus, server_ephemeral, salt, version, SRPSession
Client->>Client: Generate SRP proofs (client_ephemeral, client_proof)
Client->>API: POST /api/auth/v4
Note over Client,API: Send username + proofs
API-->>Client: access_token, refresh_token, server_proof
Client->>Client: Verify server_proof
alt 2FA Enabled
Client->>API: POST /api/auth/v4/2fa
Note over Client,API: Submit TOTP code
API-->>Client: Verified
end
Client->>Client: Store AuthSession
## Key Structures
| Structure | Purpose |
|---|---|
| `AuthManager` | Core auth state machine: HTTP client, base URL, session lock, pending 2FA lock |
| `AuthSession` | Session tokens: `uid`, `access_token`, `refresh_token`, `token_type` |
| `AuthError` | Error variants: Network, Srp, InvalidResponse, TwoFactorRequired, InvalidCredentials, NotAuthenticated, HumanVerificationRequired |
## AuthManager API
| Method | Description |
|---|---|
| `new(base_url)` | Creates manager with `reqwest::Client` (no redirects) |
| `login(username, password)` | Full SRP login: get auth info → generate proofs → submit → verify server proof → handle 2FA |
| `submit_2fa(totp_code)` | Submits TOTP code for pending 2FA session |
| `refresh_token()` | Refreshes expired access token via `/api/auth/v4/refresh` |
| `get_session()` | Returns current session (if authenticated) |
| `set_session(session)` | Restores session from persistent storage |
| `logout()` | Invalidates session and clears state |
## Session Management
- Sessions are stored in a `tokio::sync::RwLock