1515 * limitations under the License.
1616 */
1717
18- import { SDK_VERSION } from '@firebase/app-exp' ;
1918import * as externs from '@firebase/auth-types-exp' ;
20- import { isEmpty , querystring } from '@firebase/util' ;
2119
2220import { AuthEventManager } from '../core/auth/auth_event_manager' ;
2321import { AuthErrorCode } from '../core/errors' ;
24- import { OAuthProvider } from '../core/providers/oauth' ;
2522import { _assert , debugAssert , _fail } from '../core/util/assert' ;
26- import { _emulatorUrl } from '../core/util/emulator' ;
2723import { _generateEventId } from '../core/util/event_id' ;
2824import { _getCurrentUrl } from '../core/util/location' ;
2925import { _validateOrigin } from '../core/util/validate_origin' ;
30- import { ApiKey , AppName , Auth } from '../model/auth' ;
26+ import { Auth } from '../model/auth' ;
3127import {
3228 AuthEventType ,
3329 EventManager ,
@@ -40,18 +36,7 @@ import { _openIframe } from './iframe/iframe';
4036import { browserSessionPersistence } from './persistence/session_storage' ;
4137import { _open , AuthPopup } from './util/popup' ;
4238import { _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' ;
5540
5641/**
5742 * The special web storage event
@@ -89,7 +74,13 @@ class BrowserPopupRedirectResolver implements PopupRedirectResolver {
8974 ) ;
9075
9176 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+ ) ;
9384 return _open ( auth , url , _generateEventId ( ) ) ;
9485 }
9586
@@ -100,7 +91,9 @@ class BrowserPopupRedirectResolver implements PopupRedirectResolver {
10091 eventId ?: string
10192 ) : Promise < never > {
10293 await this . originValidation ( auth ) ;
103- _setWindowLocation ( getRedirectUrl ( auth , provider , authType , eventId ) ) ;
94+ _setWindowLocation (
95+ _getRedirectUrl ( auth , provider , authType , _getCurrentUrl ( ) , eventId )
96+ ) ;
10497 return new Promise ( ( ) => { } ) ;
10598 }
10699
@@ -180,84 +173,3 @@ class BrowserPopupRedirectResolver implements PopupRedirectResolver {
180173 * @public
181174 */
182175export 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