An easy-to-host PDS on the ATProtocol, iPhone and MacOS. Maintain control of your keys and data, always.
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

refactor: move RelayClient to AppState, remove RelayClient::base_url() static method

Update start_oauth_flow() and related code to use relay_client from AppState instead of static RelayClient::base_url(). Remove the now-unused static base_url() method from RelayClient.

- Replace crate::http::RelayClient::new() with state.relay_client()
- Replace all crate::http::RelayClient::base_url() calls with state.relay_client().base_url_str()
- Update test calls to use new default_relay_url() free function
- Remove static base_url() method from RelayClient
- Update http.rs module documentation to reflect runtime configurability

This completes the removal of the static RELAY_CLIENT global and ensures all relay client access flows through AppState.

authored by

Malpercio and committed by
Tangled
479aa9bd e436a5ab

+10 -16
+4 -10
apps/identity-wallet/src-tauri/src/http.rs
··· 1 1 //! Relay HTTP client for identity-wallet. 2 2 //! 3 - //! All relay API calls go through `RelayClient`. The base URL is 4 - //! compile-time configured: `http://localhost:8080` in debug builds, 5 - //! `https://relay.ezpds.com` in release builds. 3 + //! All relay API calls go through `RelayClient`. The base URL starts 4 + //! as compile-time configured (`http://localhost:8080` in debug builds, 5 + //! `https://relay.ezpds.com` in release builds) and can be overridden 6 + //! at runtime via AppState. 6 7 7 8 use reqwest::{Client, Response}; 8 9 use serde::Serialize; ··· 207 208 OAuthError::TokenExchangeFailed 208 209 })?; 209 210 Ok(resp) 210 - } 211 - 212 - /// Returns the compile-time base URL for this relay client instance. 213 - /// 214 - /// Used as the `service_endpoint` parameter in DID ceremony genesis op construction. 215 - pub const fn base_url() -> &'static str { 216 - RELAY_BASE_URL 217 211 } 218 212 219 213 /// Returns the base URL for this relay client instance.
+6 -6
apps/identity-wallet/src-tauri/src/oauth.rs
··· 400 400 // OpenerExt adds the `.opener()` method to AppHandle. 401 401 use tauri_plugin_opener::OpenerExt; 402 402 403 - let relay = crate::http::RelayClient::new(); 403 + let relay = state.relay_client(); 404 404 405 405 // 1. Generate PKCE and CSRF state. 406 406 let (pkce_verifier, pkce_challenge) = pkce::generate(); ··· 410 410 let dpop = DPoPKeypair::get_or_create()?; 411 411 let dpop_jkt = dpop.public_jwk_thumbprint(); 412 412 413 - let par_htu = format!("{}/oauth/par", crate::http::RelayClient::base_url()); 413 + let par_htu = format!("{}/oauth/par", state.relay_client().base_url_str()); 414 414 let par_proof = dpop.make_proof("POST", &par_htu, None, None)?; 415 415 416 416 // 3. PAR call. ··· 437 437 438 438 // 5. Open Safari to the authorization endpoint. 439 439 let auth_url = { 440 - let base = crate::http::RelayClient::base_url(); 440 + let base = state.relay_client().base_url_str(); 441 441 let request_uri_encoded = 442 442 url::form_urlencoded::byte_serialize(par_resp.request_uri.as_bytes()) 443 443 .collect::<String>(); ··· 465 465 let callback = rx.await.map_err(|_| OAuthError::CallbackAbandoned)??; 466 466 467 467 // 7. Token exchange. 468 - let token_htu = format!("{}/oauth/token", crate::http::RelayClient::base_url()); 468 + let token_htu = format!("{}/oauth/token", state.relay_client().base_url_str()); 469 469 let (token_resp, initial_nonce) = 470 470 exchange_code_with_retry(&relay, &dpop, &callback.code, &pkce_verifier, &token_htu).await?; 471 471 ··· 802 802 let keypair = DPoPKeypair::get_or_create().expect("keypair must generate"); 803 803 // `htu` is embedded in the DPoP proof JWT claims (the `htu` claim per RFC 9449 §4.2), 804 804 // not used for the HTTP request itself — `relay.par()` constructs the URL internally. 805 - let htu = format!("{}/oauth/par", crate::http::RelayClient::base_url()); 805 + let htu = format!("{}/oauth/par", crate::http::default_relay_url()); 806 806 let dpop_proof = keypair 807 807 .make_proof("POST", &htu, None, None) 808 808 .expect("DPoP proof must build"); ··· 834 834 #[ignore = "requires running relay at localhost:8080"] 835 835 async fn par_missing_code_challenge_returns_client_error() { 836 836 // Build a minimal PAR form body with no code_challenge field. 837 - let base_url = crate::http::RelayClient::base_url(); 837 + let base_url = crate::http::default_relay_url(); 838 838 let url = format!("{base_url}/oauth/par"); 839 839 let keypair = DPoPKeypair::get_or_create().expect("keypair must generate"); 840 840 let dpop_proof = keypair