Skip to content

Commit 76affff

Browse files
committed
refactor: Separate into XalAppParameters and XalClientParameters
1 parent 28fabdb commit 76affff

2 files changed

Lines changed: 48 additions & 36 deletions

File tree

xal/src/app_params.rs

Lines changed: 36 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -36,72 +36,79 @@ impl ToString for DeviceType {
3636
}
3737

3838
#[derive(Debug, Serialize, Deserialize, Clone)]
39-
pub struct XalClientParameters {
40-
pub user_agent: String,
39+
pub struct XalAppParameters {
4140
pub app_id: String,
42-
pub device_type: DeviceType,
43-
pub client_version: String,
4441
pub title_id: String,
4542
pub redirect_uri: String,
46-
pub query_display: String,
4743
}
4844

49-
impl XalClientParameters {
50-
pub fn ios_xboxbeta_params() -> Self {
45+
impl XalAppParameters {
46+
pub fn xbox_app_beta() -> Self {
5147
Self {
52-
user_agent: "XAL iOS 2020.07.20200714.000".into(),
5348
app_id: "000000004415494b".into(),
54-
device_type: DeviceType::IOS,
55-
client_version: "14.0.1".into(),
5649
title_id: "177887386".into(),
5750
redirect_uri: "ms-xal-000000004415494b://auth".into(),
58-
query_display: "ios_phone".into(),
5951
}
6052
}
6153

62-
pub fn ios_xbox_params() -> Self {
54+
pub fn xbox_app() -> Self {
6355
Self {
64-
user_agent: "XAL iOS 2021.11.20211021.000".into(),
6556
app_id: "000000004c12ae6f".into(),
66-
device_type: DeviceType::IOS,
67-
client_version: "15.6.1".into(),
6857
title_id: "328178078".into(),
6958
redirect_uri: "ms-xal-000000004c12ae6f://auth".into(),
70-
query_display: "ios_phone".into(),
7159
}
7260
}
7361

74-
pub fn android_xboxbeta_params() -> Self {
62+
pub fn gamepass_beta() -> Self {
7563
Self {
76-
user_agent: "XAL Android 2020.07.20200714.000".into(),
77-
app_id: "000000004415494b".into(),
78-
device_type: DeviceType::ANDROID,
79-
client_version: "8.0.0".into(),
80-
title_id: "177887386".into(),
81-
redirect_uri: "ms-xal-000000004415494b://auth".into(),
82-
query_display: "android_phone".into(),
64+
app_id: "000000004c20a908".into(),
65+
title_id: "1016898439".into(),
66+
redirect_uri: "ms-xal-public-beta-000000004c20a908://auth".into(),
67+
}
68+
}
69+
}
70+
71+
impl Default for XalAppParameters {
72+
fn default() -> Self {
73+
Self::gamepass_beta()
74+
}
75+
}
76+
77+
#[derive(Debug, Serialize, Deserialize, Clone)]
78+
pub struct XalClientParameters {
79+
pub user_agent: String,
80+
pub device_type: DeviceType,
81+
pub client_version: String,
82+
pub query_display: String,
83+
}
84+
85+
impl XalClientParameters {
86+
pub fn ios() -> Self {
87+
Self {
88+
user_agent: "XAL iOS 2021.11.20211021.000".into(),
89+
device_type: DeviceType::IOS,
90+
client_version: "15.6.1".into(),
91+
query_display: "ios_phone".into(),
8392
}
8493
}
8594

86-
pub fn android_gamepass_beta_params() -> Self {
95+
pub fn android() -> Self {
8796
Self {
8897
user_agent: "XAL Android 2020.07.20200714.000".into(),
89-
app_id: "000000004c20a908".into(),
9098
device_type: DeviceType::ANDROID,
9199
client_version: "8.0.0".into(),
92-
title_id: "1016898439".into(),
93-
redirect_uri: "ms-xal-public-beta-000000004c20a908://auth".into(),
94100
query_display: "android_phone".into(),
95101
}
96102
}
97103
}
98104

99105
impl Default for XalClientParameters {
100106
fn default() -> Self {
101-
Self::android_gamepass_beta_params()
107+
Self::android()
102108
}
103109
}
104110

111+
105112
#[cfg(test)]
106113
mod tests {
107114
use super::*;

xal/src/authenticator.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use crate::app_params::XalAppParameters;
2+
13
use super::{
24
app_params::{DeviceType, XalClientParameters},
35
models::request,
@@ -89,6 +91,7 @@ where
8991
#[derive(Debug)]
9092
pub struct XalAuthenticator {
9193
device_id: uuid::Uuid,
94+
app_params: XalAppParameters,
9295
client_params: XalClientParameters,
9396
ms_cv: cvlib::CorrelationVector,
9497
client: reqwest::Client,
@@ -98,7 +101,8 @@ pub struct XalAuthenticator {
98101

99102
impl Default for XalAuthenticator {
100103
fn default() -> Self {
101-
let app_params = XalClientParameters::default();
104+
let client_params = XalClientParameters::default();
105+
let app_params = XalAppParameters::default();
102106
let client_id = ClientId::new(app_params.app_id.clone());
103107
let client_secret = None;
104108

@@ -115,7 +119,8 @@ impl Default for XalAuthenticator {
115119

116120
Self {
117121
device_id: uuid::Uuid::new_v4(),
118-
client_params: app_params,
122+
app_params,
123+
client_params,
119124
ms_cv: cvlib::CorrelationVector::new(),
120125
client: reqwest::Client::new(),
121126
client2,
@@ -172,7 +177,7 @@ impl XalAuthenticator {
172177
refresh_token: &RefreshToken,
173178
) -> Result<response::XCloudTokenResponse> {
174179
let form_body = request::WindowsLiveTokenRequest {
175-
client_id: &self.client_params.app_id.clone(),
180+
client_id: &self.app_params.app_id.clone(),
176181
grant_type: "refresh_token",
177182
scope:
178183
"service::http://Passport.NET/purpose::PURPOSE_XBOX_CLOUD_CONSOLE_TRANSFER_TOKEN",
@@ -284,9 +289,9 @@ impl XalAuthenticator {
284289
headers.insert("MS-CV", self.next_cv().parse()?);
285290

286291
let json_body = request::SisuAuthenticationRequest {
287-
app_id: &self.client_params.app_id,
288-
title_id: &self.client_params.title_id,
289-
redirect_uri: &self.client_params.redirect_uri,
292+
app_id: &self.app_params.app_id,
293+
title_id: &self.app_params.title_id,
294+
redirect_uri: &self.app_params.redirect_uri,
290295
device_token,
291296
sandbox: "RETAIL",
292297
token_type: "code",
@@ -328,7 +333,7 @@ impl XalAuthenticator {
328333
) -> Result<response::SisuAuthorizationResponse> {
329334
let json_body = request::SisuAuthorizationRequest {
330335
access_token: &format!("t={}", access_token),
331-
app_id: &self.client_params.app_id.clone(),
336+
app_id: &self.app_params.app_id.clone(),
332337
device_token,
333338
sandbox: "RETAIL",
334339
site_name: "user.auth.xboxlive.com",

0 commit comments

Comments
 (0)