diff --git a/.gitignore b/.gitignore index 5058fb6..e264418 100644 --- a/.gitignore +++ b/.gitignore @@ -40,3 +40,4 @@ DerivedData/ !*.xcodeproj/xcshareddata/ !*.xcworkspace/contents.xcworkspacedata **/xcshareddata/WorkspaceSettings.xcsettings +kotlin-js-store/ \ No newline at end of file diff --git a/settings.gradle.kts b/settings.gradle.kts index a297655..ede34db 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -18,12 +18,12 @@ dependencyResolutionManagement { create("libs") { version("android-tools-gradle", "7.2.0") version("kotlin", "1.7.10") - version("ktor", "2.0.3") + version("ktor", "2.1.1") library("ktor-client-core", "io.ktor", "ktor-client-core").versionRef("ktor") library("ktor-client-android", "io.ktor", "ktor-client-android").versionRef("ktor") library("ktor-client-darwin", "io.ktor", "ktor-client-darwin").versionRef("ktor") - library("ktor-client-jvm", "io.ktor", "ktor-client-cio").versionRef("ktor") + library("ktor-client-jvm", "io.ktor", "ktor-client-java").versionRef("ktor") library("ktor-client-js", "io.ktor", "ktor-client-js").versionRef("ktor") library("kotlinx-coroutines", "org.jetbrains.kotlinx", "kotlinx-coroutines-core").version("1.6.1") library("kotlinx-serialization", "org.jetbrains.kotlinx", "kotlinx-serialization-json").version("1.3.3") @@ -38,4 +38,4 @@ dependencyResolutionManagement { plugin("kotlin.serialization", "org.jetbrains.kotlin.plugin.serialization").versionRef("kotlin") } } -} \ No newline at end of file +} diff --git a/src/androidMain/kotlin/com/liftric/cognito/idp/core/Engine.kt b/src/androidMain/kotlin/com/liftric/cognito/idp/core/Engine.kt new file mode 100644 index 0000000..416677c --- /dev/null +++ b/src/androidMain/kotlin/com/liftric/cognito/idp/core/Engine.kt @@ -0,0 +1,6 @@ +package com.liftric.cognito.idp.core + +import io.ktor.client.engine.HttpClientEngine +import io.ktor.client.engine.android.Android + +internal actual val Engine: HttpClientEngine = Android.create() diff --git a/src/commonMain/kotlin/com/liftric/cognito/idp/IdentityProviderClient.kt b/src/commonMain/kotlin/com/liftric/cognito/idp/IdentityProviderClient.kt index 6f8ecf7..a24b549 100644 --- a/src/commonMain/kotlin/com/liftric/cognito/idp/IdentityProviderClient.kt +++ b/src/commonMain/kotlin/com/liftric/cognito/idp/IdentityProviderClient.kt @@ -3,6 +3,7 @@ package com.liftric.cognito.idp import com.liftric.cognito.idp.core.* import io.ktor.client.* import io.ktor.client.call.* +import io.ktor.client.engine.* import io.ktor.client.plugins.* import io.ktor.client.request.* import io.ktor.client.statement.* @@ -18,14 +19,14 @@ import kotlinx.serialization.json.Json * AWS Cognito Identity Provider client. * Provides common request methods. */ -open class IdentityProviderClient(region: String, clientId: String) : IdentityProvider { +open class IdentityProviderClient(region: String, clientId: String, engine: HttpClientEngine? = null) : IdentityProvider { private val json = Json { allowStructuredMapKeys = true ignoreUnknownKeys = true explicitNulls = false } private val configuration = Configuration(region, clientId) - private val client = HttpClient { + private val client = HttpClient(engine ?: Engine) { expectSuccess = true /** * When referencing members that are in the @@ -41,6 +42,8 @@ open class IdentityProviderClient(region: String, clientId: String) : IdentityPr } } + constructor(region: String, clientId: String) : this(region, clientId, null) + override suspend fun signUp( username: String, password: String, diff --git a/src/commonMain/kotlin/com/liftric/cognito/idp/core/Engine.kt b/src/commonMain/kotlin/com/liftric/cognito/idp/core/Engine.kt new file mode 100644 index 0000000..d697189 --- /dev/null +++ b/src/commonMain/kotlin/com/liftric/cognito/idp/core/Engine.kt @@ -0,0 +1,5 @@ +package com.liftric.cognito.idp.core + +import io.ktor.client.engine.HttpClientEngine + +internal expect val Engine: HttpClientEngine diff --git a/src/iosMain/kotlin/com/liftric/cognito/idp/core/Engine.kt b/src/iosMain/kotlin/com/liftric/cognito/idp/core/Engine.kt new file mode 100644 index 0000000..732576a --- /dev/null +++ b/src/iosMain/kotlin/com/liftric/cognito/idp/core/Engine.kt @@ -0,0 +1,7 @@ +package com.liftric.cognito.idp.core + +import io.ktor.client.engine.HttpClientEngine +import io.ktor.client.engine.darwin.Darwin + +internal actual val Engine: HttpClientEngine = Darwin.create() + diff --git a/src/jsMain/kotlin/IdentityProviderJS.kt b/src/jsMain/kotlin/IdentityProviderJS.kt index 7fc2018..a6faf13 100644 --- a/src/jsMain/kotlin/IdentityProviderJS.kt +++ b/src/jsMain/kotlin/IdentityProviderJS.kt @@ -2,6 +2,7 @@ import com.liftric.cognito.idp.IdentityProviderClient import com.liftric.cognito.idp.core.* +import io.ktor.client.engine.js.* import kotlinx.coroutines.MainScope import kotlinx.coroutines.promise import kotlin.js.Promise diff --git a/src/jsMain/kotlin/com/liftric/cognito/idp/core/Engine.kt b/src/jsMain/kotlin/com/liftric/cognito/idp/core/Engine.kt new file mode 100644 index 0000000..6f70a30 --- /dev/null +++ b/src/jsMain/kotlin/com/liftric/cognito/idp/core/Engine.kt @@ -0,0 +1,7 @@ +package com.liftric.cognito.idp.core + +import io.ktor.client.engine.HttpClientEngine +import io.ktor.client.engine.js.Js + +internal actual val Engine: HttpClientEngine = Js.create() + diff --git a/src/jvmMain/kotlin/com/liftric/cognito/idp/core/Engine.kt b/src/jvmMain/kotlin/com/liftric/cognito/idp/core/Engine.kt new file mode 100644 index 0000000..77288f3 --- /dev/null +++ b/src/jvmMain/kotlin/com/liftric/cognito/idp/core/Engine.kt @@ -0,0 +1,6 @@ +package com.liftric.cognito.idp.core + +import io.ktor.client.engine.HttpClientEngine +import io.ktor.client.engine.java.Java + +internal actual val Engine: HttpClientEngine = Java.create()