Skip to content
This repository has been archived by the owner on Feb 20, 2023. It is now read-only.

Commit

Permalink
Putting web channel authentication behind feature flag for nightly
Browse files Browse the repository at this point in the history
and debug builds.
  • Loading branch information
Amejia481 committed Sep 6, 2019
1 parent fcf92b7 commit 851edb3
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 22 deletions.
7 changes: 6 additions & 1 deletion app/src/main/java/org/mozilla/fenix/AppRequestInterceptor.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
17 changes: 17 additions & 0 deletions app/src/main/java/org/mozilla/fenix/FeatureFlags.kt
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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
}
)
}
25 changes: 14 additions & 11 deletions app/src/main/java/org/mozilla/fenix/browser/BrowserFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(
Expand All @@ -65,21 +66,15 @@ 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,

// 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)) {
Expand Down Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 851edb3

Please sign in to comment.