Skip to content

Commit

Permalink
v0.1.3 - Expose ClientCredentials
Browse files Browse the repository at this point in the history
  • Loading branch information
warriorzz committed Oct 21, 2024
1 parent 78124af commit 8d67985
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ plugins {
}

group = "ee.bjarn"
version = "0.1.2"
version = "0.1.3"

repositories {
mavenCentral()
Expand Down
16 changes: 16 additions & 0 deletions src/main/kotlin/ee/bjarn/ktify/Ktify.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package ee.bjarn.ktify
import ee.bjarn.ktify.model.auth.ClientCredentials
import ee.bjarn.ktify.model.auth.ClientCredentialsResponse
import ee.bjarn.ktify.model.auth.Scope
import ee.bjarn.ktify.model.auth.refresh
import ee.bjarn.ktify.player.KtifyPlayer
import ee.bjarn.ktify.utils.AuthenticationErrorObject
import ee.bjarn.ktify.utils.AuthenticationException
Expand Down Expand Up @@ -84,6 +85,12 @@ class Ktify(
* Will be internal once the entire API is covered
*/
val jsonLessHttpClient = HttpClient(httpClient.engine)

/**
* Retrieve client credentials from the current [Ktify] instance
* @return The [ClientCredentials] object
*/
fun getClientCredentials() = clientCredentials
}

/**
Expand All @@ -109,6 +116,15 @@ class KtifyBuilder(
return "$baseUrl?client_id=$clientId&scope=${URLEncoder.encode(scopesString, "UTF-8")}&redirect_uri=${URLEncoder.encode(redirectUri, "UTF-8")}&state=$state&response_type=code"
}

/**
* @param clientCredentials Client credentials that were previously acquired
* @return The [Ktify] instance
*/
suspend fun fromClientCredentials(clientCredentials: ClientCredentials): Ktify {
clientCredentials.refresh()
return Ktify(clientCredentials)
}

/**
* @param authorizationCode returned by the request to the user
* @return The [Ktify] instance
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import io.ktor.util.*
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Serializable
data class ClientCredentials(
val clientId: String,
val clientSecret: String,
Expand Down

0 comments on commit 8d67985

Please sign in to comment.