Skip to content

Commit 90b5bdd

Browse files
Bug 1925091 - Make Android FxaAccountManager supply comma-separate list of values for service=sync
1 parent 59aaf6c commit 90b5bdd

File tree

6 files changed

+68
-20
lines changed

6 files changed

+68
-20
lines changed

components/fxa-client/src/auth.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,9 @@ impl FirefoxAccount {
8989
) -> ApiResult<String> {
9090
let scopes = scopes.iter().map(T::as_ref).collect::<Vec<_>>();
9191
let service = service.iter().map(AsRef::as_ref).collect::<Vec<_>>();
92-
self.internal.lock().begin_oauth_flow(&scopes, entrypoint, &service)
92+
self.internal
93+
.lock()
94+
.begin_oauth_flow(&scopes, entrypoint, &service)
9395
}
9496

9597
/// Get the URL at which to begin a device-pairing signin flow.

components/fxa-client/src/internal/oauth.rs

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ impl FirefoxAccount {
135135
pairing_url: &str,
136136
scopes: &[&str],
137137
entrypoint: &str,
138-
service: &[&str]
138+
service: &[&str],
139139
) -> Result<String> {
140140
let mut url = self.state.config().pair_supp_url()?;
141141
let service_param = service.join(",");
@@ -160,7 +160,12 @@ impl FirefoxAccount {
160160
/// * `entrypoint` - The entrypoint to be used for metrics
161161
/// * `service` - Space-separated list of requested services.
162162
/// * `metrics` - Optional metrics parameters
163-
pub fn begin_oauth_flow(&mut self, scopes: &[&str], entrypoint: &str, service: &[&str]) -> Result<String> {
163+
pub fn begin_oauth_flow(
164+
&mut self,
165+
scopes: &[&str],
166+
entrypoint: &str,
167+
service: &[&str],
168+
) -> Result<String> {
164169
self.state.on_begin_oauth();
165170
let mut url = if self.state.last_seen_profile().is_some() {
166171
self.state.config().oauth_force_auth_url()?
@@ -623,15 +628,15 @@ mod tests {
623628
);
624629
let mut fxa = FirefoxAccount::with_config(config);
625630
let url = fxa
626-
.begin_oauth_flow(&["profile"], "test_oauth_flow_url")
631+
.begin_oauth_flow(&["profile"], "test_oauth_flow_url", &["sync"])
627632
.unwrap();
628633
let flow_url = Url::parse(&url).unwrap();
629634

630635
assert_eq!(flow_url.host_str(), Some("accounts.firefox.com"));
631636
assert_eq!(flow_url.path(), "/authorization");
632637

633638
let mut pairs = flow_url.query_pairs();
634-
assert_eq!(pairs.count(), 11);
639+
assert_eq!(pairs.count(), 12);
635640
assert_eq!(
636641
pairs.next(),
637642
Some((Cow::Borrowed("action"), Cow::Borrowed("email")))
@@ -647,6 +652,10 @@ mod tests {
647652
Cow::Borrowed("test_oauth_flow_url")
648653
))
649654
);
655+
assert_eq!(
656+
pairs.next(),
657+
Some((Cow::Borrowed("service"), Cow::Borrowed("sync")))
658+
);
650659
assert_eq!(
651660
pairs.next(),
652661
Some((Cow::Borrowed("client_id"), Cow::Borrowed("12345678")))
@@ -740,7 +749,12 @@ mod tests {
740749
);
741750
let mut fxa = FirefoxAccount::with_config(config);
742751
let url = fxa
743-
.begin_pairing_flow(PAIRING_URL, SCOPES, "test_webchannel_pairing_context_url", &["sync".to_owned()])
752+
.begin_pairing_flow(
753+
PAIRING_URL,
754+
SCOPES,
755+
"test_webchannel_pairing_context_url",
756+
&["sync"],
757+
)
744758
.unwrap();
745759
let url = Url::parse(&url).unwrap();
746760
let query_params: HashMap<_, _> = url.query_pairs().into_owned().collect();
@@ -764,7 +778,7 @@ mod tests {
764778

765779
let mut fxa = FirefoxAccount::with_config(config);
766780
let url = fxa
767-
.begin_pairing_flow(PAIRING_URL, SCOPES, "test_pairing_flow_url")
781+
.begin_pairing_flow(PAIRING_URL, SCOPES, "test_pairing_flow_url", &["sync"])
768782
.unwrap();
769783
let flow_url = Url::parse(&url).unwrap();
770784
let expected_parsed_url = Url::parse(EXPECTED_URL).unwrap();
@@ -774,14 +788,18 @@ mod tests {
774788
assert_eq!(flow_url.fragment(), expected_parsed_url.fragment());
775789

776790
let mut pairs = flow_url.query_pairs();
777-
assert_eq!(pairs.count(), 9);
791+
assert_eq!(pairs.count(), 10);
778792
assert_eq!(
779793
pairs.next(),
780794
Some((
781795
Cow::Borrowed("entrypoint"),
782796
Cow::Borrowed("test_pairing_flow_url")
783797
))
784798
);
799+
assert_eq!(
800+
pairs.next(),
801+
Some((Cow::Borrowed("service"), Cow::Borrowed("sync")))
802+
);
785803
assert_eq!(
786804
pairs.next(),
787805
Some((Cow::Borrowed("client_id"), Cow::Borrowed("12345678")))
@@ -834,6 +852,7 @@ mod tests {
834852
PAIRING_URL,
835853
&["https://identity.mozilla.com/apps/oldsync"],
836854
"test_pairiong_flow_origin_mismatch",
855+
&["sync"],
837856
);
838857

839858
assert!(url.is_err());

components/fxa-client/src/state_machine/checker.rs

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -219,9 +219,15 @@ impl From<InternalState> for FxaStateCheckerState {
219219
fn from(state: InternalState) -> Self {
220220
match state {
221221
InternalState::GetAuthState => Self::GetAuthState,
222-
InternalState::BeginOAuthFlow { scopes, entrypoint, service } => {
223-
Self::BeginOAuthFlow { scopes, entrypoint, service }
224-
}
222+
InternalState::BeginOAuthFlow {
223+
scopes,
224+
entrypoint,
225+
service,
226+
} => Self::BeginOAuthFlow {
227+
scopes,
228+
entrypoint,
229+
service,
230+
},
225231
InternalState::BeginPairingFlow {
226232
pairing_url,
227233
scopes,
@@ -251,9 +257,15 @@ impl From<FxaStateCheckerState> for InternalState {
251257
fn from(state: FxaStateCheckerState) -> Self {
252258
match state {
253259
FxaStateCheckerState::GetAuthState => Self::GetAuthState,
254-
FxaStateCheckerState::BeginOAuthFlow { scopes, entrypoint, service } => {
255-
Self::BeginOAuthFlow { scopes, entrypoint, service }
256-
}
260+
FxaStateCheckerState::BeginOAuthFlow {
261+
scopes,
262+
entrypoint,
263+
service,
264+
} => Self::BeginOAuthFlow {
265+
scopes,
266+
entrypoint,
267+
service,
268+
},
257269
FxaStateCheckerState::BeginPairingFlow {
258270
pairing_url,
259271
scopes,

components/fxa-client/src/state_machine/internal_machines/auth_issues.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@ use State::*;
1414
impl InternalStateMachine for AuthIssuesStateMachine {
1515
fn initial_state(&self, event: FxaEvent) -> Result<State> {
1616
match event {
17-
FxaEvent::BeginOAuthFlow { scopes, entrypoint, service } => Ok(BeginOAuthFlow {
17+
FxaEvent::BeginOAuthFlow {
18+
scopes,
19+
entrypoint,
20+
service,
21+
} => Ok(BeginOAuthFlow {
1822
scopes: scopes.clone(),
1923
entrypoint: entrypoint.clone(),
2024
service: service.clone(),

components/fxa-client/src/state_machine/internal_machines/disconnected.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,15 @@ use State::*;
1414
impl InternalStateMachine for DisconnectedStateMachine {
1515
fn initial_state(&self, event: FxaEvent) -> Result<State> {
1616
match event {
17-
FxaEvent::BeginOAuthFlow { scopes, entrypoint, service } => {
18-
Ok(State::BeginOAuthFlow { scopes, entrypoint, service })
19-
}
17+
FxaEvent::BeginOAuthFlow {
18+
scopes,
19+
entrypoint,
20+
service,
21+
} => Ok(State::BeginOAuthFlow {
22+
scopes,
23+
entrypoint,
24+
service,
25+
}),
2026
FxaEvent::BeginPairingFlow {
2127
pairing_url,
2228
scopes,

components/fxa-client/src/state_machine/internal_machines/mod.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,11 @@ impl State {
126126
account.ensure_capabilities(&device_config.capabilities)?;
127127
Event::EnsureDeviceCapabilitiesSuccess
128128
}
129-
State::BeginOAuthFlow { scopes, entrypoint ,service} => {
129+
State::BeginOAuthFlow {
130+
scopes,
131+
entrypoint,
132+
service,
133+
} => {
130134
let scopes: Vec<&str> = scopes.iter().map(String::as_str).collect();
131135
let service: Vec<&str> = service.iter().map(AsRef::as_ref).collect();
132136
let oauth_url = account.begin_oauth_flow(&scopes, entrypoint, &service)?;
@@ -140,7 +144,8 @@ impl State {
140144
} => {
141145
let scopes: Vec<&str> = scopes.iter().map(String::as_str).collect();
142146
let service: Vec<&str> = service.iter().map(AsRef::as_ref).collect();
143-
let oauth_url = account.begin_pairing_flow(pairing_url, &scopes, entrypoint, &service)?;
147+
let oauth_url =
148+
account.begin_pairing_flow(pairing_url, &scopes, entrypoint, &service)?;
144149
Event::BeginPairingFlowSuccess { oauth_url }
145150
}
146151
State::CompleteOAuthFlow { code, state } => {

0 commit comments

Comments
 (0)