Add state parameter to Mastodon query
Dependencies
- [2]
W2AVMCLOLog in with Mastodon - [3]
G4JCZ5F7Store try to register on Mastodon domain - [4]
MGRTVGLJRedirect to Mastodon domain - [5]
FUCFD4UVAdd log in and log out support - [6]
BCMU6UYKStart login mastodon form - [*]
EVP2FSBHSplit index page - [*]
TEB4R7OUAdd form to join game - [*]
4MZ4VIR7Initial commit
Change contents
- edit in src/pages/mod.rs at line 49
/// Cache for OAuth state for domainpub cache_mastodon_state: Mutex<TtlCache<String, String>>, - edit in src/pages/log_in.rs at line 548
let state = Uuid::new_v4().to_string(); - replacement in src/pages/log_in.rs at line 550
let location = format!("https://{}/oauth/authorize?client_id={}&scope=read:accounts&redirect_uri={}&response_type=code",let location = format!("https://{}/oauth/authorize?client_id={}&scope=read:accounts&redirect_uri={}&response_type=code&state={}", - replacement in src/pages/log_in.rs at line 553
pct_str::PctString::encode(website_redirect.chars(), pct_str::URIReserved).as_str(),);pct_str::PctString::encode(website_redirect.chars(), pct_str::URIReserved).as_str(),state);{let mut cache = data.cache_mastodon_state.lock().await;cache.insert(state,domain,std::time::Duration::from_secs(data.cache_duration_sec),);} - edit in src/pages/log_in.rs at line 584
let mut state = None; - edit in src/pages/log_in.rs at line 589
} else if k == "state" {state = Some(v); - replacement in src/pages/log_in.rs at line 594
let code = match code {Some(r) => r,None => {let (code, state) = match (code, state) {(Some(c), Some(s)) => (c, s),_ => { - replacement in src/pages/log_in.rs at line 598
"Mastodon not redirected with code in {}","Mastodon not redirected with code or state in {}", - edit in src/pages/log_in.rs at line 605
let cached_data = {let mut cache = data.cache_mastodon_state.lock().await;cache.remove(state)};if cached_data.is_none_or(|x| x != domain) {log::warn!("Unknown state for mastodon redirect: {}", state);return HttpResponse::BadRequest().body("Incorrect");} - edit in src/main.rs at line 227
cache_mastodon_state: tokio::sync::Mutex::new(ttl_cache::TtlCache::new(cache_capacity)),