Skip to content

Commit 42e00f7

Browse files
fix: refresh tokens in approve command when unauthorized (#493)
Fixes #460. ## What changed - `approve` now handles `Unauthorized` from `list_auth_sessions` by re-running login, which refreshes tokens when possible. - After re-login, it retries listing auth sessions once. - When no sessions are pending, the command now continues to the next account instead of returning early from the entire command. ## Validation - `cargo test -p steamguard-cli --bin steamguard` <!-- PULLFROG_DIVIDER_DO_NOT_REMOVE_PLZ --> <sup><a href="https://pullfrog.com"><picture><source media="(prefers-color-scheme: dark)" srcset="https://pullfrog.com/logos/frog-white-full-18px.png"><img src="https://pullfrog.com/logos/frog-green-full-18px.png" width="9px" height="9px" style="vertical-align: middle; " alt="Pullfrog"></picture></a>&nbsp;&nbsp;| [View workflow run](https://github.com/dyc3/steamguard-cli/actions/runs/24402382941/job/71276260441) | Triggered by [Pullfrog](https://pullfrog.com) | Using `GPT Codex` | [𝕏](https://x.com/pullfrogai)</sup> --------- Co-authored-by: pullfrog[bot] <226033991+pullfrog[bot]@users.noreply.github.com>
1 parent 7f6542c commit 42e00f7

1 file changed

Lines changed: 22 additions & 12 deletions

File tree

src/commands/approve.rs

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use steamguard::approver::Challenge;
88
use steamguard::protobufs::enums::ESessionPersistence;
99
use steamguard::protobufs::steammessages_auth_steamclient::EAuthTokenPlatformType;
1010
use steamguard::transport::Transport;
11-
use steamguard::{LoginApprover, SteamGuardAccount};
11+
use steamguard::{ApproverError, LoginApprover, SteamGuardAccount};
1212

1313
#[derive(Debug, Clone, Parser)]
1414
#[clap(about = "Approve or deny pending login sessions")]
@@ -47,20 +47,30 @@ where
4747
crate::do_login(transport.clone(), &mut account, args.password.clone())?;
4848
}
4949

50-
let Some(tokens) = account.tokens.as_ref() else {
51-
error!(
52-
"No tokens found for {}. Can't approve login if we aren't logged in ourselves.",
53-
account.account_name
54-
);
55-
return Err(anyhow!("No tokens found for {}", account.account_name));
56-
};
57-
58-
let mut approver = LoginApprover::new(transport.clone(), tokens);
50+
let mut did_relogin = false;
51+
let (sessions, mut approver) = loop {
52+
let Some(tokens) = account.tokens.as_ref() else {
53+
error!(
54+
"No tokens found for {}. Can't approve login if we aren't logged in ourselves.",
55+
account.account_name
56+
);
57+
return Err(anyhow!("No tokens found for {}", account.account_name));
58+
};
5959

60-
let sessions = approver.list_auth_sessions()?;
60+
let approver = LoginApprover::new(transport.clone(), tokens);
61+
match approver.list_auth_sessions() {
62+
Ok(sessions) => break (sessions, approver),
63+
Err(ApproverError::Unauthorized) if !did_relogin => {
64+
info!("Access token expired, re-logging in...");
65+
crate::do_login(transport.clone(), &mut account, args.password.clone())?;
66+
did_relogin = true;
67+
}
68+
Err(err) => return Err(err.into()),
69+
}
70+
};
6171
if sessions.is_empty() {
6272
info!("No pending sessions to approve");
63-
return Ok(());
73+
continue;
6474
}
6575

6676
info!("Found {} pending sessions", sessions.len());

0 commit comments

Comments
 (0)