@@ -157,34 +157,20 @@ class RefreshIdpTokenResult {
157157class TokenRefreshHandlerImpl {
158158 /**
159159 * Opens a popup to get a 3P ID token and Config ID from the user.
160- * @returns {Promise<RefreshIdpTokenResult> } A promise that resolves with the result object .
160+ * @returns {Promise<RefreshIdpTokenResult> } A promise that returns IdpConfigId and 3p IDP Id token .
161161 */
162162 refreshIdpToken ( ) {
163163 log ( 'inside here' ) ;
164164 console . log ( 'inside handler - opening popup for 3p token' ) ;
165165
166- // This function handles the popup logic and returns the required object
167166 return this . promptForTokenAndConfigId ( ) ;
168167 }
169168
170- /**
171- * Opens a Bootstrap modal to ask the user for an ID token and IDP Config ID.
172- *
173- * This function dynamically creates a modal, shows it, and waits for
174- * user input. It returns a Promise that resolves or rejects based
175- * on the user's action.
176- *
177- * @returns {Promise<RefreshIdpTokenResult> } A promise that resolves with the
178- * RefreshIdpTokenResult object, or rejects if the user cancels.
179- */
180169 promptForTokenAndConfigId ( ) {
181- // We return a Promise that will be resolved/rejected by the modal's buttons
182170 return new Promise ( ( resolve , reject ) => {
183- // A flag to track if the promise has been settled
184171 let isSubmitted = false ;
185172 const modalId = 'third-party-token-modal' ;
186173
187- // 1. Define Modal HTML with two input fields
188174 const modalHtml = `
189175 <div class="modal fade" id="${ modalId } " tabindex="-1" role="dialog" aria-labelledby="tokenModalLabel">
190176 <div class="modal-dialog" role="document">
@@ -215,41 +201,32 @@ class TokenRefreshHandlerImpl {
215201 </div>
216202 ` ;
217203
218- // 2. Append modal to body and get a jQuery reference
219204 $ ( 'body' ) . append ( modalHtml ) ;
220205 const $modal = $ ( `#${ modalId } ` ) ;
221206
222- // 3. Setup Event Handlers
223-
224- // Handle Submit button click
225207 $modal . find ( '#token-submit-btn' ) . on ( 'click' , ( ) => {
226208 isSubmitted = true ;
227209
228- // Read values from *both* input fields
229210 const configId = $modal . find ( '#idp-config-id-input-field' ) . val ( ) ;
230211 const token = $modal . find ( '#id-token-input-field' ) . val ( ) ;
231212
232213 $modal . modal ( 'hide' ) ; // Hide the modal
233214
234- // Create the result object as requested
235215 const result = new RefreshIdpTokenResult ( ) ;
236216 result . idpConfigId = configId ;
237217 result . idToken = token ;
238218
239- resolve ( result ) ; // Resolve the promise with the object
219+ resolve ( result ) ;
240220 } ) ;
241221
242- // Handle modal being closed (by 'x', 'Cancel' button, backdrop click, or ESC)
243222 $modal . on ( 'hidden.bs.modal' , ( ) => {
244- $modal . remove ( ) ; // Clean up the modal from the DOM
223+ $modal . remove ( ) ;
245224
246- // If the modal was hidden *without* submitting, reject the promise
247225 if ( ! isSubmitted ) {
248226 reject ( new Error ( 'User cancelled token input.' ) ) ;
249227 }
250228 } ) ;
251229
252- // 4. Show the modal
253230 $modal . modal ( 'show' ) ;
254231 } ) ;
255232 }
0 commit comments