From a0c19863fab280cb16359bf72a26a16a82428b11 Mon Sep 17 00:00:00 2001 From: Fahim Salam Chowdhury Date: Tue, 2 Apr 2024 19:58:50 +0600 Subject: [PATCH 1/7] chore: bump nextcloud-android-library version update nc-android-lib version to support OIDC authentication. nc-android-lib now depends on android-AppAuth lib to support OIDC auth. This dependency requires `appAuthRedirectScheme` manifestPlaceHolder to be passed to build (P.S: this is for placeholder, eDrive won't use any operation requireing this value). --- app/build.gradle | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/build.gradle b/app/build.gradle index 224935d9..b11d9dcd 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -45,6 +45,10 @@ android { versionName "${versionMajor}.${versionMinor}.${versionPatch}" setProperty("archivesBaseName", "eDrive-$versionName") testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + + manifestPlaceholders = [ + 'appAuthRedirectScheme': applicationId, + ] } signingConfigs { @@ -94,7 +98,7 @@ android { } dependencies { - implementation 'foundation.e:Nextcloud-Android-Library:1.0.6-release' + implementation 'foundation.e:Nextcloud-Android-Library:1.0.7-alpha08' implementation "commons-httpclient:commons-httpclient:3.1@jar" implementation fileTree(include: ['*.jar'], dir: 'libs') api 'androidx.annotation:annotation:1.6.0' -- GitLab From db24985b16f87e69ea12e2a0bb99af17c3ab8808 Mon Sep 17 00:00:00 2001 From: Fahim Salam Chowdhury Date: Tue, 2 Apr 2024 20:02:43 +0600 Subject: [PATCH 2/7] fix: Pass authToken in shopUrl if present As previously OIDC support was missing, the shopURL always passed `placeholder` as token. So user has to always relogin to shop to access. Now, if the OIDC token for account is present, that will be passed instead. --- .../e/drive/activity/AccountsActivity.java | 4 +- .../foundation/e/drive/utils/ShopUtils.kt | 49 +++++++++++++++++++ .../e/drive/widgets/EDriveWidget.java | 6 ++- 3 files changed, 56 insertions(+), 3 deletions(-) create mode 100644 app/src/main/java/foundation/e/drive/utils/ShopUtils.kt diff --git a/app/src/main/java/foundation/e/drive/activity/AccountsActivity.java b/app/src/main/java/foundation/e/drive/activity/AccountsActivity.java index 641b3c47..87a2fac3 100644 --- a/app/src/main/java/foundation/e/drive/activity/AccountsActivity.java +++ b/app/src/main/java/foundation/e/drive/activity/AccountsActivity.java @@ -37,6 +37,7 @@ import foundation.e.drive.databinding.ActivityAccountsBinding; import foundation.e.drive.utils.AccountUtils; import foundation.e.drive.utils.CommonUtils; import foundation.e.drive.utils.DavClientProvider; +import foundation.e.drive.utils.ShopUtils; import foundation.e.drive.widgets.EDriveWidget; import timber.log.Timber; @@ -78,6 +79,7 @@ public class AccountsActivity extends AppCompatActivity { final String totalQuota = accountManager.getUserData(account, ACCOUNT_DATA_TOTAL_QUOTA_KEY); final String email = accountManager.getUserData(account, ACCOUNT_DATA_EMAIL); String name = accountManager.getUserData(account, ACCOUNT_DATA_NAME); + final String token =ShopUtils.getAccessToken(accountManager, account); // For some reason if we cant get name use email as name if (name == null || name.isEmpty()) { @@ -139,7 +141,7 @@ public class AccountsActivity extends AppCompatActivity { binding.upgrade.setVisibility(View.VISIBLE); binding.upgrade.setOnClickListener(v -> { final Intent upgradeIntent = buildIntent(Intent.ACTION_VIEW, - String.format(EDriveWidget.WEBPAGE, email, + String.format(EDriveWidget.WEBPAGE, email, token, dataForWeb(totalQuota))); startActivity(upgradeIntent); }); diff --git a/app/src/main/java/foundation/e/drive/utils/ShopUtils.kt b/app/src/main/java/foundation/e/drive/utils/ShopUtils.kt new file mode 100644 index 00000000..b750ee48 --- /dev/null +++ b/app/src/main/java/foundation/e/drive/utils/ShopUtils.kt @@ -0,0 +1,49 @@ +/* + * Copyright MURENA SAS 2024 + * 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 . + */ + +package foundation.e.drive.utils + +import android.accounts.Account +import android.accounts.AccountManager +import com.owncloud.android.lib.common.accounts.AccountUtils +import net.openid.appauth.AuthState +import org.json.JSONException +import timber.log.Timber + +object ShopUtils { + + private const val PLACEHOLDER_TOKEN = "placeholder" + + @JvmStatic + fun getAccessToken(accountManager: AccountManager, account: Account?): String { + if (account == null) { + return PLACEHOLDER_TOKEN + } + + val authState = accountManager.getUserData(account, AccountUtils.Constants.KEY_AUTH_STATE) + if (authState.isNullOrBlank()) { + return PLACEHOLDER_TOKEN + } + + try { + return AuthState.jsonDeserialize(authState).accessToken ?: PLACEHOLDER_TOKEN + } catch (e: JSONException) { + Timber.e(e) + } + + return PLACEHOLDER_TOKEN + } +} diff --git a/app/src/main/java/foundation/e/drive/widgets/EDriveWidget.java b/app/src/main/java/foundation/e/drive/widgets/EDriveWidget.java index 8c01a51e..2c156316 100644 --- a/app/src/main/java/foundation/e/drive/widgets/EDriveWidget.java +++ b/app/src/main/java/foundation/e/drive/widgets/EDriveWidget.java @@ -42,6 +42,7 @@ import foundation.e.drive.R; import foundation.e.drive.utils.AccountUtils; import foundation.e.drive.utils.AppConstants; import foundation.e.drive.utils.CommonUtils; +import foundation.e.drive.utils.ShopUtils; import timber.log.Timber; /** @@ -51,7 +52,7 @@ import timber.log.Timber; public class EDriveWidget extends AppWidgetProvider { public static final String WEBPAGE = - "https://murena.com/ecloud-subscriptions/?username=%s&token=placeholder¤t-quota=%s&from=wp"; + "https://murena.com/ecloud-subscriptions/?username=%s&token=%s¤t-quota=%s&from=wp"; private static final String ADD_ACCOUNT_WEBPAGE = "https://murena.io/signup/e-email-invite"; private static final String ACCOUNT_PROVIDER_EELO = "e.foundation.webdav.eelo"; @@ -211,6 +212,7 @@ public class EDriveWidget extends AppWidgetProvider { final String totalQuota = accountManager.getUserData(account, ACCOUNT_DATA_TOTAL_QUOTA_KEY); final String email = accountManager.getUserData(account, ACCOUNT_DATA_EMAIL); String name = accountManager.getUserData(account, ACCOUNT_DATA_NAME); + final String token = ShopUtils.getAccessToken(accountManager, account); if (email == null || email.trim().isEmpty()) { noAccountView(context); @@ -297,7 +299,7 @@ public class EDriveWidget extends AppWidgetProvider { views.setOnClickPendingIntent(R.id.settings, pendingIntentSettings); final PendingIntent pendingIntentUpgrade = PendingIntent.getActivity(context, 0, - buildIntent(Intent.ACTION_VIEW, String.format(WEBPAGE, email, + buildIntent(Intent.ACTION_VIEW, String.format(WEBPAGE, email, token, dataForWeb(totalQuota))), PendingIntent.FLAG_IMMUTABLE); views.setOnClickPendingIntent(R.id.upgrade, pendingIntentUpgrade); } -- GitLab From 56108f17f3f1f741ef58cb3fb08042d448e4b937 Mon Sep 17 00:00:00 2001 From: Fahim Salam Chowdhury Date: Tue, 2 Apr 2024 21:45:09 +0600 Subject: [PATCH 3/7] chore: update to satify detekt --- .../foundation/e/drive/utils/ShopUtils.kt | 25 +++++++++++-------- build.gradle | 2 +- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/foundation/e/drive/utils/ShopUtils.kt b/app/src/main/java/foundation/e/drive/utils/ShopUtils.kt index b750ee48..edaf61eb 100644 --- a/app/src/main/java/foundation/e/drive/utils/ShopUtils.kt +++ b/app/src/main/java/foundation/e/drive/utils/ShopUtils.kt @@ -29,21 +29,24 @@ object ShopUtils { @JvmStatic fun getAccessToken(accountManager: AccountManager, account: Account?): String { - if (account == null) { - return PLACEHOLDER_TOKEN + getAuthState(accountManager, account)?.let { authState -> + try { + return AuthState.jsonDeserialize(authState).accessToken ?: PLACEHOLDER_TOKEN + } catch (e: JSONException) { + Timber.e(e) + } } - val authState = accountManager.getUserData(account, AccountUtils.Constants.KEY_AUTH_STATE) - if (authState.isNullOrBlank()) { - return PLACEHOLDER_TOKEN - } + return PLACEHOLDER_TOKEN + } - try { - return AuthState.jsonDeserialize(authState).accessToken ?: PLACEHOLDER_TOKEN - } catch (e: JSONException) { - Timber.e(e) + private fun getAuthState(accountManager: AccountManager, account: Account?): String? { + var authState: String? = null + + if (account != null) { + authState = accountManager.getUserData(account, AccountUtils.Constants.KEY_AUTH_STATE) } - return PLACEHOLDER_TOKEN + return if (authState.isNullOrBlank()) null else authState } } diff --git a/build.gradle b/build.gradle index 766ad4a8..45313851 100644 --- a/build.gradle +++ b/build.gradle @@ -2,7 +2,7 @@ plugins { id 'com.android.application' version '7.1.3' apply false id 'com.android.library' version '7.1.3' apply false - id 'org.jetbrains.kotlin.android' version '1.8.20-RC' apply false + id 'org.jetbrains.kotlin.android' version '1.8.22' apply false id 'io.gitlab.arturbosch.detekt' version '1.23.1' } -- GitLab From 20692ec8b4601f975289d92c66230fad566fab3e Mon Sep 17 00:00:00 2001 From: Fahim Salam Chowdhury Date: Tue, 2 Apr 2024 21:57:13 +0600 Subject: [PATCH 4/7] chore: fix failing test --- app/src/test/java/foundation/e/drive/TestUtils.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/src/test/java/foundation/e/drive/TestUtils.java b/app/src/test/java/foundation/e/drive/TestUtils.java index 3ff562f9..08a9bb5d 100644 --- a/app/src/test/java/foundation/e/drive/TestUtils.java +++ b/app/src/test/java/foundation/e/drive/TestUtils.java @@ -30,6 +30,8 @@ import androidx.work.Configuration; import androidx.work.testing.SynchronousExecutor; import androidx.work.testing.WorkManagerTestInitHelper; +import okhttp3.CookieJar; + public abstract class TestUtils { public static final String TEST_LOCAL_ROOT_FOLDER_PATH = "/tmp/eDrive/test/"; //THis is where test file and folder for synchronisatio will be stored public static final String TEST_REMOTE_ROOT_FOLDER_PATH ="/eDrive-test/"; @@ -64,7 +66,7 @@ public abstract class TestUtils { public static NextcloudClient getNcClient(Context context) { final Uri serverUri = Uri.parse(TEST_SERVER_URI); - return new NextcloudClient(serverUri, TEST_ACCOUNT_NAME, TEST_ACCOUNT_PASSWORD, context); + return new NextcloudClient(serverUri, TEST_ACCOUNT_NAME, TEST_ACCOUNT_PASSWORD, context, CookieJar.NO_COOKIES); } /** -- GitLab From 5488ac766c3ebf4d6f6642f2a2cf31554d20862c Mon Sep 17 00:00:00 2001 From: Fahim Salam Chowdhury Date: Wed, 3 Apr 2024 14:46:15 +0600 Subject: [PATCH 5/7] chore: update according to review --- .../java/foundation/e/drive/activity/AccountsActivity.java | 4 ++-- .../e/drive/utils/{ShopUtils.kt => AccessTokenProvider.kt} | 2 +- .../main/java/foundation/e/drive/widgets/EDriveWidget.java | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) rename app/src/main/java/foundation/e/drive/utils/{ShopUtils.kt => AccessTokenProvider.kt} (98%) diff --git a/app/src/main/java/foundation/e/drive/activity/AccountsActivity.java b/app/src/main/java/foundation/e/drive/activity/AccountsActivity.java index 87a2fac3..b61d0885 100644 --- a/app/src/main/java/foundation/e/drive/activity/AccountsActivity.java +++ b/app/src/main/java/foundation/e/drive/activity/AccountsActivity.java @@ -37,7 +37,7 @@ import foundation.e.drive.databinding.ActivityAccountsBinding; import foundation.e.drive.utils.AccountUtils; import foundation.e.drive.utils.CommonUtils; import foundation.e.drive.utils.DavClientProvider; -import foundation.e.drive.utils.ShopUtils; +import foundation.e.drive.utils.AccessTokenProvider; import foundation.e.drive.widgets.EDriveWidget; import timber.log.Timber; @@ -79,7 +79,7 @@ public class AccountsActivity extends AppCompatActivity { final String totalQuota = accountManager.getUserData(account, ACCOUNT_DATA_TOTAL_QUOTA_KEY); final String email = accountManager.getUserData(account, ACCOUNT_DATA_EMAIL); String name = accountManager.getUserData(account, ACCOUNT_DATA_NAME); - final String token =ShopUtils.getAccessToken(accountManager, account); + final String token = AccessTokenProvider.getAccessToken(accountManager, account); // For some reason if we cant get name use email as name if (name == null || name.isEmpty()) { diff --git a/app/src/main/java/foundation/e/drive/utils/ShopUtils.kt b/app/src/main/java/foundation/e/drive/utils/AccessTokenProvider.kt similarity index 98% rename from app/src/main/java/foundation/e/drive/utils/ShopUtils.kt rename to app/src/main/java/foundation/e/drive/utils/AccessTokenProvider.kt index edaf61eb..17367911 100644 --- a/app/src/main/java/foundation/e/drive/utils/ShopUtils.kt +++ b/app/src/main/java/foundation/e/drive/utils/AccessTokenProvider.kt @@ -23,7 +23,7 @@ import net.openid.appauth.AuthState import org.json.JSONException import timber.log.Timber -object ShopUtils { +object AccessTokenProvider { private const val PLACEHOLDER_TOKEN = "placeholder" diff --git a/app/src/main/java/foundation/e/drive/widgets/EDriveWidget.java b/app/src/main/java/foundation/e/drive/widgets/EDriveWidget.java index 2c156316..d5692dbe 100644 --- a/app/src/main/java/foundation/e/drive/widgets/EDriveWidget.java +++ b/app/src/main/java/foundation/e/drive/widgets/EDriveWidget.java @@ -42,7 +42,7 @@ import foundation.e.drive.R; import foundation.e.drive.utils.AccountUtils; import foundation.e.drive.utils.AppConstants; import foundation.e.drive.utils.CommonUtils; -import foundation.e.drive.utils.ShopUtils; +import foundation.e.drive.utils.AccessTokenProvider; import timber.log.Timber; /** @@ -212,7 +212,7 @@ public class EDriveWidget extends AppWidgetProvider { final String totalQuota = accountManager.getUserData(account, ACCOUNT_DATA_TOTAL_QUOTA_KEY); final String email = accountManager.getUserData(account, ACCOUNT_DATA_EMAIL); String name = accountManager.getUserData(account, ACCOUNT_DATA_NAME); - final String token = ShopUtils.getAccessToken(accountManager, account); + final String token = AccessTokenProvider.getAccessToken(accountManager, account); if (email == null || email.trim().isEmpty()) { noAccountView(context); -- GitLab From a778cd520b4fbdd30b94a3272c57bc1c8f1f8c1b Mon Sep 17 00:00:00 2001 From: Fahim Salam Chowdhury Date: Wed, 3 Apr 2024 15:12:30 +0600 Subject: [PATCH 6/7] chore: update according to review --- .../main/java/foundation/e/drive/activity/AccountsActivity.java | 2 +- .../main/java/foundation/e/drive/utils/AccessTokenProvider.kt | 2 +- app/src/main/java/foundation/e/drive/widgets/EDriveWidget.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/foundation/e/drive/activity/AccountsActivity.java b/app/src/main/java/foundation/e/drive/activity/AccountsActivity.java index b61d0885..b4e0ad42 100644 --- a/app/src/main/java/foundation/e/drive/activity/AccountsActivity.java +++ b/app/src/main/java/foundation/e/drive/activity/AccountsActivity.java @@ -79,7 +79,7 @@ public class AccountsActivity extends AppCompatActivity { final String totalQuota = accountManager.getUserData(account, ACCOUNT_DATA_TOTAL_QUOTA_KEY); final String email = accountManager.getUserData(account, ACCOUNT_DATA_EMAIL); String name = accountManager.getUserData(account, ACCOUNT_DATA_NAME); - final String token = AccessTokenProvider.getAccessToken(accountManager, account); + final String token = AccessTokenProvider.getToken(accountManager, account); // For some reason if we cant get name use email as name if (name == null || name.isEmpty()) { diff --git a/app/src/main/java/foundation/e/drive/utils/AccessTokenProvider.kt b/app/src/main/java/foundation/e/drive/utils/AccessTokenProvider.kt index 17367911..eecb67e4 100644 --- a/app/src/main/java/foundation/e/drive/utils/AccessTokenProvider.kt +++ b/app/src/main/java/foundation/e/drive/utils/AccessTokenProvider.kt @@ -28,7 +28,7 @@ object AccessTokenProvider { private const val PLACEHOLDER_TOKEN = "placeholder" @JvmStatic - fun getAccessToken(accountManager: AccountManager, account: Account?): String { + fun getToken(accountManager: AccountManager, account: Account?): String { getAuthState(accountManager, account)?.let { authState -> try { return AuthState.jsonDeserialize(authState).accessToken ?: PLACEHOLDER_TOKEN diff --git a/app/src/main/java/foundation/e/drive/widgets/EDriveWidget.java b/app/src/main/java/foundation/e/drive/widgets/EDriveWidget.java index d5692dbe..a839ee11 100644 --- a/app/src/main/java/foundation/e/drive/widgets/EDriveWidget.java +++ b/app/src/main/java/foundation/e/drive/widgets/EDriveWidget.java @@ -212,7 +212,7 @@ public class EDriveWidget extends AppWidgetProvider { final String totalQuota = accountManager.getUserData(account, ACCOUNT_DATA_TOTAL_QUOTA_KEY); final String email = accountManager.getUserData(account, ACCOUNT_DATA_EMAIL); String name = accountManager.getUserData(account, ACCOUNT_DATA_NAME); - final String token = AccessTokenProvider.getAccessToken(accountManager, account); + final String token = AccessTokenProvider.getToken(accountManager, account); if (email == null || email.trim().isEmpty()) { noAccountView(context); -- GitLab From c834af629acd5d7c77c484a62ec88f0e16449f99 Mon Sep 17 00:00:00 2001 From: Fahim Salam Chowdhury Date: Thu, 4 Apr 2024 21:45:30 +0600 Subject: [PATCH 7/7] chore: bump nc-android-lib version to 1.0.7-u2.17-release --- app/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/build.gradle b/app/build.gradle index b11d9dcd..df6b5d3f 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -98,7 +98,7 @@ android { } dependencies { - implementation 'foundation.e:Nextcloud-Android-Library:1.0.7-alpha08' + implementation 'foundation.e:Nextcloud-Android-Library:1.0.7-u2.17-release' implementation "commons-httpclient:commons-httpclient:3.1@jar" implementation fileTree(include: ['*.jar'], dir: 'libs') api 'androidx.annotation:annotation:1.6.0' -- GitLab