steam-user 0.1.0

Steam User web client for Rust - HTTP-based Steam Community interactions
Documentation
//! Two-factor authentication example for steam-user crate.
//!
//! This example demonstrates:
//! - Enabling Steam Guard Mobile Authenticator
//! - Finalizing 2FA setup with SMS code
//! - Disabling 2FA with revocation code
//!
//! WARNING: These operations affect your account security!
//! Make sure to save your shared_secret, identity_secret, and revocation_code.
//!
//! Run with: cargo run --example twofactor

use steam_user::{SteamUser, SteamUserError};
use tracing::info;

#[tokio::main]
async fn main() -> Result<(), SteamUserError> {
    tracing_subscriber::fmt::init();

    // Create a new SteamUser client with cookies from session login
    let mut community = SteamUser::new(&["steamLoginSecure=76561198012345678||YOUR_ACCESS_TOKEN", "sessionid=YOUR_SESSION_ID"])?;

    // Set mobile access token (required for 2FA operations)
    // This comes from a mobile login via steam-session
    community.set_mobile_access_token("YOUR_MOBILE_ACCESS_TOKEN".to_string());

    // Example: Enable two-factor authentication
    // This will send an SMS to the phone number associated with your account
    info!("=== Enable Two-Factor Authentication ===");
    info!("WARNING: This will enable 2FA on your account!");
    info!("Make sure to SAVE your secrets after this operation.\n");

    // match community.enable_two_factor().await {
    // Ok(response) => {
    // info!("2FA setup initiated!");
    // info!("\n!!! SAVE THESE SECRETS !!!");
    // info!("shared_secret: {}", response.shared_secret);
    // info!("identity_secret: {}", response.identity_secret);
    // info!("revocation_code: {}", response.revocation_code);
    // info!("serial_number: {}", response.serial_number);
    // info!("server_time: {}", response.server_time);
    // info!("account_name: {}", response.account_name);
    //
    // Now you need to finalize with the SMS code sent to your phone
    // info!("\nAn SMS code has been sent to your phone.");
    // info!("Use this code to finalize 2FA setup.");
    //
    // Store share_secret for finalization
    // let shared_secret = response.shared_secret;
    //
    // In a real application, you would prompt for the SMS code
    // let sms_code = "12345"; // Replace with actual SMS code
    //
    // match community.finalize_two_factor(&shared_secret, sms_code).await {
    // Ok(()) => {
    // info!("\n2FA enabled successfully!");
    // info!("Your account is now protected with Steam Guard Mobile
    // Authenticator."); }
    // Err(e) => {
    // info!("Failed to finalize 2FA: {}", e);
    // info!("If the SMS code was wrong, try again.");
    // }
    // }
    // }
    // Err(e) => {
    // info!("Failed to enable 2FA: {}", e);
    // }
    // }

    // Example: Disable two-factor authentication
    // This removes the mobile authenticator from your account
    // info!("\n=== Disable Two-Factor Authentication ===");
    // info!("WARNING: This will remove 2FA from your account!\n");
    //
    // Your revocation code starts with 'R' followed by 5 digits (e.g., R12345)
    // let revocation_code = "R12345";
    //
    // match community.disable_two_factor(revocation_code).await {
    // Ok(()) => {
    // info!("2FA disabled successfully!");
    // info!("Your account no longer has Steam Guard Mobile Authenticator.");
    // }
    // Err(e) => {
    // info!("Failed to disable 2FA: {}", e);
    // }
    // }

    info!("This example demonstrates 2FA operations but doesn't execute them.");
    info!("Uncomment the code blocks to enable or disable 2FA.");
    info!("\nRemember to:");
    info!("1. Set your mobile access token");
    info!("2. Save all secrets when enabling 2FA");
    info!("3. Keep your revocation code safe");

    Ok(())
}