Skip to content

Commit

Permalink
Merge pull request #17902 from mozilla/FXA-10614
Browse files Browse the repository at this point in the history
fix(sync): Adjust fxaLogin / fxaOAuthLogin web channel data for oauth desktop
  • Loading branch information
vpomerleau authored Oct 25, 2024
2 parents e272f94 + 9c4cd61 commit ad18787
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 33 deletions.
25 changes: 14 additions & 11 deletions packages/fxa-settings/src/lib/channels/firefox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,17 @@ export type FxALoginRequest = {
keyFetchToken?: hexstring;
unwrapBKey?: string;
verifiedCanLinkAccount?: boolean;
services?: {
sync: {
offeredEngines?: string[];
declinedEngines?: string[];
};
};
services?:
| {
sync: {
offeredEngines?: string[];
declinedEngines?: string[];
};
}
// For sync optional flows (currently only Relay)
| {
relay: {};
};
};

// ref: [FxAccounts.sys.mjs](https://searchfox.org/mozilla-central/rev/82828dba9e290914eddd294a0871533875b3a0b5/services/fxaccounts/FxAccounts.sys.mjs#910)
Expand All @@ -114,13 +119,11 @@ export type FxAOAuthLogin = {
code: string;
redirect: string;
state: string;
// For sync oauth signup
// OAuth desktop looks at the syc engine list in fxaLogin.
// OAuth mobile currently looks at fxaOAuthLogin, but should
// eventually move to look at fxaLogin as well to prevent FXA-10596.
declinedSyncEngines?: string[];
offeredSyncEngines?: string[];
// For sync optional flows (currently only Relay)
services?: {
relay: {};
};
};

// ref: https://searchfox.org/mozilla-central/rev/82828dba9e290914eddd294a0871533875b3a0b5/services/fxaccounts/FxAccountsWebChannel.sys.mjs#230
Expand Down
5 changes: 2 additions & 3 deletions packages/fxa-settings/src/pages/Signin/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -572,15 +572,14 @@ describe('Signin', () => {
});
enterPasswordAndSubmit();
await waitFor(() => {
// Ensure it's not called with keyFetchToken or unwrapBKey
// Ensure it's not called with keyFetchToken, unwrapBKey, or { relay: {} }
expect(fxaLoginSpy).toHaveBeenCalledWith({
email: MOCK_EMAIL,
sessionToken: MOCK_SESSION_TOKEN,
uid: MOCK_UID,
verified: true,
services: { sync: {} },
});
// Ensure it's not called with services: { relay: {} }
expect(fxaOAuthLoginSpy).toHaveBeenCalledWith({
action: 'signin',
...MOCK_OAUTH_FLOW_HANDLER_RESPONSE,
Expand Down Expand Up @@ -622,11 +621,11 @@ describe('Signin', () => {
sessionToken: MOCK_SESSION_TOKEN,
uid: MOCK_UID,
verified: true,
services: { relay: {} },
});
expect(fxaOAuthLoginSpy).toHaveBeenCalledWith({
action: 'signin',
...MOCK_OAUTH_FLOW_HANDLER_RESPONSE,
services: { relay: {} },
});

const fxaLoginCallOrder =
Expand Down
15 changes: 3 additions & 12 deletions packages/fxa-settings/src/pages/Signin/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,6 @@ export async function handleNavigation(
code: oauthData.code,
redirect: oauthData.redirect,
state: oauthData.state,
// OAuth desktop sync optional flow sends service in fxaOAuthLogin
...(integration.isDesktopRelay() && {
services: {
relay: {},
},
}),
});
}
performNavigation({ to, locationState, shouldHardNavigate });
Expand Down Expand Up @@ -187,12 +181,9 @@ function sendFxaLogin(navigationOptions: NavigationOptions) {
keyFetchToken: navigationOptions.signinData.keyFetchToken!,
unwrapBKey: navigationOptions.unwrapBKey!,
}),
// OAuth desktop sync optional flow sends service in fxaOAuthLogin
...(!navigationOptions.integration.isDesktopRelay() && {
services: {
sync: {},
},
}),
services: navigationOptions.integration.isDesktopRelay()
? { relay: {} }
: { sync: {} },
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -298,9 +298,6 @@ describe('ConfirmSignupCode page', () => {
expect(fxaOAuthLoginSpy).toHaveBeenCalledWith({
action: 'signup',
...MOCK_OAUTH_FLOW_HANDLER_RESPONSE,
services: {
relay: {},
},
});
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,9 @@ const ConfirmSignupCode = ({

if (integration.isSync()) {
firefox.fxaOAuthLogin({
// OAuth desktop looks at the syc engine list in fxaLogin. Oauth
// mobile currently looks at the engines provided here, but should
// eventually move to look at fxaLogin as well to prevent FXA-10596.
declinedSyncEngines,
offeredSyncEngines,
action: 'signup',
Expand All @@ -229,9 +232,6 @@ const ConfirmSignupCode = ({
code,
redirect,
state,
services: {
relay: {},
},
});
goToSettingsWithAlertSuccess();
} else {
Expand Down
1 change: 1 addition & 0 deletions packages/fxa-settings/src/pages/Signup/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -792,6 +792,7 @@ describe('Signup page', () => {
// Does not send services: { sync: {...} }
expect(fxaLoginSpy).toBeCalledWith({
...oauthCommonFxaLoginOptions,
services: { relay: {} },
});
});

Expand Down
4 changes: 3 additions & 1 deletion packages/fxa-settings/src/pages/Signup/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,9 @@ export const Signup = ({
sessionToken: data.signUp.sessionToken,
uid: data.signUp.uid,
verified: false,
// OAuth desktop sync optional flow sends service in fxaOAuthLogin
services: {
relay: {},
},
});
} else {
GleanMetrics.registration.marketing({
Expand Down

0 comments on commit ad18787

Please sign in to comment.