From d5f340c0104ef7d9b89295c85d6d1f2e8e1868f9 Mon Sep 17 00:00:00 2001 From: Bjarne Eberhardt <63170816+warriorzz@users.noreply.github.com> Date: Wed, 8 May 2024 14:47:06 +1200 Subject: [PATCH] Hotfix KtifyBuilder URL generation (#7) * Hotfix KtifyBuilder URL generation * Edit version in README --- README.md | 2 +- build.gradle.kts | 2 +- src/main/kotlin/ee/bjarn/ktify/Ktify.kt | 5 +++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 833d640..011a3f4 100755 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ repositories { mavenCentral() } dependencies { - implementation("ee.bjarn", "ktify", "0.1.1") + implementation("ee.bjarn", "ktify", "0.1.1-hotfix") } ``` diff --git a/build.gradle.kts b/build.gradle.kts index c79e1dd..9e03a98 100755 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -12,7 +12,7 @@ plugins { } group = "ee.bjarn" -version = "0.1.1" +version = "0.1.1-hotfix" repositories { mavenCentral() diff --git a/src/main/kotlin/ee/bjarn/ktify/Ktify.kt b/src/main/kotlin/ee/bjarn/ktify/Ktify.kt index c02d31f..91696a2 100755 --- a/src/main/kotlin/ee/bjarn/ktify/Ktify.kt +++ b/src/main/kotlin/ee/bjarn/ktify/Ktify.kt @@ -21,6 +21,7 @@ import io.ktor.serialization.kotlinx.json.* import io.ktor.util.* import kotlinx.serialization.json.JsonObject import mu.KotlinLogging +import java.net.URLEncoder import java.util.UUID /** @@ -103,8 +104,8 @@ class KtifyBuilder( */ fun getAuthorisationURL(scopes: List): String { val baseUrl = "https://accounts.spotify.com/authorize" - val scopesString = if (scopes.size > 0) scopes.map { it.value + "%20" }.reduce { acc, s -> acc + s }.dropLast(3) else "none" - return "$baseUrl?client_id=&scope=$scopesString&redirect_uri=$redirectUri&state=$state&response_type=code" + val scopesString = if (scopes.size > 0) scopes.map { it.value + " " }.reduce { acc, s -> acc + s }.dropLast(1) else "none" + return "$baseUrl?client_id=$clientId&scope=${URLEncoder.encode(scopesString, "UTF-8")}&redirect_uri=${URLEncoder.encode(redirectUri, "UTF-8")}&state=$state&response_type=code" } /**