[Windows] WebAuthenticator: add protocol callback support via app activation - #36415
Conversation
|
@dotnet-policy-service agree |
9df876b to
1b105a5
Compare
This comment has been minimized.
This comment has been minimized.
1b105a5 to
30fcb50
Compare
|
The branch has been force-pushed with the latest revision ( The WebAuthenticator Unit, Public API, Windows build, sample build, and all 14 WebAuthenticator Windows device tests passed. Human-interaction tests still require manual validation. This PR routes callbacks to the original app instance but does not explicitly bring its window to the foreground; that should be addressed separately. |
This comment has been minimized.
This comment has been minimized.
30fcb50 to
513b29d
Compare
|
Supersedes the previous update for With this revision, the PR is now complete and ready for review. The Windows WebAuthenticator flow now covers protocol routing, consecutive authentications, minimized and multi-window scenarios, and best-effort foreground activation without affecting the OAuth result. The branch has been force-pushed with the latest revision ( Minimized or hidden windows are restored without intermediate activation before the single
The updated Essentials Windows target builds with 0 warnings and 0 errors. Manual OAuth verification confirmed that the existing MAUI window returns in front of the browser; the remaining minimized, maximized, multi-window, cancellation/retry, invalid-callback, and consecutive-authentication cases are documented as human-interaction validation scenarios in the PR description. |
This comment has been minimized.
This comment has been minimized.
c1554db
into
dotnet:windows-app-activation-lifecycle
Note
Are you waiting for the changes in this PR to be merged?
It would be very helpful if you could test the resulting artifacts from this PR and let us know in a comment if this change resolves your issue. Thank you!
Root Cause
WebAuthenticatoris unsupported on Windows. A custom-protocol callback may launch a second app process, so Windows needs both protocol activation handling and cross-instance routing back to the process that owns the pending authentication.Windows App SDK also cannot reliably re-register an
AppInstanceafterUnregisterKey()(microsoft/WindowsAppSDK#4420). Releasing the route after the first authentication caused a subsequent callback process to find no route owner.After a redirected callback completes, the existing MAUI window is not automatically restored or brought in front of the browser. The request must retain its originating window and perform a best-effort foreground activation only after a valid callback completes it.
Description of Change
Adds a Windows implementation that preserves the existing cross-platform contract: caller-provided authentication URL and callback URL in,
WebAuthenticatorResultout.Launcher.LaunchUriAsyncOnAppInstanceActivatedfrom [Windows] Lifecycle: Add AppInstance activated event #34883AppInstanceroute for the callback schemeIPlatformWebAuthenticatorCallbackAppWindowthat started each authentication so multi-window callbacks return to the correct windowThis intentionally does not use
OAuth2Manager. The caller still ownsstate, PKCE, provider parameters, and token exchange.Key Technical Details
Microsoft.Maui.WebAuthenticator:{scheme}AppInstancekeys are preservedAppInstance.GetInstances()to find the route owner without registering another keyWebUtils.CanHandleCallback(...)UnregisterKey()re-registration issueTrySetResultmay restore and foreground its captured windowOverlappedPresenter.Restore(false)and hidden windows useAppWindow.Show(false)soSetForegroundWindowis the only explicit activation requestRedirectActivationToAsyncalready requests foreground permission for the route-owner process throughAllowSetForegroundWindowin Windows App SDKAppInstance::QueueRequest. MAUI therefore does not duplicate that call.The foreground path intentionally does not use
AppWindow.DispatcherQueue.AppWindowandOverlappedPresenterare agile, and a dispatcher queue is not guaranteed to be available in the redirected activation context.Packaged apps declare the callback scheme in
AppxManifest.xml; unpackaged apps register it withActivationRegistrationManager.RegisterForProtocolActivation(...).Foreground Behavior
Windows ultimately decides whether
SetForegroundWindowsucceeds. Foreground activation is therefore best effort by design: failure is diagnostic only and never changes a successful authentication result.Testing
The routing revision passed Unit, Public API, Windows build, sample build, and all 14 WebAuthenticator Windows device tests.
The foreground revision was validated with:
Microsoft.Maui.EssentialsWindows build: 0 warnings, 0 errorsAppWindow.DispatcherQueuefrom the redirected activation context can fail withCOMException; the final implementation does not depend on itAdditional human-interaction validation remains useful for minimized, maximized, multi-window, cancellation followed by retry, invalid callback, and consecutive-authentication scenarios.
Breaking Changes
None.
Issues Fixed
Looking forward to your feedback, thanks!
@mattleibow
@dotMorten