From cc4957dcee496180326c594006074e9b2fd1767d Mon Sep 17 00:00:00 2001 From: mansisampat Date: Fri, 3 Oct 2025 11:25:03 +0530 Subject: [PATCH 1/5] Refresh Firebase Token Demo App changes. --- packages/auth/demo/src/index.js | 108 ++++++++++++++++++++++++++++++++ 1 file changed, 108 insertions(+) diff --git a/packages/auth/demo/src/index.js b/packages/auth/demo/src/index.js index 7afcd3e70d4..15f77241446 100644 --- a/packages/auth/demo/src/index.js +++ b/packages/auth/demo/src/index.js @@ -149,6 +149,112 @@ async function getActiveUserBlocking() { } } +class RefreshIdpTokenResult { + idpConfigId; + idToken; +} + +class TokenRefreshHandlerImpl { + /** + * Opens a popup to get a 3P ID token and Config ID from the user. + * @returns {Promise} A promise that resolves with the result object. + */ + refreshIdpToken() { + log('inside here'); + console.log('inside handler - opening popup for 3p token'); + + // This function handles the popup logic and returns the required object + return this.promptForTokenAndConfigId(); + } + + /** + * Opens a Bootstrap modal to ask the user for an ID token and IDP Config ID. + * + * This function dynamically creates a modal, shows it, and waits for + * user input. It returns a Promise that resolves or rejects based + * on the user's action. + * + * @returns {Promise} A promise that resolves with the + * RefreshIdpTokenResult object, or rejects if the user cancels. + */ + promptForTokenAndConfigId() { + // We return a Promise that will be resolved/rejected by the modal's buttons + return new Promise((resolve, reject) => { + // A flag to track if the promise has been settled + let isSubmitted = false; + const modalId = 'third-party-token-modal'; + + // 1. Define Modal HTML with two input fields + const modalHtml = ` + + `; + + // 2. Append modal to body and get a jQuery reference + $('body').append(modalHtml); + const $modal = $(`#${modalId}`); + + // 3. Setup Event Handlers + + // Handle Submit button click + $modal.find('#token-submit-btn').on('click', () => { + isSubmitted = true; + + // Read values from *both* input fields + const configId = $modal.find('#idp-config-id-input-field').val(); + const token = $modal.find('#id-token-input-field').val(); + + $modal.modal('hide'); // Hide the modal + + // Create the result object as requested + const result = new RefreshIdpTokenResult(); + result.idpConfigId = configId; + result.idToken = token; + + resolve(result); // Resolve the promise with the object + }); + + // Handle modal being closed (by 'x', 'Cancel' button, backdrop click, or ESC) + $modal.on('hidden.bs.modal', () => { + $modal.remove(); // Clean up the modal from the DOM + + // If the modal was hidden *without* submitting, reject the promise + if (!isSubmitted) { + reject(new Error('User cancelled token input.')); + } + }); + + // 4. Show the modal + $modal.modal('show'); + }); + } +} + /** * Refreshes the current user data in the UI, displaying a user info box if * a user is signed in, or removing it. @@ -2092,6 +2198,8 @@ function initApp() { popupRedirectResolver: browserPopupRedirectResolver, tenantConfig: tenantConfig }); + const tokenRefreshHandler = new TokenRefreshHandlerImpl(); + regionalAuth.setTokenRefreshHandler(tokenRefreshHandler); const firebaseTokenStatus = document.getElementById('firebase-token-status'); setTimeout(async () => { From 54bfb9b595c198147c7b1eb683ea8c5b89cbaccc Mon Sep 17 00:00:00 2001 From: mansisampat Date: Fri, 3 Oct 2025 12:41:32 +0530 Subject: [PATCH 2/5] take IdpConfig id as input --- packages/auth/demo/public/index.html | 1 + packages/auth/demo/src/index.js | 7 ++++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/auth/demo/public/index.html b/packages/auth/demo/public/index.html index f69918d43d0..fde656a9d48 100644 --- a/packages/auth/demo/public/index.html +++ b/packages/auth/demo/public/index.html @@ -854,6 +854,7 @@

Sign in with your CIAM token

No CIAM token found. User not logged in.
+