@@ -74,7 +74,8 @@ import {
7474 connectAuthEmulator ,
7575 initializeRecaptchaConfig ,
7676 validatePassword ,
77- revokeAccessToken
77+ revokeAccessToken ,
78+ exchangeToken
7879} from '@firebase/auth' ;
7980
8081import { config } from './config' ;
@@ -95,6 +96,7 @@ const AUTH_EMULATOR_URL = 'http://localhost:9099';
9596
9697let app = null ;
9798let auth = null ;
99+ let regionalAuth = null ;
98100let currentTab = null ;
99101let lastUser = null ;
100102let applicationVerifier = null ;
@@ -1506,6 +1508,24 @@ function onFinalizeSignInWithTotpMultiFactor(event) {
15061508 } , onAuthError ) ;
15071509}
15081510
1511+ function onExchangeToken ( event ) {
1512+ event . preventDefault ( ) ;
1513+ const byoCiamInput = document . getElementById ( "byo-ciam-token" ) ;
1514+ const byoCiamSubmit = document . getElementById ( "byo-ciam-submit" ) ;
1515+ const byoCiamResult = document . getElementById ( "byo-ciam-result" ) ;
1516+
1517+ byoCiamResult . textContent = "Exchanging token..." ;
1518+
1519+ exchangeCIAMToken ( byoCiamInput . value )
1520+ . then ( ( response ) => {
1521+ byoCiamResult . textContent = response . accessToken ;
1522+ console . log ( "Token:" , response ) ;
1523+ } )
1524+ . catch ( ( error ) => {
1525+ console . error ( "Error exchanging token:" , error ) ;
1526+ } ) ;
1527+ }
1528+
15091529/**
15101530 * Adds a new row to insert an OAuth custom parameter key/value pair.
15111531 * @param {!jQuery.Event } _event The jQuery event object.
@@ -1795,6 +1815,14 @@ function revokeAppleTokenAndDeleteUser() {
17951815 } ) ;
17961816}
17971817
1818+ async function exchangeCIAMToken ( token ) {
1819+ const firebaseToken = await exchangeToken (
1820+ regaionalAuth ,
1821+ idpConfigId = "Bar-e2e-idpconfig-002" ,
1822+ token )
1823+ return firebaseToken ;
1824+ }
1825+
17981826/**
17991827 * Gets a specific query parameter from the current URL.
18001828 * @param {string } name Name of the parameter.
@@ -2047,6 +2075,20 @@ function initApp() {
20472075 log ( 'Initializing app...' ) ;
20482076 app = initializeApp ( config ) ;
20492077 auth = getAuth ( app ) ;
2078+ let tenantConfig = {
2079+ "location" : "global" ,
2080+ "tenantId" : "Foo-e2e-tenant-001"
2081+ } ;
2082+ const regionalApp = initializeApp (
2083+ config ,
2084+ `${ auth . name } -rgcip`
2085+ ) ;
2086+
2087+ regaionalAuth = initializeAuth ( regionalApp , {
2088+ persistence : inMemoryPersistence ,
2089+ popupRedirectResolver : browserPopupRedirectResolver ,
2090+ tenantConfig : tenantConfig
2091+ } ) ;
20502092 if ( USE_AUTH_EMULATOR ) {
20512093 connectAuthEmulator ( auth , AUTH_EMULATOR_URL ) ;
20522094 }
@@ -2379,6 +2421,10 @@ function initApp() {
23792421 onFinalizeSignInWithTotpMultiFactor
23802422 ) ;
23812423
2424+ $ ( '#exchange-token' ) . click (
2425+ onExchangeToken
2426+ ) ;
2427+
23822428 // Starts multi-factor enrollment with phone number.
23832429 $ ( '#enroll-mfa-verify-phone-number' ) . click ( onStartEnrollWithPhoneMultiFactor ) ;
23842430 // Completes multi-factor enrollment with supplied SMS code.
0 commit comments