Allow side-stepping the typed grandslam API
Dadoum

Dadoum commited on 2026-09-28 03:16:10
Showing 1 changed files, with 25 additions and 7 deletions.

... ...
@@ -9,7 +9,7 @@ use aes_gcm::{AesGcm, KeyInit};
9 9
 use base64::Engine;
10 10
 use base64::prelude::BASE64_STANDARD;
11 11
 use hmac::{Hmac, Mac};
12
-use log::{trace, warn};
12
+use log::warn;
13 13
 use plist::{Dictionary, Value};
14 14
 use plist_macros::{array, dict};
15 15
 use reqwest::{Method, RequestBuilder};
... ...
@@ -146,7 +146,24 @@ impl<'lt, 'adi> AccountHTTPSession<'lt, 'adi> {
146 146
         session_key: &SessionKey,
147 147
         cookie: &AuthCookie,
148 148
     ) -> Result<Token<T>, AppTokenRequestError> {
149
-        let app_token_identifier = T::APP_TOKEN_IDENTIFIER;
149
+        let token = self
150
+            .get_app_token_for_service(T::APP_TOKEN_IDENTIFIER, idms_token, session_key, cookie)
151
+            .await?;
152
+        Ok(Token {
153
+            duration: token.duration,
154
+            expiry_epoch_millis: token.expiry_epoch_millis,
155
+            token: T::from(token.token),
156
+        })
157
+    }
158
+
159
+    /// Request a token for a service identifier supplied at runtime.
160
+    pub async fn get_app_token_for_service(
161
+        &self,
162
+        app_token_identifier: &str,
163
+        idms_token: &IdmsToken,
164
+        session_key: &SessionKey,
165
+        cookie: &AuthCookie,
166
+    ) -> Result<Token, AppTokenRequestError> {
150 167
         let alt_dsid = self.alt_dsid.0.as_str();
151 168
 
152 169
         let gs_service_url = self
... ...
@@ -209,8 +226,6 @@ impl<'lt, 'adi> AccountHTTPSession<'lt, 'adi> {
209 226
             .and_then(|response| response.as_dictionary())
210 227
             .ok_or_else(|| AppTokenRequestError::Structure(response_plist.clone()))?;
211 228
 
212
-        // println!("Response: {response_dict:?}");
213
-
214 229
         let status = response_dict
215 230
             .get("Status")
216 231
             .and_then(|status| status.as_dictionary())
... ...
@@ -251,12 +266,15 @@ impl<'lt, 'adi> AccountHTTPSession<'lt, 'adi> {
251 266
         let tokens: Dictionary =
252 267
             plist::from_bytes(&tokens_data).map_err(AppTokenRequestError::Parsing)?;
253 268
 
254
-        trace!("Decrypted token response: {:#?}", tokens);
255
-
256 269
         let tokens = ServerProvidedData(tokens);
257 270
         tokens
258 271
             .tokens()
259
-            .and_then(|tokens| tokens.get())
272
+            .and_then(|tokens| {
273
+                tokens
274
+                    .0
275
+                    .get(app_token_identifier)
276
+                    .and_then(|token| plist::from_value(token).ok())
277
+            })
260 278
             .ok_or_else(|| AppTokenRequestError::InvalidResponse(tokens.0))
261 279
     }
262 280
 
263 281