Loading app/src/main/java/at/bitfire/davdroid/OpenIdUtils.kt 0 → 100644 +32 −0 Original line number Diff line number Diff line /* * Copyright MURENA SAS 2023 * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. */ package at.bitfire.davdroid import net.openid.appauth.ClientAuthentication import net.openid.appauth.ClientSecretBasic import net.openid.appauth.NoClientAuthentication object OpenIdUtils { fun getClientAuthentication(secret: String?): ClientAuthentication { if (secret == null) { return NoClientAuthentication.INSTANCE } return ClientSecretBasic(secret) } } app/src/main/java/at/bitfire/davdroid/db/Credentials.kt +7 −6 Original line number Diff line number Diff line Loading @@ -12,7 +12,8 @@ data class Credentials( val password: String? = null, val authState: AuthState? = null, val certificateAlias: String? = null, val serverUri: URI? = null val serverUri: URI? = null, val clientSecret: String? = null ) { override fun toString(): String { Loading app/src/main/java/at/bitfire/davdroid/settings/AccountSettings.kt +8 −1 Original line number Diff line number Diff line Loading @@ -93,6 +93,7 @@ class AccountSettings( const val KEY_USERNAME = "user_name" const val KEY_EMAIL_ADDRESS = "email_address" const val KEY_AUTH_STATE = "auth_state" const val KEY_CLIENT_SECRET = "client_secret" const val KEY_CERTIFICATE_ALIAS = "certificate_alias" const val KEY_WIFI_ONLY = "wifi_only" // sync on WiFi only (default: false) Loading Loading @@ -155,6 +156,10 @@ class AccountSettings( if (credentials.authState != null) { bundle.putString(KEY_AUTH_STATE, credentials.authState.jsonSerializeString()) } if (credentials.clientSecret != null) { bundle.putString(KEY_CLIENT_SECRET, credentials.clientSecret) } } if (!baseURL.isNullOrEmpty()) { Loading Loading @@ -258,7 +263,8 @@ class AccountSettings( accountManager.getUserData(account, KEY_USERNAME), accountManager.getPassword(account), AuthState.jsonDeserialize(accountManager.getUserData(account, KEY_AUTH_STATE)), accountManager.getUserData(account, KEY_CERTIFICATE_ALIAS) accountManager.getUserData(account, KEY_CERTIFICATE_ALIAS), clientSecret = accountManager.getUserData(account, KEY_CLIENT_SECRET) ) } } Loading @@ -274,6 +280,7 @@ class AccountSettings( accountManager.setPassword(account, credentials.password) accountManager.setUserData(account, KEY_AUTH_STATE, credentials.authState.jsonSerializeString()) accountManager.setUserData(account, KEY_CERTIFICATE_ALIAS, credentials.certificateAlias) accountManager.setUserData(account, KEY_CLIENT_SECRET, credentials.clientSecret) } } Loading app/src/main/java/at/bitfire/davdroid/syncadapter/CalendarsSyncAdapterService.kt +8 −3 Original line number Diff line number Diff line Loading @@ -12,6 +12,7 @@ import android.os.AsyncTask import android.os.Bundle import android.provider.CalendarContract import at.bitfire.davdroid.HttpClient import at.bitfire.davdroid.OpenIdUtils import at.bitfire.davdroid.db.AppDatabase import at.bitfire.davdroid.db.Collection import at.bitfire.davdroid.db.Credentials Loading Loading @@ -91,15 +92,18 @@ open class CalendarsSyncAdapterService : SyncAdapterService() { if (authState != null) { if (authState.needsTokenRefresh) { val tokenRequest = authState.createTokenRefreshRequest() val clientSecretString = accountSettings.credentials().clientSecret val clientSecret = OpenIdUtils.getClientAuthentication(clientSecretString) AuthorizationService(context).performTokenRequest(tokenRequest) { tokenResponse, ex -> AuthorizationService(context).performTokenRequest(tokenRequest, clientSecret) { tokenResponse, ex -> authState.update(tokenResponse, ex) accountSettings.credentials( Credentials( account.name, null, authState, null null, clientSecret = clientSecretString ) ) it.accountSettings.credentials( Loading @@ -107,7 +111,8 @@ open class CalendarsSyncAdapterService : SyncAdapterService() { it.account.name, null, authState, null null, clientSecret = clientSecretString ) ) object : AsyncTask<Void, Void, Void>() { Loading app/src/main/java/at/bitfire/davdroid/syncadapter/ContactsSyncAdapterService.kt +8 −3 Original line number Diff line number Diff line Loading @@ -13,6 +13,7 @@ import android.os.AsyncTask import android.os.Bundle import android.provider.ContactsContract import at.bitfire.davdroid.HttpClient import at.bitfire.davdroid.OpenIdUtils import at.bitfire.davdroid.db.AppDatabase import at.bitfire.davdroid.db.Credentials import at.bitfire.davdroid.log.Logger Loading Loading @@ -71,15 +72,18 @@ class ContactsSyncAdapterService: SyncAdapterService() { if (authState != null) { if (authState.needsTokenRefresh) { val tokenRequest = authState.createTokenRefreshRequest() val clientSecretString = accountSettings.credentials().clientSecret val clientSecret = OpenIdUtils.getClientAuthentication(clientSecretString) AuthorizationService(context).performTokenRequest(tokenRequest) { tokenResponse, ex -> AuthorizationService(context).performTokenRequest(tokenRequest, clientSecret) { tokenResponse, ex -> authState.update(tokenResponse, ex) accountSettings.credentials( Credentials( account.name, null, authState, null null, clientSecret = clientSecretString ) ) it.accountSettings.credentials( Loading @@ -87,7 +91,8 @@ class ContactsSyncAdapterService: SyncAdapterService() { it.account.name, null, authState, null null, clientSecret = clientSecretString ) ) object : AsyncTask<Void, Void, Void>() { Loading Loading
app/src/main/java/at/bitfire/davdroid/OpenIdUtils.kt 0 → 100644 +32 −0 Original line number Diff line number Diff line /* * Copyright MURENA SAS 2023 * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. */ package at.bitfire.davdroid import net.openid.appauth.ClientAuthentication import net.openid.appauth.ClientSecretBasic import net.openid.appauth.NoClientAuthentication object OpenIdUtils { fun getClientAuthentication(secret: String?): ClientAuthentication { if (secret == null) { return NoClientAuthentication.INSTANCE } return ClientSecretBasic(secret) } }
app/src/main/java/at/bitfire/davdroid/db/Credentials.kt +7 −6 Original line number Diff line number Diff line Loading @@ -12,7 +12,8 @@ data class Credentials( val password: String? = null, val authState: AuthState? = null, val certificateAlias: String? = null, val serverUri: URI? = null val serverUri: URI? = null, val clientSecret: String? = null ) { override fun toString(): String { Loading
app/src/main/java/at/bitfire/davdroid/settings/AccountSettings.kt +8 −1 Original line number Diff line number Diff line Loading @@ -93,6 +93,7 @@ class AccountSettings( const val KEY_USERNAME = "user_name" const val KEY_EMAIL_ADDRESS = "email_address" const val KEY_AUTH_STATE = "auth_state" const val KEY_CLIENT_SECRET = "client_secret" const val KEY_CERTIFICATE_ALIAS = "certificate_alias" const val KEY_WIFI_ONLY = "wifi_only" // sync on WiFi only (default: false) Loading Loading @@ -155,6 +156,10 @@ class AccountSettings( if (credentials.authState != null) { bundle.putString(KEY_AUTH_STATE, credentials.authState.jsonSerializeString()) } if (credentials.clientSecret != null) { bundle.putString(KEY_CLIENT_SECRET, credentials.clientSecret) } } if (!baseURL.isNullOrEmpty()) { Loading Loading @@ -258,7 +263,8 @@ class AccountSettings( accountManager.getUserData(account, KEY_USERNAME), accountManager.getPassword(account), AuthState.jsonDeserialize(accountManager.getUserData(account, KEY_AUTH_STATE)), accountManager.getUserData(account, KEY_CERTIFICATE_ALIAS) accountManager.getUserData(account, KEY_CERTIFICATE_ALIAS), clientSecret = accountManager.getUserData(account, KEY_CLIENT_SECRET) ) } } Loading @@ -274,6 +280,7 @@ class AccountSettings( accountManager.setPassword(account, credentials.password) accountManager.setUserData(account, KEY_AUTH_STATE, credentials.authState.jsonSerializeString()) accountManager.setUserData(account, KEY_CERTIFICATE_ALIAS, credentials.certificateAlias) accountManager.setUserData(account, KEY_CLIENT_SECRET, credentials.clientSecret) } } Loading
app/src/main/java/at/bitfire/davdroid/syncadapter/CalendarsSyncAdapterService.kt +8 −3 Original line number Diff line number Diff line Loading @@ -12,6 +12,7 @@ import android.os.AsyncTask import android.os.Bundle import android.provider.CalendarContract import at.bitfire.davdroid.HttpClient import at.bitfire.davdroid.OpenIdUtils import at.bitfire.davdroid.db.AppDatabase import at.bitfire.davdroid.db.Collection import at.bitfire.davdroid.db.Credentials Loading Loading @@ -91,15 +92,18 @@ open class CalendarsSyncAdapterService : SyncAdapterService() { if (authState != null) { if (authState.needsTokenRefresh) { val tokenRequest = authState.createTokenRefreshRequest() val clientSecretString = accountSettings.credentials().clientSecret val clientSecret = OpenIdUtils.getClientAuthentication(clientSecretString) AuthorizationService(context).performTokenRequest(tokenRequest) { tokenResponse, ex -> AuthorizationService(context).performTokenRequest(tokenRequest, clientSecret) { tokenResponse, ex -> authState.update(tokenResponse, ex) accountSettings.credentials( Credentials( account.name, null, authState, null null, clientSecret = clientSecretString ) ) it.accountSettings.credentials( Loading @@ -107,7 +111,8 @@ open class CalendarsSyncAdapterService : SyncAdapterService() { it.account.name, null, authState, null null, clientSecret = clientSecretString ) ) object : AsyncTask<Void, Void, Void>() { Loading
app/src/main/java/at/bitfire/davdroid/syncadapter/ContactsSyncAdapterService.kt +8 −3 Original line number Diff line number Diff line Loading @@ -13,6 +13,7 @@ import android.os.AsyncTask import android.os.Bundle import android.provider.ContactsContract import at.bitfire.davdroid.HttpClient import at.bitfire.davdroid.OpenIdUtils import at.bitfire.davdroid.db.AppDatabase import at.bitfire.davdroid.db.Credentials import at.bitfire.davdroid.log.Logger Loading Loading @@ -71,15 +72,18 @@ class ContactsSyncAdapterService: SyncAdapterService() { if (authState != null) { if (authState.needsTokenRefresh) { val tokenRequest = authState.createTokenRefreshRequest() val clientSecretString = accountSettings.credentials().clientSecret val clientSecret = OpenIdUtils.getClientAuthentication(clientSecretString) AuthorizationService(context).performTokenRequest(tokenRequest) { tokenResponse, ex -> AuthorizationService(context).performTokenRequest(tokenRequest, clientSecret) { tokenResponse, ex -> authState.update(tokenResponse, ex) accountSettings.credentials( Credentials( account.name, null, authState, null null, clientSecret = clientSecretString ) ) it.accountSettings.credentials( Loading @@ -87,7 +91,8 @@ class ContactsSyncAdapterService: SyncAdapterService() { it.account.name, null, authState, null null, clientSecret = clientSecretString ) ) object : AsyncTask<Void, Void, Void>() { Loading