From 851edb333ba4d7b7af68d11790bbfc841a426e8a Mon Sep 17 00:00:00 2001 From: Arturo Mejia Date: Wed, 4 Sep 2019 16:14:31 -0400 Subject: [PATCH] Putting web channel authentication behind feature flag for nightly and debug builds. --- .../mozilla/fenix/AppRequestInterceptor.kt | 7 +++++- .../java/org/mozilla/fenix/FeatureFlags.kt | 17 +++++++++++++ .../mozilla/fenix/browser/BrowserFragment.kt | 25 +++++++++++-------- .../fenix/components/BackgroundServices.kt | 15 ++++------- .../components/metrics/GleanMetricsService.kt | 1 + .../fenix/components/metrics/Metrics.kt | 1 + 6 files changed, 44 insertions(+), 22 deletions(-) diff --git a/app/src/main/java/org/mozilla/fenix/AppRequestInterceptor.kt b/app/src/main/java/org/mozilla/fenix/AppRequestInterceptor.kt index 87d1b192688e..ae3bd8528de3 100644 --- a/app/src/main/java/org/mozilla/fenix/AppRequestInterceptor.kt +++ b/app/src/main/java/org/mozilla/fenix/AppRequestInterceptor.kt @@ -26,7 +26,12 @@ class AppRequestInterceptor(private val context: Context) : RequestInterceptor { adjustTrackingProtection(host, context, session) - return null + // WebChannel-driven authentication does not require a separate redirect interceptor. + return if (FeatureFlags.webChannelAuthentication) { + null + } else { + context.components.services.accountsAuthFeature.interceptor.onLoadRequest(session, uri) + } } private fun adjustTrackingProtection(host: String, context: Context, session: EngineSession) { diff --git a/app/src/main/java/org/mozilla/fenix/FeatureFlags.kt b/app/src/main/java/org/mozilla/fenix/FeatureFlags.kt index 3f53f6ca0564..795e7ab1cdc9 100644 --- a/app/src/main/java/org/mozilla/fenix/FeatureFlags.kt +++ b/app/src/main/java/org/mozilla/fenix/FeatureFlags.kt @@ -1,4 +1,5 @@ package org.mozilla.fenix +import org.mozilla.fenix.components.BackgroundServices /** * A single source for setting feature flags that are mostly based on build type. @@ -36,4 +37,20 @@ object FeatureFlags { * https://github.com/mozilla-mobile/fenix/issues/4431 */ const val mediaIntegration = true + val webChannelAuthentication = nightly or debug + val webChannelConfiguration = WebChannelConfigurations() + + data class WebChannelConfigurations( + val redirectUrl: String = + if (webChannelAuthentication) { + "urn:ietf:wg:oauth:2.0:oob:oauth-redirect-webchannel" + } else { + "https://accounts.firefox.com/oauth/success/${BackgroundServices.CLIENT_ID}" + }, + val contentUrl: String = if (debug) { + mozilla.appservices.fxaclient.Config.Server.DEV.contentUrl + } else { + mozilla.appservices.fxaclient.Config.Server.RELEASE.contentUrl + } + ) } diff --git a/app/src/main/java/org/mozilla/fenix/browser/BrowserFragment.kt b/app/src/main/java/org/mozilla/fenix/browser/BrowserFragment.kt index d5fd3b34b43a..1f022807136d 100644 --- a/app/src/main/java/org/mozilla/fenix/browser/BrowserFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/browser/BrowserFragment.kt @@ -33,6 +33,7 @@ import mozilla.components.feature.sitepermissions.SitePermissions import mozilla.components.lib.state.ext.consumeFrom import mozilla.components.support.base.feature.BackHandler import mozilla.components.support.base.feature.ViewBoundFeatureWrapper +import org.mozilla.fenix.FeatureFlags import org.mozilla.fenix.HomeActivity import org.mozilla.fenix.R import org.mozilla.fenix.browser.readermode.DefaultReaderModeController @@ -104,17 +105,19 @@ class BrowserFragment : BaseBrowserFragment(), BackHandler { view = view ) - webchannelIntegration.set( - feature = WebChannelFeature( - requireContext(), - customTabSessionId, - requireComponents.core.engine, - requireComponents.core.sessionManager, - requireComponents.backgroundServices.accountManager - ), - owner = this, - view = view - ) + if (FeatureFlags.webChannelAuthentication) { + webchannelIntegration.set( + feature = WebChannelFeature( + requireContext(), + customTabSessionId, + requireComponents.core.engine, + requireComponents.core.sessionManager, + requireComponents.backgroundServices.accountManager + ), + owner = this, + view = view + ) + } readerViewFeature.set( feature = ReaderViewFeature( diff --git a/app/src/main/java/org/mozilla/fenix/components/BackgroundServices.kt b/app/src/main/java/org/mozilla/fenix/components/BackgroundServices.kt index 23016a2d689b..05c8248d72a7 100644 --- a/app/src/main/java/org/mozilla/fenix/components/BackgroundServices.kt +++ b/app/src/main/java/org/mozilla/fenix/components/BackgroundServices.kt @@ -36,6 +36,7 @@ import mozilla.components.service.fxa.manager.FxaAccountManager import mozilla.components.service.fxa.sync.GlobalSyncableStoreProvider import mozilla.components.support.base.log.logger.Logger import org.mozilla.fenix.Experiments +import org.mozilla.fenix.FeatureFlags import org.mozilla.fenix.R import org.mozilla.fenix.components.metrics.Event import org.mozilla.fenix.ext.components @@ -55,7 +56,7 @@ class BackgroundServices( ) { companion object { const val CLIENT_ID = "a2270f727f45f648" - const val REDIRECT_URL = "urn:ietf:wg:oauth:2.0:oob:oauth-redirect-webchannel" + val REDIRECT_URL = FeatureFlags.webChannelConfiguration.redirectUrl } fun defaultDeviceName(context: Context): String = context.getString( @@ -65,9 +66,7 @@ class BackgroundServices( Build.MODEL ) -// private val serverConfig = ServerConfig.release(CLIENT_ID, REDIRECT_URL) -// TODO replace with release channel ^^ - private val serverConfig = ServerConfig("https://oauthchannel2.dev.lcip.org", CLIENT_ID, REDIRECT_URL) + private val serverConfig = ServerConfig(FeatureFlags.webChannelConfiguration.contentUrl, CLIENT_ID, REDIRECT_URL) private val deviceConfig = DeviceConfig( name = defaultDeviceName(context), type = DeviceType.MOBILE, @@ -75,11 +74,7 @@ class BackgroundServices( // NB: flipping this flag back and worth is currently not well supported and may need hand-holding. // Consult with the android-components peers before changing. // See https://github.com/mozilla/application-services/issues/1308 - capabilities = if (FeatureFlags.sendTabEnabled) { - setOf(DeviceCapability.SEND_TAB) - } else { - emptySet() - } + capabilities = setOf(DeviceCapability.SEND_TAB) ) // If sync has been turned off on the server then disable syncing. private val syncConfig = if (context.isInExperiment(Experiments.asFeatureSyncDisabled)) { @@ -153,7 +148,7 @@ class BackgroundServices( } if (authType == AuthType.Signup) { - context.components.analytics.metrics.track(Event.FXANewSignup) + context.components.analytics.metrics.track(Event.SyncAuthSignUp) } else if (authType == AuthType.Signin) { context.components.analytics.metrics.track(Event.SyncAuthSignIn) } diff --git a/app/src/main/java/org/mozilla/fenix/components/metrics/GleanMetricsService.kt b/app/src/main/java/org/mozilla/fenix/components/metrics/GleanMetricsService.kt index 82a57b116d7a..dc0cde8a8c24 100644 --- a/app/src/main/java/org/mozilla/fenix/components/metrics/GleanMetricsService.kt +++ b/app/src/main/java/org/mozilla/fenix/components/metrics/GleanMetricsService.kt @@ -338,6 +338,7 @@ private val Event.wrapper: EventWrapper<*>? is Event.InteractWithSearchURLArea -> null is Event.ClearedPrivateData -> null is Event.DismissedOnboarding -> null + Event.SyncAuthSignUp -> null } class GleanMetricsService(private val context: Context) : MetricsService { diff --git a/app/src/main/java/org/mozilla/fenix/components/metrics/Metrics.kt b/app/src/main/java/org/mozilla/fenix/components/metrics/Metrics.kt index 4aa09d800736..9275b950f62f 100644 --- a/app/src/main/java/org/mozilla/fenix/components/metrics/Metrics.kt +++ b/app/src/main/java/org/mozilla/fenix/components/metrics/Metrics.kt @@ -64,6 +64,7 @@ sealed class Event { object LibraryClosed : Event() object SyncAuthOpened : Event() object SyncAuthClosed : Event() + object SyncAuthSignUp: Event() object SyncAuthSignIn : Event() object SyncAuthSignOut : Event() object SyncAuthScanPairing : Event()