Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix how UserLogin handles access tokens for new api behavior, fixes #319 #320

Merged
merged 1 commit into from
Sep 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion steamguard/src/steamapi/authentication.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const SERVICE_NAME: &str = "IAuthenticationService";

use super::{ApiRequest, ApiResponse, BuildableRequest};

#[derive(Debug)]
#[derive(Debug, Clone)]
pub struct AuthenticationClient<T>
where
T: Transport,
Expand Down
34 changes: 27 additions & 7 deletions steamguard/src/userlogin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ use crate::protobufs::steammessages_auth_steamclient::{
CAuthentication_UpdateAuthSessionWithSteamGuardCode_Request,
CAuthentication_UpdateAuthSessionWithSteamGuardCode_Response, EAuthTokenPlatformType,
};
use crate::refresher::TokenRefresher;
use crate::steamapi::authentication::AuthenticationClient;
use crate::steamapi::EResult;
use crate::token::Tokens;
use crate::transport::Transport;
use anyhow::Context;
use base64::Engine;
use log::*;
use rsa::{Pkcs1v15Encrypt, RsaPublicKey};
Expand Down Expand Up @@ -82,7 +84,7 @@ impl BeginQrLoginResponse {
#[derive(Debug)]
pub struct UserLogin<T>
where
T: Transport,
T: Transport + Clone,
{
client: AuthenticationClient<T>,
device_details: DeviceDetails,
Expand All @@ -92,7 +94,7 @@ where

impl<T> UserLogin<T>
where
T: Transport,
T: Transport + Clone,
{
pub fn new(transport: T, device_details: DeviceDetails) -> Self {
Self {
Expand Down Expand Up @@ -214,11 +216,29 @@ where
loop {
let mut next_poll = self.poll_until_info()?;

if next_poll.has_access_token() {
return Ok(Tokens::new(
next_poll.take_access_token(),
next_poll.take_refresh_token(),
));
if next_poll.has_access_token() || next_poll.has_refresh_token() {
// On 2023-09-12, Steam stopped issuing access tokens alongside refresh tokens for newly authenticated sessions.
// If they decide to revert this change, we'll accept the access token if it's present.

let access_token = next_poll.take_access_token();
if access_token.is_empty() {
// Let's go ahead an fetch the access token, because we are going to need it anyway.
let mut refresher = TokenRefresher::new(self.client.clone());
let mut tokens = Tokens::new(
next_poll.take_access_token(),
next_poll.take_refresh_token(),
);
let steamid = tokens
.refresh_token()
.decode()
.context("decoding refresh token for steam id")?
.steam_id();
let access_token = refresher.refresh(steamid, &tokens)?;
tokens.set_access_token(access_token);
return Ok(tokens);
} else {
return Ok(Tokens::new(access_token, next_poll.take_refresh_token()));
};
}
}
}
Expand Down
Loading