Skip to content

Commit 2dc6b5f

Browse files
committed
feat(oauth): add additional fallback oauth backend
1 parent a989d19 commit 2dc6b5f

File tree

4 files changed

+352
-84
lines changed

4 files changed

+352
-84
lines changed

Cargo.lock

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ htmlescape = "0.3.1"
5959
bincode = "1.3.3"
6060
base2048 = "2.0.2"
6161
revision = "0.10.0"
62+
fake_user_agent = "0.2.2"
6263

6364

6465
[dev-dependencies]

src/client.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use std::sync::LazyLock;
1717
use std::{io, result::Result};
1818

1919
use crate::dbg_msg;
20-
use crate::oauth::{force_refresh_token, token_daemon, Oauth};
20+
use crate::oauth::{force_refresh_token, token_daemon, Oauth, OauthBackendImpl};
2121
use crate::server::RequestExt;
2222
use crate::utils::{format_url, Post};
2323

@@ -494,11 +494,17 @@ async fn self_check(sub: &str) -> Result<(), String> {
494494
}
495495

496496
pub async fn rate_limit_check() -> Result<(), String> {
497+
// First, test the Oauth client: we can perform a rate limit check if the OAuth backend is MobileSpoof; if GenericWeb, we skip the check.
498+
if matches!(OAUTH_CLIENT.load().backend, OauthBackendImpl::GenericWeb(_)) {
499+
warn!("[⚠️] Cannot perform rate limit check, running as GenericWeb. Skipping check.");
500+
return Ok(());
501+
}
502+
497503
// First, check a subreddit.
498504
self_check("reddit").await?;
499505
// This will reduce the rate limit to 99. Assert this check.
500506
if OAUTH_RATELIMIT_REMAINING.load(Ordering::SeqCst) != 99 {
501-
return Err(format!("Rate limit check failed: expected 99, got {}", OAUTH_RATELIMIT_REMAINING.load(Ordering::SeqCst)));
507+
return Err(format!("Rate limit check 1 failed: expected 99, got {}", OAUTH_RATELIMIT_REMAINING.load(Ordering::SeqCst)));
502508
}
503509
// Now, we switch out the OAuth client.
504510
// This checks for the IP rate limit association.
@@ -507,7 +513,7 @@ pub async fn rate_limit_check() -> Result<(), String> {
507513
self_check("rust").await?;
508514
// Again, assert the rate limit check.
509515
if OAUTH_RATELIMIT_REMAINING.load(Ordering::SeqCst) != 99 {
510-
return Err(format!("Rate limit check failed: expected 99, got {}", OAUTH_RATELIMIT_REMAINING.load(Ordering::SeqCst)));
516+
return Err(format!("Rate limit check 2 failed: expected 99, got {}", OAUTH_RATELIMIT_REMAINING.load(Ordering::SeqCst)));
511517
}
512518

513519
Ok(())

0 commit comments

Comments
 (0)