steam_auth/transport.rs
1//! Transport implementations for Steam API communication.
2//!
3//! This module provides transport abstractions for communicating with Steam's
4//! services. Two built-in transports are available:
5//!
6//! - [`WebApiTransport`]: HTTP-based transport using `api.steampowered.com`
7//! - [`WebSocketCMTransport`]: WebSocket transport for direct CM server
8//! communication
9//!
10//! # Custom Transports
11//!
12//! The [`Transport`] enum is currently closed (not extensible) to provide a
13//! simpler API. If you need custom transport behavior, you can:
14//!
15//! 1. Use [`WebApiTransport::with_client`] to provide a custom
16//! `reqwest::Client` with custom configuration (timeouts, proxies, etc.)
17//! 2. Use [`WebSocketCMTransport::with_options`] to provide a custom CM server
18//! provider
19//!
20//! For more advanced customization, consider wrapping the existing transports
21//! or contributing a new transport variant to the crate.
22
23pub mod web_api;
24pub mod websocket_cm;
25
26use std::collections::HashMap;
27
28pub use web_api::WebApiTransport;
29pub use websocket_cm::WebSocketCMTransport;
30
31use crate::error::SessionError;
32
33/// Request to send to Steam API.
34#[derive(Debug, Clone)]
35pub struct ApiRequest {
36 /// API interface (e.g., "Authentication").
37 pub api_interface: String,
38 /// API method (e.g., "GetPasswordRSAPublicKey").
39 pub api_method: String,
40 /// API version.
41 pub api_version: u32,
42 /// Access token for authenticated requests.
43 pub access_token: Option<String>,
44 /// Protobuf-encoded request data.
45 pub request_data: Option<Vec<u8>>,
46 /// HTTP headers.
47 pub headers: HashMap<String, String>,
48}
49
50/// Response from Steam API.
51#[derive(Debug, Clone)]
52pub struct ApiResponse {
53 /// EResult code.
54 pub result: Option<i32>,
55 /// Error message from Steam.
56 pub error_message: Option<String>,
57 /// Protobuf-encoded response data.
58 pub response_data: Option<Vec<u8>>,
59}
60
61/// Transport type for communicating with Steam.
62#[derive(Debug, Clone)]
63pub enum Transport {
64 /// Web API transport (HTTPS).
65 WebApi(WebApiTransport),
66 /// WebSocket CM transport.
67 WebSocketCM(WebSocketCMTransport),
68}
69
70impl Transport {
71 /// Send a request and receive a response.
72 pub async fn send_request(&self, request: ApiRequest) -> Result<ApiResponse, SessionError> {
73 match self {
74 Transport::WebApi(t) => t.send_request(request).await,
75 Transport::WebSocketCM(t) => t.send_request(request).await,
76 }
77 }
78}