Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Unverified Commit 5b389432 authored by Ricki Hirner's avatar Ricki Hirner
Browse files

Support OAuth for Google (bitfireAT/davx5#289)

* Proof of concept (without auth state storage)
* Implement Bearer authentication, create network package
* Properly create/dispose AuthService
* Use proper ActivityResultContract
* Integrate into default login activity
* Change client ID to davx5integration@gmail.com
* Google Login: adapt login view
* Fix tests
* Don't allow empty Google account
* Move strings to resources
parent 1b3fde08
Loading
Loading
Loading
Loading
+8 −1
Original line number Diff line number Diff line
@@ -28,6 +28,10 @@ android {

        buildConfigField "String", "userAgent", "\"DAVx5\""

        manifestPlaceholders = [
            'appAuthRedirectScheme': applicationId
        ]

        testInstrumentationRunner "at.bitfire.davdroid.CustomTestRunner"

        kapt {
@@ -123,7 +127,7 @@ dependencies {
    implementation 'androidx.concurrent:concurrent-futures-ktx:1.1.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
    implementation 'androidx.core:core-ktx:1.10.1'
    implementation 'androidx.fragment:fragment-ktx:1.5.7'
    implementation 'androidx.fragment:fragment-ktx:1.6.0'
    implementation 'androidx.hilt:hilt-work:1.0.0'
    kapt 'androidx.hilt:hilt-compiler:1.0.0'
    implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
@@ -135,6 +139,7 @@ dependencies {
    implementation 'androidx.work:work-runtime-ktx:2.8.1'
    implementation 'com.google.android.flexbox:flexbox:3.0.0'
    implementation 'com.google.android.material:material:1.9.0'
    implementation 'net.openid:appauth:0.11.1'

    // Jetpack Compose
    def composeBom = platform("androidx.compose:compose-bom:${versions.composeBom}")
@@ -142,6 +147,8 @@ dependencies {
    androidTestImplementation composeBom
    implementation 'androidx.compose.material:material'
    implementation 'androidx.compose.runtime:runtime-livedata'
    debugImplementation 'androidx.compose.ui:ui-tooling'
    implementation 'androidx.compose.ui:ui-tooling-preview'
    implementation 'com.google.accompanist:accompanist-themeadapter-material:0.30.1'

    // Jetpack Room
+3 −2
Original line number Diff line number Diff line
@@ -6,9 +6,10 @@ package at.bitfire.davdroid.db

import android.security.NetworkSecurityPolicy
import androidx.test.filters.SmallTest
import androidx.test.platform.app.InstrumentationRegistry
import at.bitfire.dav4jvm.DavResource
import at.bitfire.dav4jvm.property.ResourceType
import at.bitfire.davdroid.HttpClient
import at.bitfire.davdroid.network.HttpClient
import at.bitfire.davdroid.settings.SettingsManager
import dagger.hilt.android.testing.HiltAndroidRule
import dagger.hilt.android.testing.HiltAndroidTest
@@ -43,7 +44,7 @@ class CollectionTest {

    @Before
    fun setUp() {
        httpClient = HttpClient.Builder().build()
        httpClient = HttpClient.Builder(InstrumentationRegistry.getInstrumentation().targetContext).build()
        Assume.assumeTrue(NetworkSecurityPolicy.getInstance().isCleartextTrafficPermitted)
    }

+1 −1
Original line number Diff line number Diff line
@@ -2,7 +2,7 @@
 * Copyright © All Contributors. See LICENSE and AUTHORS in the root directory for details.
 **************************************************************************************************/

package at.bitfire.davdroid
package at.bitfire.davdroid.network

import android.os.Build
import androidx.test.filters.SdkSuppress
+12 −2
Original line number Diff line number Diff line
@@ -2,9 +2,12 @@
 * Copyright © All Contributors. See LICENSE and AUTHORS in the root directory for details.
 **************************************************************************************************/

package at.bitfire.davdroid
package at.bitfire.davdroid.network

import android.security.NetworkSecurityPolicy
import androidx.test.platform.app.InstrumentationRegistry
import dagger.hilt.android.testing.HiltAndroidRule
import dagger.hilt.android.testing.HiltAndroidTest
import okhttp3.Request
import okhttp3.mockwebserver.MockResponse
import okhttp3.mockwebserver.MockWebServer
@@ -13,16 +16,23 @@ import org.junit.Assert.assertEquals
import org.junit.Assert.assertNull
import org.junit.Assume
import org.junit.Before
import org.junit.Rule
import org.junit.Test

@HiltAndroidTest
class HttpClientTest {

    lateinit var server: MockWebServer
    lateinit var httpClient: HttpClient

    @get:Rule
    var hiltRule = HiltAndroidRule(this)

    @Before
    fun setUp() {
        httpClient = HttpClient.Builder().build()
        hiltRule.inject()

        httpClient = HttpClient.Builder(InstrumentationRegistry.getInstrumentation().targetContext).build()

        server = MockWebServer()
        server.start(30000)
+2 −2
Original line number Diff line number Diff line
@@ -10,7 +10,7 @@ import androidx.test.platform.app.InstrumentationRegistry
import at.bitfire.dav4jvm.DavResource
import at.bitfire.dav4jvm.property.AddressbookHomeSet
import at.bitfire.dav4jvm.property.ResourceType
import at.bitfire.davdroid.HttpClient
import at.bitfire.davdroid.network.HttpClient
import at.bitfire.davdroid.db.Credentials
import at.bitfire.davdroid.log.Logger
import at.bitfire.davdroid.servicedetection.DavResourceFinder.Configuration.ServiceInfo
@@ -68,7 +68,7 @@ class DavResourceFinderTest {
        loginModel.credentials = Credentials("mock", "12345")

        finder = DavResourceFinder(InstrumentationRegistry.getInstrumentation().targetContext, loginModel)
        client = HttpClient.Builder()
        client = HttpClient.Builder(InstrumentationRegistry.getInstrumentation().targetContext)
                .addAuthentication(null, loginModel.credentials!!)
                .build()

Loading