From 3be96cf035c47e190278115ff489d36af535859a Mon Sep 17 00:00:00 2001 From: SkyfaceD Date: Tue, 17 May 2022 15:40:34 +0600 Subject: [PATCH] Hide shikimori sensitive information --- app/build.gradle | 3 +++ .../kotatsu/shikimori/data/ShikimoriRepository.kt | 9 ++++----- build.gradle | 9 +++++++++ 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index ddd401a15..aa3e958a6 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -24,6 +24,9 @@ android { arg 'room.schemaLocation', "$projectDir/schemas".toString() } } + + buildConfigField 'String', 'SHIKIMORI_CLIENT_ID', localProperty('shikimori.clientId') + buildConfigField 'String', 'SHIKIMORI_CLIENT_SECRET', localProperty('shikimori.clientSecret') } buildTypes { debug { diff --git a/app/src/main/java/org/koitharu/kotatsu/shikimori/data/ShikimoriRepository.kt b/app/src/main/java/org/koitharu/kotatsu/shikimori/data/ShikimoriRepository.kt index 2cfca1505..e8dfae344 100644 --- a/app/src/main/java/org/koitharu/kotatsu/shikimori/data/ShikimoriRepository.kt +++ b/app/src/main/java/org/koitharu/kotatsu/shikimori/data/ShikimoriRepository.kt @@ -4,6 +4,7 @@ import okhttp3.FormBody import okhttp3.HttpUrl.Companion.toHttpUrl import okhttp3.OkHttpClient import okhttp3.Request +import org.koitharu.kotatsu.BuildConfig import org.koitharu.kotatsu.parsers.model.Manga import org.koitharu.kotatsu.parsers.util.await import org.koitharu.kotatsu.parsers.util.json.mapJSON @@ -14,8 +15,6 @@ import org.koitharu.kotatsu.shikimori.data.model.ShikimoriManga import org.koitharu.kotatsu.shikimori.data.model.ShikimoriMangaInfo import org.koitharu.kotatsu.shikimori.data.model.ShikimoriUser -private const val CLIENT_ID = "Mw6F0tPEOgyV7F9U9Twg50Q8SndMY7hzIOfXg0AX_XU" -private const val CLIENT_SECRET = "euBMt1GGRSDpVIFQVPxZrO7Kh6X4gWyv0dABuj4B-M8" private const val REDIRECT_URI = "kotatsu://shikimori-auth" private const val BASE_URL = "https://shikimori.one/api/" private const val MANGA_PAGE_SIZE = 10 @@ -26,7 +25,7 @@ class ShikimoriRepository( ) { val oauthUrl: String - get() = "https://shikimori.one/oauth/authorize?client_id=$CLIENT_ID&" + + get() = "https://shikimori.one/oauth/authorize?client_id=${BuildConfig.SHIKIMORI_CLIENT_ID}&" + "redirect_uri=$REDIRECT_URI&response_type=code&scope=" val isAuthorized: Boolean @@ -35,8 +34,8 @@ class ShikimoriRepository( suspend fun authorize(code: String?) { val body = FormBody.Builder() body.add("grant_type", "authorization_code") - body.add("client_id", CLIENT_ID) - body.add("client_secret", CLIENT_SECRET) + body.add("client_id", BuildConfig.SHIKIMORI_CLIENT_ID) + body.add("client_secret", BuildConfig.SHIKIMORI_CLIENT_SECRET) if (code != null) { body.add("redirect_uri", REDIRECT_URI) body.add("code", code) diff --git a/build.gradle b/build.gradle index 390d5748a..be41a3021 100644 --- a/build.gradle +++ b/build.gradle @@ -23,6 +23,15 @@ allprojects { } } +Object localProperty(String name, Object defaultValue = 'null') { + Properties localProperties = new Properties() + project.rootProject.file('local.properties').withInputStream { localProperties.load(it) } + + def value = localProperties[name] + + return value != null ? value : defaultValue +} + task clean(type: Delete) { delete rootProject.buildDir } \ No newline at end of file