@@ -12,13 +12,15 @@ import { useConfig } from '../../models';
1212import { ReactElement } from 'react-markdown/lib/react-markdown' ;
1313import { useMetrics } from '../../lib/metrics' ;
1414import GleanMetrics from '../../lib/glean' ;
15+ import { QueryParams } from '../..' ;
1516
1617export type ThirdPartyAuthProps = {
1718 onContinueWithGoogle ?: FormEventHandler < HTMLFormElement > ;
1819 onContinueWithApple ?: FormEventHandler < HTMLFormElement > ;
1920 showSeparator ?: boolean ;
2021 viewName ?: string ;
2122 deeplink ?: string ;
23+ flowQueryParams ?: QueryParams ;
2224} ;
2325
2426/**
@@ -31,7 +33,8 @@ const ThirdPartyAuth = ({
3133 onContinueWithApple,
3234 showSeparator = true ,
3335 viewName = 'unknown' ,
34- deeplink,
36+ deeplink,
37+ flowQueryParams
3538} : ThirdPartyAuthProps ) => {
3639 const config = useConfig ( ) ;
3740
@@ -63,7 +66,7 @@ const ThirdPartyAuth = ({
6366 { ...{
6467 party : 'google' ,
6568 ...config . googleAuthConfig ,
66- state : getState ( ) ,
69+ state : getState ( flowQueryParams ) ,
6770 scope : 'openid email profile' ,
6871 responseType : 'code' ,
6972 accessType : 'offline' ,
@@ -85,7 +88,7 @@ const ThirdPartyAuth = ({
8588 { ...{
8689 party : 'apple' ,
8790 ...config . appleAuthConfig ,
88- state : getState ( ) ,
91+ state : getState ( flowQueryParams ) ,
8992 scope : 'email' ,
9093 responseType : 'code id_token' ,
9194 accessType : 'offline' ,
@@ -129,7 +132,8 @@ const ThirdPartySignInForm = ({
129132 buttonText,
130133 onSubmit,
131134 viewName,
132- deeplink
135+ deeplink,
136+ flowQueryParams
133137} : {
134138 party : 'google' | 'apple' ;
135139 authorizationEndpoint : string ;
@@ -145,6 +149,7 @@ const ThirdPartySignInForm = ({
145149 onSubmit ?: FormEventHandler < HTMLFormElement > ;
146150 viewName ?: string ;
147151 deeplink ?: string ;
152+ flowQueryParams ?: QueryParams ;
148153} ) => {
149154 const { logViewEventOnce } = useMetrics ( ) ;
150155 const stateRef = useRef < HTMLInputElement > ( null ) ;
@@ -153,7 +158,6 @@ const ThirdPartySignInForm = ({
153158
154159 const onClick = useCallback ( async ( ) => {
155160 logViewEventOnce ( `flow.${ party } ` , 'oauth-start' ) ;
156-
157161 switch ( `${ party } -${ viewName } ` ) {
158162 case 'google-index' :
159163 GleanMetrics . emailFirst . googleOauthStart ( ) ;
@@ -185,9 +189,9 @@ const ThirdPartySignInForm = ({
185189 await GleanMetrics . isDone ( ) ;
186190
187191 if ( stateRef . current ) {
188- stateRef . current . value = getState ( ) ;
192+ stateRef . current . value = getState ( flowQueryParams ) ;
189193 }
190- } , [ party , stateRef , viewName , logViewEventOnce ] ) ;
194+ } , [ party , stateRef , viewName , logViewEventOnce , flowQueryParams ] ) ;
191195
192196
193197 if ( onSubmit === undefined ) {
@@ -242,23 +246,33 @@ function deleteParams(searchParams: URLSearchParams, paramsToDelete: string[]) {
242246 return searchParams ;
243247}
244248
245- function getState ( ) {
249+ function getState ( flowQueryParams : QueryParams | undefined ) {
246250 // We stash the originating location in the state oauth param
247251 // because we will need it to use it to reconstruct the redirect URL for RP
248252 const params = new URLSearchParams ( window . location . search ) ;
249- // we won't need these params that are used for internal backbone/react navigation
250- const modifiedParams = deleteParams ( params , [
253+
254+ // Combine flowQueryParams and paramsObject, ensuring all values are strings
255+ const paramsObject = Object . fromEntries ( params . entries ( ) ) ;
256+ const combinedParams = {
257+ ...paramsObject ,
258+ ...Object . fromEntries (
259+ Object . entries ( flowQueryParams || { } ) . map ( ( [ key , value ] ) => [ key , String ( value ) ] )
260+ ) ,
261+ } ;
262+
263+ // Remove unwanted keys
264+ const filteredParams = deleteParams ( new URLSearchParams ( combinedParams ) , [
251265 'deeplink' ,
252266 'email' ,
253267 'emailStatusChecked' ,
254268 'forceExperiment' ,
255269 'forceExperimentGroup' ,
256270 'showReactApp' ,
257271 ] ) ;
272+ // we won't need these params that are used for internal backbone/react navigation
258273 return encodeURIComponent (
259- `${ window . location . origin } ${
260- window . location . pathname
261- } ?${ modifiedParams . toString ( ) } `
274+ `${ window . location . origin } ${ window . location . pathname
275+ } ?${ filteredParams . toString ( ) } `
262276 ) ;
263277}
264278
0 commit comments