π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Remove Rust accounts URL fallback
Manav Rathi6a57528bb1ba
diff --git a/rust/crates/accounts/src/flow.rs b/rust/crates/accounts/src/flow.rsindex d3fa730aed..b7f9c22334 100644--- a/rust/crates/accounts/src/flow.rs+++ b/rust/crates/accounts/src/flow.rs@@ -28,7 +28,7 @@ use crate::{TwoFactorAuthorizationResponse, TwoFactorRecoveryResponse, TwoFactorType,UpdateSrpAndKeysRequest, UpdatedKeyAttr,},- types::{AccountSecrets, DEFAULT_ACCOUNTS_URL},+ types::AccountSecrets,};const SRP_A_LEN: usize = 512;@@ -790,10 +790,8 @@ wherelet accounts_url = auth_response.accounts_url- .as_ref()- .filter(|url| !url.is_empty())- .map(String::as_str)- .unwrap_or(DEFAULT_ACCOUNTS_URL);+ .as_deref()+ .expect("accountsUrl is required when passkeySessionID is present");let verification_url = build_passkey_verification_url(accounts_url,diff --git a/rust/crates/accounts/src/lib.rs b/rust/crates/accounts/src/lib.rsindex 2285c87045..18dc4c9bb8 100644--- a/rust/crates/accounts/src/lib.rs+++ b/rust/crates/accounts/src/lib.rs@@ -20,4 +20,4 @@ pub use flow::{SecondFactorMethod, SessionValidity, SetupTwoFactorParams, SetupTwoFactorResult, TotpPurpose,};pub use models::KeyAttributes;-pub use types::{AccountSecrets, AccountsClientConfig, DEFAULT_ACCOUNTS_URL};+pub use types::{AccountSecrets, AccountsClientConfig};diff --git a/rust/crates/accounts/src/models.rs b/rust/crates/accounts/src/models.rsindex b02677b767..9873e19b22 100644--- a/rust/crates/accounts/src/models.rs+++ b/rust/crates/accounts/src/models.rs@@ -74,6 +74,7 @@ pub struct KeyAttributes {/// Auth response emitted by login and verification endpoints.#[derive(Deserialize, Serialize, Clone)]+#[serde(try_from = "AuthResponseWire")]#[serde(rename_all = "camelCase")]pub struct AuthResponse {/// User ID.@@ -99,6 +100,53 @@ pub struct AuthResponse {pub accounts_url: Option<String>,}+#[derive(Deserialize)]+#[serde(rename_all = "camelCase")]+struct AuthResponseWire {+ id: i64,+ key_attributes: Option<KeyAttributes>,+ encrypted_token: Option<String>,+ token: Option<String>,+ #[serde(rename = "twoFactorSessionID")]+ two_factor_session_id: Option<String>,+ #[serde(rename = "twoFactorSessionIDV2")]+ two_factor_session_id_v2: Option<String>,+ #[serde(rename = "passkeySessionID")]+ passkey_session_id: Option<String>,+ srp_m2: Option<String>,+ accounts_url: Option<String>,+}++impl TryFrom<AuthResponseWire> for AuthResponse {+ type Error = String;++ fn try_from(value: AuthResponseWire) -> std::result::Result<Self, Self::Error> {+ if value+ .passkey_session_id+ .as_ref()+ .is_some_and(|session_id| !session_id.is_empty())+ && value+ .accounts_url+ .as_ref()+ .map_or(true, |accounts_url| accounts_url.is_empty())+ {+ return Err("accountsUrl is required when passkeySessionID is present".into());+ }++ Ok(Self {+ id: value.id,+ key_attributes: value.key_attributes,+ encrypted_token: value.encrypted_token,+ token: value.token,+ two_factor_session_id: value.two_factor_session_id,+ two_factor_session_id_v2: value.two_factor_session_id_v2,+ passkey_session_id: value.passkey_session_id,+ srp_m2: value.srp_m2,+ accounts_url: value.accounts_url,+ })+ }+}+impl fmt::Debug for AuthResponse {fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {f.debug_struct("AuthResponse")@@ -495,3 +543,25 @@ pub struct AccountsTokenResponse {/// JWT for the accounts app.pub accounts_token: String,}++#[cfg(test)]+mod tests {+ use super::AuthResponse;++ #[test]+ fn auth_response_requires_accounts_url_for_passkey() {+ let error =+ serde_json::from_str::<AuthResponse>(r#"{"id":1,"passkeySessionID":"session"}"#)+ .unwrap_err();++ assert!(error.to_string().contains("accountsUrl is required"));+ }++ #[test]+ fn auth_response_allows_missing_accounts_url_without_passkey() {+ let response = serde_json::from_str::<AuthResponse>(r#"{"id":1}"#).unwrap();++ assert_eq!(response.id, 1);+ assert!(response.accounts_url.is_none());+ }+}diff --git a/rust/crates/accounts/src/types.rs b/rust/crates/accounts/src/types.rsindex 7a1b88f852..5034b5c45c 100644--- a/rust/crates/accounts/src/types.rs+++ b/rust/crates/accounts/src/types.rs@@ -9,9 +9,6 @@ use zeroize::Zeroize;/// Default base URL for Ente's public API.pub const DEFAULT_API_BASE_URL: &str = PRODUCTION_API_BASE_URL;-/// Default base URL for Ente's accounts broker.-pub const DEFAULT_ACCOUNTS_URL: &str = "https://accounts.ente.com";-/// Boxed future returned by a configured sleep hook.pub type SleepFuture = Pin<Box<dyn Future<Output = ()> + 'static>>;