Skip to content

Commit

Permalink
Initial code import
Browse files Browse the repository at this point in the history
  • Loading branch information
tuxuser committed Nov 13, 2022
1 parent ca56745 commit a49c793
Show file tree
Hide file tree
Showing 9 changed files with 1,792 additions and 14 deletions.
36 changes: 35 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,44 @@
[package]
name = "xal"
version = "0.1.0"
edition = "2021"
edition = "2018"
description = "Xbox Authentication library"
license = "MIT"
repository = "https://github.com/OpenXbox/xal-rs"
homepage = "https://openxbox.org"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
reqwest = { version = "0.11", features = ["json"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
cvlib = "0.1.2"
filetime_type = "0.1"
base64 = "0.13.0"
chrono = "0.4"
josekit = "0.8"
uuid = { version = "1", features = ["v4"] }
oauth2 = "4.3"

# common for bins
tokio = { version = "1", features = ["full"], optional = true }

# auth_webview
tauri = { version = "1.1.1", optional = true }
wry = { version = "0.21.1", optional = true }

[dev-dependencies]
hex-literal = "0.3.4"

[features]
webview = ["dep:tauri", "dep:wry"]
tokio = ["dep:tokio"]

[[bin]]
name = "auth-cli"
required-features = ["tokio"]

[[bin]]
name = "auth-webview"
required-features = ["webview"]
152 changes: 152 additions & 0 deletions src/app_params.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
use serde::{Deserialize, Serialize};
use std::str::FromStr;

#[derive(Debug, Serialize, Deserialize, Eq, PartialEq, Copy, Clone)]
pub enum DeviceType {
IOS,
ANDROID,
WIN32,
}

impl FromStr for DeviceType {
type Err = Box<dyn std::error::Error>;

fn from_str(s: &str) -> Result<Self, Self::Err> {
let enm = match s.to_lowercase().as_ref() {
"android" => DeviceType::ANDROID,
"ios" => DeviceType::IOS,
"win32" => DeviceType::WIN32,
val => {
return Err(format!("Unhandled device type: '{}'", val).into());
}
};
Ok(enm)
}
}

impl ToString for DeviceType {
fn to_string(&self) -> String {
let str = match self {
DeviceType::ANDROID => "Android",
DeviceType::IOS => "iOS",
DeviceType::WIN32 => "Win32",
};
str.to_owned()
}
}

#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct XalAppParameters {
pub app_id: String,
pub title_id: String,
pub redirect_uri: String,
}

impl XalAppParameters {
pub fn xbox_app_beta() -> Self {
Self {
app_id: "000000004415494b".into(),
title_id: "177887386".into(),
redirect_uri: "ms-xal-000000004415494b://auth".into(),
}
}

pub fn xbox_app() -> Self {
Self {
app_id: "000000004c12ae6f".into(),
title_id: "328178078".into(),
redirect_uri: "ms-xal-000000004c12ae6f://auth".into(),
}
}

pub fn gamepass() -> Self {
Self {
app_id: "000000004c20a908".into(),
title_id: "1016898439".into(),
redirect_uri: "ms-xal-000000004c20a908://auth".into(),
}
}

pub fn gamepass_beta() -> Self {
Self {
app_id: "000000004c20a908".into(),
title_id: "1016898439".into(),
redirect_uri: "ms-xal-public-beta-000000004c20a908://auth".into(),
}
}

/// Family settings is somewhat special
/// Uses default oauth20_desktop.srf redirect uri
pub fn family_settings() -> Self {
Self {
app_id: "00000000482C8F49".into(),
title_id: "1618633878".into(),
redirect_uri: "https://login.live.com/oauth20_desktop.srf".into(),
}
}
}

impl Default for XalAppParameters {
fn default() -> Self {
Self::gamepass_beta()
}
}

#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct XalClientParameters {
pub user_agent: String,
pub device_type: DeviceType,
pub client_version: String,
pub query_display: String,
}

impl XalClientParameters {
pub fn ios() -> Self {
Self {
user_agent: "XAL iOS 2021.11.20211021.000".into(),
device_type: DeviceType::IOS,
client_version: "15.6.1".into(),
query_display: "ios_phone".into(),
}
}

pub fn android() -> Self {
Self {
user_agent: "XAL Android 2020.07.20200714.000".into(),
device_type: DeviceType::ANDROID,
client_version: "8.0.0".into(),
query_display: "android_phone".into(),
}
}
}

impl Default for XalClientParameters {
fn default() -> Self {
Self::android()
}
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn devicetype_enum_into() {
assert_eq!(DeviceType::WIN32.to_string(), "Win32");
assert_eq!(DeviceType::ANDROID.to_string(), "Android");
assert_eq!(DeviceType::IOS.to_string(), "iOS");
}

#[test]
fn str_into_devicetype_enum() {
assert_eq!(DeviceType::from_str("win32").unwrap(), DeviceType::WIN32);
assert_eq!(DeviceType::from_str("Win32").unwrap(), DeviceType::WIN32);
assert_eq!(DeviceType::from_str("WIN32").unwrap(), DeviceType::WIN32);
assert_eq!(
DeviceType::from_str("android").unwrap(),
DeviceType::ANDROID
);
assert_eq!(DeviceType::from_str("ios").unwrap(), DeviceType::IOS);
assert!(DeviceType::from_str("androidx").is_err());
}
}
Loading

0 comments on commit a49c793

Please sign in to comment.