Add AuthTab support for MSAL browser auth and Broker DUNA flows, Fixes AB#3533538#2998
Draft
Add AuthTab support for MSAL browser auth and Broker DUNA flows, Fixes AB#3533538#2998
Conversation
|
✅ Work item link check complete. Description contains link AB#3533538 to an Azure Boards work item. |
…rowserActivity, CustomTabsManager helper, and tests Co-authored-by: shahzaibj <37125644+shahzaibj@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Implement full AuthTab support in Common repo, Fixes AB#3533538
Add AuthTab support for MSAL browser auth and Broker DUNA flows
Mar 4, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Chrome 137+ introduces
AuthTabIntent(androidx.browser:browser:1.9.0), which returns auth results viaActivityResultCallbackinstead of intent-based redirects — improving security and simplifying redirect handling. This PR wires up AuthTab support behind anENABLE_AUTH_TABfeature flag (defaultfalse) for two flows: MSAL interactive browser auth and Broker Switch Browser (DUNA).Changes
Feature Flag
CommonFlight.ENABLE_AUTH_TAB("EnableAuthTab", false)added toCommonFlight.javaDependency
browserVersion:1.7.0→1.9.0ingradle/versions.gradleTelemetry (
AttributeName.java)is_auth_tab_used,auth_tab_result_code,auth_tab_supportedNew:
AuthTabAuthorizationFragment(MSAL browser flow)Extends
AuthorizationFragment; replacesBrowserAuthorizationFragmentwhenENABLE_AUTH_TABis on.ActivityResultLauncherinonCreate()(required before STARTED state)AuthTabIntentinonResume()withrequestUrl/redirectSchemefrom argumentsRESULT_OK,RESULT_CANCELED,RESULT_VERIFICATION_FAILED,RESULT_VERIFICATION_TIMED_OUTonResume()without a callback result → treated as user cancellationAuthorizationActivityFactoryupdateENABLE_AUTH_TABis enabled → returnsAuthTabAuthorizationFragment()instead ofBrowserAuthorizationFragment()SwitchBrowserActivityupdate (DUNA flow)AuthTabIntent.ActivityResultLauncherinonCreate()launchBrowser()pre-checksENABLE_AUTH_TABflag +CustomTabsManager.isAuthTabSupported()before the existing Custom Tabs pathhandleAuthTabResult():RESULT_OK→ passes URI viaWebViewAuthorizationFragment.setSwitchBrowserBundle()+finishAndRemoveTask(); cancel/error →finishAndRemoveTask()CustomTabsManager.isAuthTabSupported()helperStatic method wrapping
CustomTabsClient.isAuthTabSupported(context, browserPackage)with null-safety and logging.Tests (
AuthorizationActivityFactoryTest)ENABLE_AUTH_TAB = true→getAuthorizationFragmentFromStartIntent()returnsAuthTabAuthorizationFragmentENABLE_AUTH_TAB = false→ returnsBrowserAuthorizationFragment(existing behavior unchanged)Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
dl.google.com/usr/lib/jvm/temurin-17-jdk-amd64/bin/java /usr/lib/jvm/temurin-17-jdk-amd64/bin/java --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.lang.invoke=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.prefs/java.util.prefs=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.prefs/java.util.prefs=ALL-UNNAMED --add-opens=java.base/java.nio.charset=ALL-UNNAMED --add-opens=java.base/java.net=ALL-UNNAMED --add-opens=java.base/java.util.concurrent.atomic=ALL-UNNAMED --add-opens=java.xml/javax.xml.namespace=ALL-UNNAMED -XX:MaxMetaspaceSize=1024m -XX:+HeapDumpOnOutOfMemoryError -Xmx3072m -Dfile.encoding=UTF-8 -Duser.country -Duser.language=en -Duser.variant(dns block)identitydivision.pkgs.visualstudio.com/usr/lib/jvm/temurin-17-jdk-amd64/bin/java /usr/lib/jvm/temurin-17-jdk-amd64/bin/java --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.lang.invoke=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.prefs/java.util.prefs=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.prefs/java.util.prefs=ALL-UNNAMED --add-opens=java.base/java.nio.charset=ALL-UNNAMED --add-opens=java.base/java.net=ALL-UNNAMED --add-opens=java.base/java.util.concurrent.atomic=ALL-UNNAMED --add-opens=java.xml/javax.xml.namespace=ALL-UNNAMED -XX:MaxMetaspaceSize=1024m -XX:+HeapDumpOnOutOfMemoryError -Xmx3072m -Dfile.encoding=UTF-8 -Duser.country -Duser.language=en -Duser.variant(dns block)www.puppycrawl.com/opt/hostedtoolcache/CodeQL/2.24.2/x64/codeql/tools/linux64/java/bin/java /opt/hostedtoolcache/CodeQL/2.24.2/x64/codeql/tools/linux64/java/bin/java -jar /opt/hostedtoolcache/CodeQL/2.24.2/x64/codeql/xml/tools/xml-extractor.jar --fileList=/tmp/codeql-scratch-b2678d0398b00160/dbs/java/working/files-to-index8780552885994131758.list --sourceArchiveDir=/tmp/codeql-scratch-b2678d0398b00160/dbs/java/src --outputDir=/tmp/codeql-scratch-b2678d0398b00160/dbs/java/trap/java /opt/hostedtoolcache/CodeQL/2.24.2/x64/codeql/java/tools/setup-proxy.gradle --init-script /opt/hostedtoolcache/CodeQL/2.24.2/x64/codeql/java/tools/dep-graph.gradle ForceDependencyResolutionPlugin_resolveAllDependencies --stacktrace -DGITHUB_DEPENDENCY_GRAPH_JOB_CORRELATOR=dep-graph(dns block)If you need me to access, download, or install something from one of these locations, you can either:
Original prompt
Fixes AB#3533538
Objective
Implement full AuthTab support in the Common repo: add the
ENABLE_AUTH_TABfeature flag toCommonFlight, create a newAuthTabAuthorizationFragmentfor MSAL browser flows, updateAuthorizationActivityFactoryto route to it, updateSwitchBrowserActivityfor DUNA flows, add anisAuthTabSupported()helper inCustomTabsManager, and bumpandroidx.browserto 1.9.0.Target Repository
Context
Chrome 137+ introduces AuthTab (
AuthTabIntentfromandroidx.browser:browser:1.9.0), a specialized Custom Tab for authentication. AuthTab returns results viaActivityResultCallbackinstead of intent-based redirects, improving security and simplifying the flow. This PBI implements AuthTab support for two paths:AuthTabAuthorizationFragmentreplacesBrowserAuthorizationFragmentwhen AuthTab is enabled and supported.SwitchBrowserActivitygains an AuthTab launch path alongside its existing Custom Tabs path.Both paths fall back to standard Custom Tabs when the browser doesn't support AuthTab.
Feature Flag
Create a new
ENABLE_AUTH_TABenum value inCommonFlight.java(common4j module) with config key"EnableAuthTab"and defaultfalse. Follow the pattern ofSWITCH_BROWSER_PROTOCOL_REQUIRES_STATE. Then gate all new behavior behindCommonFlightsManager.getFlightsProvider().isFlightEnabled(CommonFlight.ENABLE_AUTH_TAB).Technical Requirements
1. Feature Flag (common4j)
ENABLE_AUTH_TAB("EnableAuthTab", false)toCommonFlight.java2. Dependency Bump
browserVersion = "1.7.0"tobrowserVersion = "1.9.0"ingradle/versions.gradle3. New AuthTabAuthorizationFragment.kt (common)
common/src/main/java/com/microsoft/identity/common/internal/providers/oauth2/AuthorizationFragmentonCreate(), registerActivityResultLauncherviaAuthTabIntent.registerActivityResultLauncher(this, ::handleAuthResult)- MUST be before STARTED stateonResume(), buildAuthTabIntent.Builder().build()and callauthTabIntent.launch(launcher, uri, redirectScheme)requestUrlandredirectSchemefrom fragment arguments (same pattern asBrowserAuthorizationFragmentgetsmAuthIntent)AuthResult: RESULT_OK ->sendResult(RawAuthorizationResult.fromRedirectUri(...)), RESULT_CANCELED ->cancelAuthorization(true), RESULT_VERIFICATION_FAILED/TIMED_OUT -> send exception resultis_auth_tab_used,auth_tab_result_code,auth_tab_supportedLoggerclassonSaveInstanceState/extractStateforauthFlowStartedflag4. Update AuthorizationActivityFactory.kt
getAuthorizationFragmentFromStartIntent(), when agent is NOT WEBVIEW, checkCommonFlight.ENABLE_AUTH_TAB. If true, returnAuthTabAuthorizationFragment()5. Update SwitchBrowserActivity.kt
launchBrowser(), before existing Custom Tabs check: if AuthTab flag on +CustomTabsClient.isAuthTabSupported()returns true, launch viaAuthTabIntentActivityResultLauncherinonCreate()(must be before onStart)WebViewAuthorizationFragment.setSwitchBrowserBundle()+finishAndRemoveTask(); cancel/error ->finishAndRemoveTask()6. Add isAuthTabSupported() to CustomTabsManager.java
public static boolean isAuthTabSupported(@NonNull Context context, @NonNull String browserPackage)CustomTabsClient.isAuthTabSupported()with null-safety and loggingFiles to Modify/Create
common4j/src/main/com/microsoft/identity/common/java/flighting/CommonFlight.java- Add ENABLE_AUTH_TAB enumgradle/versions.gradle- browserVersion = "1.9.0"common/src/main/java/com/microsoft/identity/common/internal/providers/oauth2/AuthTabAuthorizationFragment.kt- NEW: AuthTab authorization fragmentcommon/src/main/java/com/microsoft/identity/common/internal/providers/oauth2/AuthorizationActivityFactory.kt- Add AuthTab branchcommon/src/main/java/com/microsoft/identity/common/internal/providers/oauth2/SwitchBrowserActivity.kt- Add AuthTab launch pathcommon/src/main/java/com/microsoft/identity/common/internal/ui/browser/CustomTabsManager.java- Add isAuthTabSupported()common/src/test/java/com/microsoft/identity/common/internal/providers/oauth2/AuthTabAuthorizationFragmentTest.kt- NEW: Unit testscommon/src/test/java/com/microsoft/identity/common/internal/providers/oauth2/AuthorizationActivityFactoryTest.java- Add AuthTab testsAcceptance Criteria
CommonFlight.ENABLE_AUTH_TABexists w...💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.