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

Commit

Permalink
WIP Use WebChannels for FxA integration
Browse files Browse the repository at this point in the history
  • Loading branch information
Grisha Kruglov committed Aug 26, 2019
1 parent 153af58 commit aed1b0f
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 12 deletions.
5 changes: 4 additions & 1 deletion app/src/main/java/org/mozilla/fenix/AppRequestInterceptor.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,11 @@ class AppRequestInterceptor(private val context: Context) : RequestInterceptor {
}

adjustTrackingProtection(host, context, session)

return null

// Accounts uses interception to check for a "success URL" in the sign-in flow to finalize authentication.
return context.components.services.accountsAuthFeature.interceptor.onLoadRequest(session, uri)
// return context.components.services.accountsAuthFeature.interceptor.onLoadRequest(session, uri)
}

private fun adjustTrackingProtection(host: String, context: Context, session: EngineSession) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class IntentReceiverActivity : Activity() {
private fun setIntentActivity(intent: Intent) {
val openToBrowser = when {
components.utils.customTabIntentProcessor.matches(intent) -> {
// TODO This is potentially unsafe. Any app on the system can set the auth extra.
val activityClass = if (intent.hasExtra(getString(R.string.intent_extra_auth))) {
AuthCustomTabActivity::class
} else {
Expand Down
14 changes: 14 additions & 0 deletions app/src/main/java/org/mozilla/fenix/browser/BrowserFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import kotlinx.coroutines.withContext
import mozilla.appservices.places.BookmarkRoot
import mozilla.components.browser.session.Session
import mozilla.components.feature.readerview.ReaderViewFeature
import mozilla.components.feature.accounts.WebChannelFeature
import mozilla.components.feature.session.ThumbnailsFeature
import mozilla.components.feature.sitepermissions.SitePermissions
import mozilla.components.lib.state.ext.consumeFrom
Expand Down Expand Up @@ -63,6 +64,7 @@ class BrowserFragment : BaseBrowserFragment(), BackHandler {

private val readerViewFeature = ViewBoundFeatureWrapper<ReaderViewFeature>()
private val thumbnailsFeature = ViewBoundFeatureWrapper<ThumbnailsFeature>()
private val webchannelIntegration = ViewBoundFeatureWrapper<WebChannelFeature>()

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand Down Expand Up @@ -102,6 +104,18 @@ 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
)

readerViewFeature.set(
feature = ReaderViewFeature(
requireContext(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class BackgroundServices(
) {
companion object {
const val CLIENT_ID = "a2270f727f45f648"
const val REDIRECT_URL = "https://accounts.firefox.com/oauth/success/$CLIENT_ID"
const val REDIRECT_URL = "urn:ietf:wg:oauth:2.0:oob:oauth-redirect-webchannel"
}

fun defaultDeviceName(context: Context): String = context.getString(
Expand All @@ -64,7 +64,7 @@ class BackgroundServices(
Build.MODEL
)

private val serverConfig = ServerConfig.release(CLIENT_ID, REDIRECT_URL)
private val serverConfig = ServerConfig("https://oauthchannel.dev.lcip.org", CLIENT_ID, REDIRECT_URL)
private val deviceConfig = DeviceConfig(
name = defaultDeviceName(context),
type = DeviceType.MOBILE,
Expand Down
12 changes: 5 additions & 7 deletions app/src/main/java/org/mozilla/fenix/components/Core.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ import mozilla.components.browser.storage.sync.PlacesHistoryStorage
import mozilla.components.concept.engine.DefaultSettings
import mozilla.components.concept.engine.Engine
import mozilla.components.concept.engine.EngineSession.TrackingProtectionPolicy
import mozilla.components.concept.engine.EngineSession.TrackingProtectionPolicy.SafeBrowsingCategory
import mozilla.components.concept.engine.EngineSession.TrackingProtectionPolicy.Companion.select
import mozilla.components.concept.engine.EngineSession.TrackingProtectionPolicy.TrackingCategory
import mozilla.components.concept.engine.mediaquery.PreferredColorScheme
import mozilla.components.concept.fetch.Client
import mozilla.components.feature.media.MediaFeature
Expand Down Expand Up @@ -179,10 +176,11 @@ class Core(private val context: Context) {
normalMode && privateMode -> trackingProtectionPolicy
normalMode && !privateMode -> trackingProtectionPolicy.forRegularSessionsOnly()
!normalMode && privateMode -> trackingProtectionPolicy.forPrivateSessionsOnly()
else -> select(
trackingCategories = arrayOf(TrackingCategory.NONE),
safeBrowsingCategories = arrayOf(SafeBrowsingCategory.RECOMMENDED)
)
else -> trackingProtectionPolicy.forRegularSessionsOnly()
// else -> select(
// trackingCategories = arrayOf(TrackingCategory.NONE),
// safeBrowsingCategories = arrayOf(SafeBrowsingCategory.RECOMMENDED)
// )
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import org.mozilla.fenix.ext.components

class AuthCustomTabActivity : CustomTabActivity() {
private lateinit var accountManager: FxaAccountManager

// Navigate away from this activity when we have successful authentication
private val accountStateObserver = object : AccountObserver {
override fun onAuthenticated(account: OAuthAccount, newAccount: Boolean) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ class QuickSettingsUIView(
drawableTint = R.color.photonGreen50
} else {
stringId = R.string.quick_settings_sheet_insecure_connection
drawableId = R.drawable.mozac_ic_broken_lock
drawableId = R.drawable.mozac_ic_lock
drawableTint = R.color.photonRed50
}

Expand Down

0 comments on commit aed1b0f

Please sign in to comment.