@@ -149,6 +149,86 @@ async function getActiveUserBlocking() {
149
149
}
150
150
}
151
151
152
+ class RefreshIdpTokenResult {
153
+ idpConfigId ;
154
+ idToken ;
155
+ }
156
+
157
+ class TokenRefreshHandlerImpl {
158
+ /**
159
+ * Opens a popup to get a 3P ID token and Config ID from the user.
160
+ * @returns {Promise<RefreshIdpTokenResult> } A promise that returns IdpConfigId and 3p IDP Id token.
161
+ */
162
+ refreshIdpToken ( ) {
163
+ return this . promptForTokenAndConfigId ( ) ;
164
+ }
165
+
166
+ promptForTokenAndConfigId ( ) {
167
+ return new Promise ( ( resolve , reject ) => {
168
+ let isSubmitted = false ;
169
+ const modalId = 'third-party-token-modal' ;
170
+
171
+ const modalHtml = `
172
+ <div class="modal fade" id="${ modalId } " tabindex="-1" role="dialog" aria-labelledby="tokenModalLabel">
173
+ <div class="modal-dialog" role="document">
174
+ <div class="modal-content">
175
+ <div class="modal-header">
176
+ <button type="button" class="close" data-dismiss="modal" aria-label="Close">
177
+ <span aria-hidden="true">×</span>
178
+ </button>
179
+ <h4 class="modal-title" id="tokenModalLabel">Enter 3P Token Details</h4>
180
+ </div>
181
+ <div class="modal-body">
182
+ <p>Please enter the third-party token details:</p>
183
+ <div class="form-group">
184
+ <label for="idp-config-id-input-field">IDP Config ID</label>
185
+ <input type="text" class="form-control" id="idp-config-id-input-field" placeholder="eg: idp.example.com">
186
+ </div>
187
+ <div class="form-group">
188
+ <label for="id-token-input-field">ID Token</label>
189
+ <input type="text" class="form-control" id="id-token-input-field" placeholder="Paste ID Token here">
190
+ </div>
191
+ </div>
192
+ <div class="modal-footer">
193
+ <button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
194
+ <button type="button" class="btn btn-primary" id="token-submit-btn">Submit</button>
195
+ </div>
196
+ </div>
197
+ </div>
198
+ </div>
199
+ ` ;
200
+
201
+ $ ( 'body' ) . append ( modalHtml ) ;
202
+ const $modal = $ ( `#${ modalId } ` ) ;
203
+
204
+ $modal . find ( '#token-submit-btn' ) . on ( 'click' , ( ) => {
205
+ isSubmitted = true ;
206
+
207
+ const configId = $modal . find ( '#idp-config-id-input-field' ) . val ( ) ;
208
+ const token = $modal . find ( '#id-token-input-field' ) . val ( ) ;
209
+
210
+ $modal . modal ( 'hide' ) ; // Hide the modal
211
+
212
+ const result = new RefreshIdpTokenResult ( ) ;
213
+ result . idpConfigId = configId ;
214
+ result . idToken = token ;
215
+
216
+ resolve ( result ) ;
217
+ } ) ;
218
+
219
+ $modal . on ( 'hidden.bs.modal' , ( ) => {
220
+ $modal . remove ( ) ;
221
+
222
+ if ( ! isSubmitted ) {
223
+ reject ( new Error ( 'User cancelled token input.' ) ) ;
224
+ }
225
+ } ) ;
226
+
227
+ $modal . modal ( 'show' ) ;
228
+ } ) ;
229
+ }
230
+ }
231
+
152
232
/**
153
233
* Refreshes the current user data in the UI, displaying a user info box if
154
234
* a user is signed in, or removing it.
@@ -1509,23 +1589,20 @@ function onFinalizeSignInWithTotpMultiFactor(event) {
1509
1589
} , onAuthError ) ;
1510
1590
}
1511
1591
1512
- async function exchangeCIAMToken ( token ) {
1513
- const firebaseToken = await exchangeToken (
1514
- regionalAuth ,
1515
- ( idpConfigId = 'Bar-e2e-idpconfig-002' ) ,
1516
- token
1517
- ) ;
1592
+ async function exchangeCIAMToken ( idpConfigId , token ) {
1593
+ const firebaseToken = await exchangeToken ( regionalAuth , idpConfigId , token ) ;
1518
1594
return firebaseToken ;
1519
1595
}
1520
1596
1521
1597
function onExchangeToken ( event ) {
1522
1598
event . preventDefault ( ) ;
1523
1599
const byoCiamInput = document . getElementById ( 'byo-ciam-token' ) ;
1600
+ const idpConfigId = document . getElementById ( 'idp-config-id' ) ;
1524
1601
const firebaseTokenStatus = document . getElementById ( 'firebase-token-status' ) ;
1525
1602
1526
1603
firebaseTokenStatus . textContent = 'Exchanging token...' ;
1527
1604
1528
- exchangeCIAMToken ( byoCiamInput . value )
1605
+ exchangeCIAMToken ( idpConfigId . value , byoCiamInput . value )
1529
1606
. then ( response => {
1530
1607
firebaseTokenStatus . textContent = '✅ Firebase token is set: ' + response ;
1531
1608
console . log ( 'Token:' , response ) ;
@@ -2092,6 +2169,8 @@ function initApp() {
2092
2169
popupRedirectResolver : browserPopupRedirectResolver ,
2093
2170
tenantConfig : tenantConfig
2094
2171
} ) ;
2172
+ const tokenRefreshHandler = new TokenRefreshHandlerImpl ( ) ;
2173
+ regionalAuth . setTokenRefreshHandler ( tokenRefreshHandler ) ;
2095
2174
2096
2175
const firebaseTokenStatus = document . getElementById ( 'firebase-token-status' ) ;
2097
2176
setTimeout ( async ( ) => {
0 commit comments