cobble_core/profile/
xsts.rs

1use crate::{consts, error::AuthResult};
2use serde::Deserialize;
3use serde_json::json;
4
5#[derive(Debug, Clone)]
6pub struct XstsToken {
7    pub access_token: String,
8}
9
10#[instrument(name = "authenticate_xsts", level = "trace", skip_all)]
11pub async fn authenticate(xbl_token: &str) -> AuthResult<XstsToken> {
12    let client = reqwest::Client::new();
13    let response = client
14        .post(consts::XSTS_TOKEN_URL)
15        .json(&json!({
16            "Properties": {
17                "SandboxId": "RETAIL",
18                "UserTokens": [
19                    xbl_token
20                ]
21            },
22            "RelyingParty": "rp://api.minecraftservices.com/",
23            "TokenType": "JWT"
24        }))
25        .send()
26        .await?
27        .error_for_status()?
28        .json::<XboxLiveSecurityTokenResponse>()
29        .await?;
30
31    Ok(XstsToken {
32        access_token: response.token,
33    })
34}
35
36#[derive(Clone, Debug, Deserialize)]
37#[serde(rename_all = "PascalCase")]
38struct XboxLiveSecurityTokenResponse {
39    token: String,
40}