Skip to content

Commit c159979

Browse files
CopilotVeena11
andcommitted
Fix: Don't dismiss ASWebAuthenticationSession after successful completion
- Removed dismissExternalSession call after successful callback - ASWebAuthenticationSession completion handler already cleans up the session - After successful callback (msauth://profileInstalled), just set externalSessionHandler = nil - Prevents attempting to cancel an already-completed session - dismissExternalSession should only be called for error/cancellation scenarios - Updated documentation to clarify when to use dismiss vs nil assignment - Updated log messages to indicate dismissal is for active session cancellation - cleanup method still dismisses if session is somehow still active (safety net) Co-authored-by: Veena11 <9446116+Veena11@users.noreply.github.com>
1 parent 1c0c626 commit c159979

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

IdentityCore/src/controllers/MSIDLocalInteractiveController.m

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -341,8 +341,10 @@ - (void)handleProfileInstallationCompletion:(NSURL *)callbackURL
341341
MSID_LOG_WITH_CTX(MSIDLogLevelInfo, self.requestParameters,
342342
@"Profile installation completed successfully (msauth://profileInstalled)");
343343

344-
// Dismiss the ASWebAuthenticationSession
345-
[self.transitionCoordinator dismissExternalSession];
344+
// ASWebAuthenticationSession has already completed successfully
345+
// Its completion handler has fired, and the session has cleaned itself up
346+
// We should NOT call dismiss (which would try to cancel it) - just release our reference
347+
self.transitionCoordinator.externalSessionHandler = nil;
346348

347349
// Resume the suspended embedded webview
348350
[self.transitionCoordinator resumeSuspendedEmbeddedWebview];
@@ -356,7 +358,7 @@ - (void)handleProfileInstallationCompletion:(NSURL *)callbackURL
356358
MSID_LOG_WITH_CTX(MSIDLogLevelWarning, self.requestParameters,
357359
@"Unexpected callback URL from profile installation: %@", callbackURL);
358360

359-
// Clean up
361+
// Clean up - this will dismiss the session if still active
360362
[self.transitionCoordinator cleanup];
361363

362364
// Create error for unexpected callback

IdentityCore/src/webview/MSIDWebviewTransitionCoordinator.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ NS_ASSUME_NONNULL_BEGIN
7878

7979
/**
8080
* Dismisses the ASWebAuthenticationSession if active
81+
* NOTE: Only call this if the session needs to be canceled (error, timeout, user cancellation).
82+
* If the session has already completed successfully (completion handler fired with callback URL),
83+
* the session has already cleaned itself up - just set externalSessionHandler = nil instead.
8184
*/
8285
- (void)dismissExternalSession;
8386

IdentityCore/src/webview/MSIDWebviewTransitionCoordinator.m

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,11 @@ - (void)dismissExternalSession
159159
{
160160
if (self.externalSessionHandler)
161161
{
162-
MSID_LOG_WITH_CTX(MSIDLogLevelInfo, nil, @"[MSIDWebviewTransitionCoordinator] Dismissing external session");
162+
MSID_LOG_WITH_CTX(MSIDLogLevelInfo, nil, @"[MSIDWebviewTransitionCoordinator] Dismissing external session (canceling active session)");
163163

164-
// Dismiss the ASWebAuthenticationSession
164+
// Cancel the ASWebAuthenticationSession
165+
// NOTE: Only call this if the session is still active and needs to be canceled
166+
// If the session has already completed (completion handler fired), it has cleaned itself up
165167
[self.externalSessionHandler dismiss];
166168
self.externalSessionHandler = nil;
167169
}
@@ -173,8 +175,11 @@ - (void)cleanup
173175

174176
self.suspendedEmbeddedWebview = nil;
175177

178+
// Dismiss external session if still active (e.g., on error or cancellation)
179+
// If the session completed successfully, it should already be nil
176180
if (self.externalSessionHandler)
177181
{
182+
MSID_LOG_WITH_CTX(MSIDLogLevelVerbose, nil, @"[MSIDWebviewTransitionCoordinator] Dismissing active external session during cleanup");
178183
[self.externalSessionHandler dismiss];
179184
self.externalSessionHandler = nil;
180185
}

0 commit comments

Comments
 (0)