15
15
* limitations under the License.
16
16
*/
17
17
18
- import { SDK_VERSION } from '@firebase/app-exp' ;
19
18
import * as externs from '@firebase/auth-types-exp' ;
20
- import { isEmpty , querystring } from '@firebase/util' ;
21
19
22
20
import { AuthEventManager } from '../core/auth/auth_event_manager' ;
23
21
import { AuthErrorCode } from '../core/errors' ;
24
- import { OAuthProvider } from '../core/providers/oauth' ;
25
22
import { _assert , debugAssert , _fail } from '../core/util/assert' ;
26
- import { _emulatorUrl } from '../core/util/emulator' ;
27
23
import { _generateEventId } from '../core/util/event_id' ;
28
24
import { _getCurrentUrl } from '../core/util/location' ;
29
25
import { _validateOrigin } from '../core/util/validate_origin' ;
30
- import { ApiKey , AppName , Auth } from '../model/auth' ;
26
+ import { Auth } from '../model/auth' ;
31
27
import {
32
28
AuthEventType ,
33
29
EventManager ,
@@ -40,18 +36,7 @@ import { _openIframe } from './iframe/iframe';
40
36
import { browserSessionPersistence } from './persistence/session_storage' ;
41
37
import { _open , AuthPopup } from './util/popup' ;
42
38
import { _getRedirectResult } from './strategies/redirect' ;
43
-
44
- /**
45
- * URL for Authentication widget which will initiate the OAuth handshake
46
- *
47
- */
48
- const WIDGET_PATH = '__/auth/handler' ;
49
-
50
- /**
51
- * URL for emulated environment
52
- *
53
- */
54
- const EMULATOR_WIDGET_PATH = 'emulator/auth/handler' ;
39
+ import { _getRedirectUrl } from '../core/util/handler' ;
55
40
56
41
/**
57
42
* The special web storage event
@@ -89,7 +74,13 @@ class BrowserPopupRedirectResolver implements PopupRedirectResolver {
89
74
) ;
90
75
91
76
await this . originValidation ( auth ) ;
92
- const url = getRedirectUrl ( auth , provider , authType , eventId ) ;
77
+ const url = _getRedirectUrl (
78
+ auth ,
79
+ provider ,
80
+ authType ,
81
+ _getCurrentUrl ( ) ,
82
+ eventId
83
+ ) ;
93
84
return _open ( auth , url , _generateEventId ( ) ) ;
94
85
}
95
86
@@ -100,7 +91,9 @@ class BrowserPopupRedirectResolver implements PopupRedirectResolver {
100
91
eventId ?: string
101
92
) : Promise < never > {
102
93
await this . originValidation ( auth ) ;
103
- _setWindowLocation ( getRedirectUrl ( auth , provider , authType , eventId ) ) ;
94
+ _setWindowLocation (
95
+ _getRedirectUrl ( auth , provider , authType , _getCurrentUrl ( ) , eventId )
96
+ ) ;
104
97
return new Promise ( ( ) => { } ) ;
105
98
}
106
99
@@ -180,84 +173,3 @@ class BrowserPopupRedirectResolver implements PopupRedirectResolver {
180
173
* @public
181
174
*/
182
175
export const browserPopupRedirectResolver : externs . PopupRedirectResolver = BrowserPopupRedirectResolver ;
183
-
184
- // eslint-disable-next-line @typescript-eslint/consistent-type-definitions
185
- type WidgetParams = {
186
- apiKey : ApiKey ;
187
- appName : AppName ;
188
- authType : AuthEventType ;
189
- redirectUrl : string ;
190
- v : string ;
191
- providerId ?: string ;
192
- scopes ?: string ;
193
- customParameters ?: string ;
194
- eventId ?: string ;
195
- tid ?: string ;
196
- } ;
197
-
198
- function getRedirectUrl (
199
- auth : Auth ,
200
- provider : externs . AuthProvider ,
201
- authType : AuthEventType ,
202
- eventId ?: string
203
- ) : string {
204
- _assert ( auth . config . authDomain , auth , AuthErrorCode . MISSING_AUTH_DOMAIN ) ;
205
- _assert ( auth . config . apiKey , auth , AuthErrorCode . INVALID_API_KEY ) ;
206
-
207
- const params : WidgetParams = {
208
- apiKey : auth . config . apiKey ,
209
- appName : auth . name ,
210
- authType,
211
- redirectUrl : _getCurrentUrl ( ) ,
212
- v : SDK_VERSION ,
213
- eventId
214
- } ;
215
-
216
- if ( provider instanceof OAuthProvider ) {
217
- provider . setDefaultLanguage ( auth . languageCode ) ;
218
- params . providerId = provider . providerId || '' ;
219
- if ( ! isEmpty ( provider . getCustomParameters ( ) ) ) {
220
- params . customParameters = JSON . stringify ( provider . getCustomParameters ( ) ) ;
221
- }
222
- const scopes = provider . getScopes ( ) . filter ( scope => scope !== '' ) ;
223
- if ( scopes . length > 0 ) {
224
- params . scopes = scopes . join ( ',' ) ;
225
- }
226
- // TODO set additionalParams?
227
- // let additionalParams = provider.getAdditionalParams();
228
- // for (let key in additionalParams) {
229
- // if (!params.hasOwnProperty(key)) {
230
- // params[key] = additionalParams[key]
231
- // }
232
- // }
233
- }
234
-
235
- if ( auth . tenantId ) {
236
- params . tid = auth . tenantId ;
237
- }
238
-
239
- for ( const key of Object . keys ( params ) ) {
240
- if ( ( params as Record < string , unknown > ) [ key ] === undefined ) {
241
- delete ( params as Record < string , unknown > ) [ key ] ;
242
- }
243
- }
244
-
245
- // TODO: maybe set eid as endipointId
246
- // TODO: maybe set fw as Frameworks.join(",")
247
-
248
- const url = new URL (
249
- `${ getHandlerBase ( auth ) } ?${ querystring (
250
- params as Record < string , string | number >
251
- ) . slice ( 1 ) } `
252
- ) ;
253
-
254
- return url . toString ( ) ;
255
- }
256
-
257
- function getHandlerBase ( { config } : Auth ) : string {
258
- if ( ! config . emulator ) {
259
- return `https://${ config . authDomain } /${ WIDGET_PATH } ` ;
260
- }
261
-
262
- return _emulatorUrl ( config , EMULATOR_WIDGET_PATH ) ;
263
- }
0 commit comments