@@ -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,32 @@ function onFinalizeSignInWithTotpMultiFactor(event) {
15061508 } , onAuthError ) ;
15071509}
15081510
1511+ async function exchangeCIAMToken ( token ) {
1512+ const firebaseToken = await exchangeToken (
1513+ regaionalAuth ,
1514+ ( idpConfigId = 'Bar-e2e-idpconfig-002' ) ,
1515+ token
1516+ ) ;
1517+ return firebaseToken ;
1518+ }
1519+
1520+ function onExchangeToken ( event ) {
1521+ event . preventDefault ( ) ;
1522+ const byoCiamInput = document . getElementById ( 'byo-ciam-token' ) ;
1523+ const byoCiamResult = document . getElementById ( 'byo-ciam-result' ) ;
1524+
1525+ byoCiamResult . textContent = 'Exchanging token...' ;
1526+
1527+ exchangeCIAMToken ( byoCiamInput . value )
1528+ . then ( response => {
1529+ byoCiamResult . textContent = response . accessToken ;
1530+ console . log ( 'Token:' , response ) ;
1531+ } )
1532+ . catch ( error => {
1533+ console . error ( 'Error exchanging token:' , error ) ;
1534+ } ) ;
1535+ }
1536+
15091537/**
15101538 * Adds a new row to insert an OAuth custom parameter key/value pair.
15111539 * @param {!jQuery.Event } _event The jQuery event object.
@@ -2051,6 +2079,18 @@ function initApp() {
20512079 connectAuthEmulator ( auth , AUTH_EMULATOR_URL ) ;
20522080 }
20532081
2082+ let tenantConfig = {
2083+ 'location' : 'global' ,
2084+ 'tenantId' : 'Foo-e2e-tenant-001'
2085+ } ;
2086+ const regionalApp = initializeApp ( config , `${ auth . name } -rgcip` ) ;
2087+
2088+ regionalAuth = initializeAuth ( regionalApp , {
2089+ persistence : inMemoryPersistence ,
2090+ popupRedirectResolver : browserPopupRedirectResolver ,
2091+ tenantConfig : tenantConfig
2092+ } ) ;
2093+
20542094 tempApp = initializeApp (
20552095 {
20562096 apiKey : config . apiKey ,
@@ -2391,6 +2431,9 @@ function initApp() {
23912431 $ ( '#enroll-mfa-totp-finalize' ) . click ( onFinalizeEnrollWithTotpMultiFactor ) ;
23922432 // Sets tenant for the current auth instance
23932433 $ ( '#set-tenant-btn' ) . click ( onSetTenantIdClick ) ;
2434+
2435+ // Performs Exchange Token
2436+ $ ( '#exchange-token' ) . click ( onExchangeToken ) ;
23942437}
23952438
23962439$ ( initApp ) ;
0 commit comments