Update oauth.rs to use Android client only (fixes #8)
This commit is contained in:
parent
d327ab2c95
commit
cd836308db
@ -24,7 +24,7 @@ echo "// Please do not edit manually" >> "$filename"
|
||||
echo "// Filled in with real app versions" >> "$filename"
|
||||
|
||||
# Open the array in the source file
|
||||
echo "pub static IOS_APP_VERSION_LIST: &[&str; $ios_app_count] = &[" >> "$filename"
|
||||
echo "pub static _IOS_APP_VERSION_LIST: &[&str; $ios_app_count] = &[" >> "$filename"
|
||||
|
||||
num=0
|
||||
|
||||
@ -89,7 +89,7 @@ ios_count=$(echo "$table" | wc -l)
|
||||
echo -e "Fetching \e[34m$ios_count iOS versions...\e[0m"
|
||||
|
||||
# Append to the source file
|
||||
echo "pub static IOS_OS_VERSION_LIST: &[&str; $ios_count] = &[" >> "$filename"
|
||||
echo "pub static _IOS_OS_VERSION_LIST: &[&str; $ios_count] = &[" >> "$filename"
|
||||
|
||||
num=0
|
||||
|
||||
|
57
src/oauth.rs
57
src/oauth.rs
@ -2,7 +2,7 @@ use std::{collections::HashMap, time::Duration};
|
||||
|
||||
use crate::{
|
||||
client::{CLIENT, OAUTH_CLIENT},
|
||||
oauth_resources::{ANDROID_APP_VERSION_LIST, IOS_APP_VERSION_LIST, IOS_OS_VERSION_LIST},
|
||||
oauth_resources::ANDROID_APP_VERSION_LIST,
|
||||
};
|
||||
use base64::{engine::general_purpose, Engine as _};
|
||||
use hyper::{client, Body, Method, Request};
|
||||
@ -11,11 +11,10 @@ use log::info;
|
||||
use serde_json::json;
|
||||
|
||||
static REDDIT_ANDROID_OAUTH_CLIENT_ID: &str = "ohXpoqrZYub1kg";
|
||||
static REDDIT_IOS_OAUTH_CLIENT_ID: &str = "LNDo9k1o8UAEUw";
|
||||
|
||||
static AUTH_ENDPOINT: &str = "https://accounts.reddit.com";
|
||||
|
||||
// Spoofed client for Android and iOS devices
|
||||
// Spoofed client for Android devices
|
||||
#[derive(Debug, Clone, Default)]
|
||||
pub struct Oauth {
|
||||
pub(crate) initial_headers: HashMap<String, String>,
|
||||
@ -32,8 +31,8 @@ impl Oauth {
|
||||
oauth
|
||||
}
|
||||
pub(crate) fn default() -> Self {
|
||||
// Generate a random device to spoof
|
||||
let device = Device::random();
|
||||
// Generate a device to spoof
|
||||
let device = Device::new();
|
||||
let headers_map = device.headers.clone();
|
||||
let initial_headers = device.initial_headers.clone();
|
||||
// For now, just insert headers - no token request
|
||||
@ -163,49 +162,9 @@ impl Device {
|
||||
initial_headers: headers,
|
||||
}
|
||||
}
|
||||
fn ios() -> Self {
|
||||
// Generate uuid
|
||||
let uuid = uuid::Uuid::new_v4().to_string();
|
||||
|
||||
// Generate random user-agent
|
||||
let ios_app_version = choose(IOS_APP_VERSION_LIST).to_string();
|
||||
let ios_os_version = choose(IOS_OS_VERSION_LIST).to_string();
|
||||
let ios_user_agent = format!("Reddit/{ios_app_version}/iOS {ios_os_version}");
|
||||
|
||||
// Generate random device
|
||||
let ios_device_num = fastrand::u8(8..=15).to_string();
|
||||
let ios_device = format!("iPhone{ios_device_num},1").to_string();
|
||||
|
||||
let initial_headers = HashMap::from([
|
||||
("X-Reddit-DPR".into(), "2".into()),
|
||||
("User-Agent".into(), ios_user_agent.clone()),
|
||||
("Device-Name".into(), ios_device.clone()),
|
||||
]);
|
||||
let headers = HashMap::from([
|
||||
("X-Reddit-DPR".into(), "2".into()),
|
||||
("Device-Name".into(), ios_device.clone()),
|
||||
("User-Agent".into(), ios_user_agent),
|
||||
("Client-Vendor-Id".into(), uuid.clone()),
|
||||
("x-dev-ad-id".into(), "00000000-0000-0000-0000-000000000000".into()),
|
||||
("Reddit-User_Id".into(), "anonymous_browsing_mode".into()),
|
||||
("x-reddit-device-id".into(), uuid.clone()),
|
||||
]);
|
||||
|
||||
info!("[🔄] Spoofing iOS client {ios_device} with headers: {headers:?}, uuid: \"{uuid}\", and OAuth ID \"{REDDIT_IOS_OAUTH_CLIENT_ID}\"");
|
||||
|
||||
Self {
|
||||
oauth_id: REDDIT_IOS_OAUTH_CLIENT_ID.to_string(),
|
||||
initial_headers,
|
||||
headers,
|
||||
}
|
||||
}
|
||||
// Randomly choose a device
|
||||
fn random() -> Self {
|
||||
if fastrand::bool() {
|
||||
Self::android()
|
||||
} else {
|
||||
Self::ios()
|
||||
}
|
||||
fn new() -> Self {
|
||||
// See https://github.com/redlib-org/redlib/issues/8
|
||||
Self::android()
|
||||
}
|
||||
}
|
||||
|
||||
@ -234,5 +193,5 @@ async fn test_oauth_headers_len() {
|
||||
|
||||
#[test]
|
||||
fn test_creating_device() {
|
||||
Device::random();
|
||||
Device::new();
|
||||
}
|
||||
|
@ -2,7 +2,7 @@
|
||||
// Rerun scripts/update_oauth_resources.sh to update this file
|
||||
// Please do not edit manually
|
||||
// Filled in with real app versions
|
||||
pub static IOS_APP_VERSION_LIST: &[&str; 67] = &[
|
||||
pub static _IOS_APP_VERSION_LIST: &[&str; 67] = &[
|
||||
"Version 2020.0.0/Build 306960",
|
||||
"Version 2020.10.0/Build 307041",
|
||||
"Version 2020.10.1/Build 307047",
|
||||
@ -223,7 +223,7 @@ pub static ANDROID_APP_VERSION_LIST: &[&str; 150] = &[
|
||||
"Version 2021.43.0/Build 382019",
|
||||
"Version 2021.44.0/Build 385129",
|
||||
];
|
||||
pub static IOS_OS_VERSION_LIST: &[&str; 8] = &[
|
||||
pub static _IOS_OS_VERSION_LIST: &[&str; 8] = &[
|
||||
"Version 17.0.1 (Build 21A340)",
|
||||
"Version 17.0.2 (Build 21A350)",
|
||||
"Version 17.0.3 (Build 21A360)",
|
||||
|
14
src/utils.rs
14
src/utils.rs
@ -1108,3 +1108,17 @@ mod tests {
|
||||
assert_eq!(format_url("spoiler"), "");
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
|
||||
async fn test_fetching_subreddit_quarantined() {
|
||||
let subreddit = Post::fetch("/r/drugs", true).await;
|
||||
assert!(subreddit.is_ok());
|
||||
assert!(!subreddit.unwrap().0.is_empty());
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
|
||||
async fn test_fetching_nsfw_subreddit() {
|
||||
let subreddit = Post::fetch("/r/randnsfw", false).await;
|
||||
assert!(subreddit.is_ok());
|
||||
assert!(!subreddit.unwrap().0.is_empty());
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user