diff --git a/.gitignore b/.gitignore index 9fd27739..1e9c8ec6 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,12 @@ build **/.DS_Store *.hprof local.properties -.kotlin \ No newline at end of file +.kotlin + +xcuserdata +*.xcodeproj/* +!*.xcodeproj/project.pbxproj +!*.xcodeproj/xcshareddata/ +!*.xcodeproj/project.xcworkspace/ +!*.xcworkspace/contents.xcworkspacedata +**/xcshareddata/WorkspaceSettings.xcsettings \ No newline at end of file diff --git a/build-logic/convention/src/main/kotlin/org/publicvalue/convention/config/Multiplatform.kt b/build-logic/convention/src/main/kotlin/org/publicvalue/convention/config/Multiplatform.kt index 2cfa3fa3..1a2a19b9 100644 --- a/build-logic/convention/src/main/kotlin/org/publicvalue/convention/config/Multiplatform.kt +++ b/build-logic/convention/src/main/kotlin/org/publicvalue/convention/config/Multiplatform.kt @@ -22,7 +22,7 @@ fun KotlinMultiplatformExtension.configureAndroidTarget() { @OptIn(ExperimentalWasmDsl::class) fun KotlinMultiplatformExtension.configureWasmTarget(baseName: String? = null) { wasmJs { - outputModuleName.set(baseName ?: project.path.substring(1).replace(":","-").replace("-","_")) + outputModuleName.set(baseName ?: project.path.substring(1).replace(":", "-").replace("-", "_")) browser { commonWebpackConfig { outputFileName = "$baseName.js" @@ -31,6 +31,7 @@ fun KotlinMultiplatformExtension.configureWasmTarget(baseName: String? = null) { // Serve sources to debug inside browser add(project.projectDir.path) add(project.projectDir.path + "/commonMain/") + add(project.projectDir.path + "/webMain/") add(project.projectDir.path + "/wasmJsMain/") } } @@ -39,6 +40,13 @@ fun KotlinMultiplatformExtension.configureWasmTarget(baseName: String? = null) { } } +fun KotlinMultiplatformExtension.configureJsTarget() { + js(IR) { + browser() + binaries.library() + } +} + fun KotlinMultiplatformExtension.configureIosTargets(baseName: String? = null) { listOf( iosX64(), diff --git a/oidc-appsupport/build.gradle.kts b/oidc-appsupport/build.gradle.kts index 990fd36b..8de56f5d 100644 --- a/oidc-appsupport/build.gradle.kts +++ b/oidc-appsupport/build.gradle.kts @@ -1,12 +1,9 @@ -import com.android.build.gradle.internal.tasks.factory.dependsOn import org.jetbrains.kotlin.gradle.plugin.mpp.Framework import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget import org.publicvalue.convention.config.configureIosTargets +import org.publicvalue.convention.config.configureJsTarget import org.publicvalue.convention.config.configureWasmTarget import org.publicvalue.convention.config.exportKdoc -import java.nio.file.Files -import java.util.stream.Collectors.toList -import kotlin.io.path.name plugins { id("org.publicvalue.convention.android.library") @@ -27,6 +24,7 @@ kotlin { jvm() configureIosTargets(baseName = "OpenIdConnectClient") configureWasmTarget(baseName = "OpenIdConnectClient") + configureJsTarget() sourceSets { val commonMain by getting { dependencies { @@ -58,7 +56,7 @@ kotlin { } } - val wasmJsMain by getting { + val webMain by getting { dependencies { implementation(libs.kotlinx.browser) } diff --git a/oidc-appsupport/src/wasmJsMain/kotlin/org/publicvalue/multiplatform/oidc/appsupport/PlatformCodeAuthFlow.wasmJs.kt b/oidc-appsupport/src/webMain/kotlin/org/publicvalue/multiplatform/oidc/appsupport/PlatformCodeAuthFlow.web.kt similarity index 96% rename from oidc-appsupport/src/wasmJsMain/kotlin/org/publicvalue/multiplatform/oidc/appsupport/PlatformCodeAuthFlow.wasmJs.kt rename to oidc-appsupport/src/webMain/kotlin/org/publicvalue/multiplatform/oidc/appsupport/PlatformCodeAuthFlow.web.kt index cba7acb8..59992870 100644 --- a/oidc-appsupport/src/wasmJsMain/kotlin/org/publicvalue/multiplatform/oidc/appsupport/PlatformCodeAuthFlow.wasmJs.kt +++ b/oidc-appsupport/src/webMain/kotlin/org/publicvalue/multiplatform/oidc/appsupport/PlatformCodeAuthFlow.web.kt @@ -4,7 +4,6 @@ import org.publicvalue.multiplatform.oidc.ExperimentalOpenIdConnect import org.publicvalue.multiplatform.oidc.OpenIdConnectClient import org.publicvalue.multiplatform.oidc.flows.CodeAuthFlow import org.publicvalue.multiplatform.oidc.flows.EndSessionFlow -import org.publicvalue.multiplatform.oidc.flows.EndSessionResponse import org.publicvalue.multiplatform.oidc.preferences.Preferences import org.publicvalue.multiplatform.oidc.types.AuthCodeRequest import org.publicvalue.multiplatform.oidc.types.EndSessionRequest diff --git a/oidc-appsupport/src/wasmJsMain/kotlin/org/publicvalue/multiplatform/oidc/appsupport/WasmCodeAuthFlowFactory.kt b/oidc-appsupport/src/webMain/kotlin/org/publicvalue/multiplatform/oidc/appsupport/WebCodeAuthFlowFactory.kt similarity index 89% rename from oidc-appsupport/src/wasmJsMain/kotlin/org/publicvalue/multiplatform/oidc/appsupport/WasmCodeAuthFlowFactory.kt rename to oidc-appsupport/src/webMain/kotlin/org/publicvalue/multiplatform/oidc/appsupport/WebCodeAuthFlowFactory.kt index 3713cfec..f71d4f03 100644 --- a/oidc-appsupport/src/wasmJsMain/kotlin/org/publicvalue/multiplatform/oidc/appsupport/WasmCodeAuthFlowFactory.kt +++ b/oidc-appsupport/src/webMain/kotlin/org/publicvalue/multiplatform/oidc/appsupport/WebCodeAuthFlowFactory.kt @@ -4,17 +4,16 @@ import kotlinx.browser.window import org.publicvalue.multiplatform.oidc.ExperimentalOpenIdConnect import org.publicvalue.multiplatform.oidc.OpenIdConnectClient import org.publicvalue.multiplatform.oidc.flows.EndSessionFlow -import org.publicvalue.multiplatform.oidc.preferences.PREFERENCES_FILENAME import org.publicvalue.multiplatform.oidc.preferences.PreferencesFactory @ExperimentalOpenIdConnect -class WasmCodeAuthFlowFactory( +class WebCodeAuthFlowFactory( private val windowTarget: String = "", private val windowFeatures: String = "width=1000,height=800,resizable=yes,scrollbars=yes", private val redirectOrigin: String = window.location.origin, /** factory used to create preferences to save session information during login process. **/ private val preferencesFactory: PreferencesFactory = PreferencesFactory() -): CodeAuthFlowFactory { +) : CodeAuthFlowFactory { override fun createAuthFlow(client: OpenIdConnectClient): PlatformCodeAuthFlow { val preferences = preferencesFactory.create() return PlatformCodeAuthFlow(windowTarget, windowFeatures, redirectOrigin, client, preferences) diff --git a/oidc-appsupport/src/wasmJsMain/kotlin/org/publicvalue/multiplatform/oidc/appsupport/WebPopupFlow.kt b/oidc-appsupport/src/webMain/kotlin/org/publicvalue/multiplatform/oidc/appsupport/WebPopupFlow.kt similarity index 95% rename from oidc-appsupport/src/wasmJsMain/kotlin/org/publicvalue/multiplatform/oidc/appsupport/WebPopupFlow.kt rename to oidc-appsupport/src/webMain/kotlin/org/publicvalue/multiplatform/oidc/appsupport/WebPopupFlow.kt index 2d99d87c..d5a00cec 100644 --- a/oidc-appsupport/src/wasmJsMain/kotlin/org/publicvalue/multiplatform/oidc/appsupport/WebPopupFlow.kt +++ b/oidc-appsupport/src/webMain/kotlin/org/publicvalue/multiplatform/oidc/appsupport/WebPopupFlow.kt @@ -1,3 +1,5 @@ +@file:OptIn(ExperimentalWasmJsInterop::class) + package org.publicvalue.multiplatform.oidc.appsupport import io.ktor.http.* @@ -12,6 +14,8 @@ import org.w3c.dom.Window import org.w3c.dom.events.Event import kotlin.coroutines.resume import kotlin.coroutines.suspendCoroutine +import kotlin.js.ExperimentalWasmJsInterop +import kotlin.js.js @ExperimentalOpenIdConnect internal class WebPopupFlow( @@ -19,7 +23,7 @@ internal class WebPopupFlow( private val windowFeatures: String = "width=1000,height=800,resizable=yes,scrollbars=yes", private val redirectOrigin: String, private val preferences: Preferences, -): WebAuthenticationFlow { +) : WebAuthenticationFlow { private class WindowHolder(var window: Window?) diff --git a/oidc-core/build.gradle.kts b/oidc-core/build.gradle.kts index a017da2e..9738c27a 100644 --- a/oidc-core/build.gradle.kts +++ b/oidc-core/build.gradle.kts @@ -1,4 +1,5 @@ import org.publicvalue.convention.config.configureIosTargets +import org.publicvalue.convention.config.configureJsTarget import org.publicvalue.convention.config.configureWasmTarget import org.publicvalue.convention.config.exportKdoc @@ -15,6 +16,7 @@ kotlin { jvm() configureIosTargets() configureWasmTarget() + configureJsTarget() sourceSets { commonMain { dependencies { diff --git a/oidc-crypto/build.gradle.kts b/oidc-crypto/build.gradle.kts index 2629ec67..f1cd40f9 100644 --- a/oidc-crypto/build.gradle.kts +++ b/oidc-crypto/build.gradle.kts @@ -1,5 +1,5 @@ -import org.gradle.nativeplatform.platform.internal.DefaultNativePlatform import org.publicvalue.convention.config.configureIosTargets +import org.publicvalue.convention.config.configureJsTarget import org.publicvalue.convention.config.configureWasmTarget import org.publicvalue.convention.config.exportKdoc @@ -16,6 +16,7 @@ kotlin { jvm() configureIosTargets() configureWasmTarget() + configureJsTarget() sourceSets { val commonMain by getting { dependencies { @@ -34,7 +35,7 @@ kotlin { } } - val wasmJsMain by getting { + val webMain by getting { dependencies { implementation(project.dependencies.platform(libs.kotlincrypto.hash.bom)) implementation(libs.kotlincrypto.hash.sha2) diff --git a/oidc-crypto/src/wasmJsMain/kotlin/org/publicvalue/multiplatform/oidc/Crypto.wasmJs.kt b/oidc-crypto/src/webMain/kotlin/org/publicvalue/multiplatform/oidc/Crypto.web.kt similarity index 100% rename from oidc-crypto/src/wasmJsMain/kotlin/org/publicvalue/multiplatform/oidc/Crypto.wasmJs.kt rename to oidc-crypto/src/webMain/kotlin/org/publicvalue/multiplatform/oidc/Crypto.web.kt diff --git a/oidc-ktor/build.gradle.kts b/oidc-ktor/build.gradle.kts index 97b3dfd6..4903ea15 100644 --- a/oidc-ktor/build.gradle.kts +++ b/oidc-ktor/build.gradle.kts @@ -1,4 +1,5 @@ import org.publicvalue.convention.config.configureIosTargets +import org.publicvalue.convention.config.configureJsTarget import org.publicvalue.convention.config.configureWasmTarget plugins { @@ -14,6 +15,7 @@ kotlin { jvm() configureIosTargets() configureWasmTarget() + configureJsTarget() sourceSets { val commonMain by getting { dependencies { diff --git a/oidc-preferences/build.gradle.kts b/oidc-preferences/build.gradle.kts index d081f3b1..140cebf1 100644 --- a/oidc-preferences/build.gradle.kts +++ b/oidc-preferences/build.gradle.kts @@ -1,4 +1,5 @@ import org.publicvalue.convention.config.configureIosTargets +import org.publicvalue.convention.config.configureJsTarget import org.publicvalue.convention.config.configureWasmTarget import org.publicvalue.convention.config.exportKdoc @@ -16,6 +17,7 @@ kotlin { jvm() configureIosTargets() configureWasmTarget() + configureJsTarget() sourceSets { commonMain { dependencies { @@ -26,23 +28,22 @@ kotlin { } } - wasmJsMain { + webMain { dependencies { implementation(libs.kotlinx.browser) } } - val nonWasmJsMain by creating { + val nonWebMain by creating { dependsOn(commonMain.get()) dependencies { implementation(libs.androidx.datastore.core) } } - jvmMain.get().dependsOn(nonWasmJsMain) - iosMain.get().dependsOn(nonWasmJsMain) - androidMain.get().dependsOn(nonWasmJsMain) - + jvmMain.get().dependsOn(nonWebMain) + iosMain.get().dependsOn(nonWebMain) + androidMain.get().dependsOn(nonWebMain) } exportKdoc() diff --git a/oidc-preferences/src/nonWasmJsMain/kotlin/org/publicvalue/multiplatform/oidc/preferences/PreferencesDataStore.kt b/oidc-preferences/src/nonWebMain/kotlin/org/publicvalue/multiplatform/oidc/preferences/PreferencesDataStore.kt similarity index 100% rename from oidc-preferences/src/nonWasmJsMain/kotlin/org/publicvalue/multiplatform/oidc/preferences/PreferencesDataStore.kt rename to oidc-preferences/src/nonWebMain/kotlin/org/publicvalue/multiplatform/oidc/preferences/PreferencesDataStore.kt diff --git a/oidc-preferences/src/wasmJsMain/kotlin/org/publicvalue/multiplatform/oidc/preferences/PreferencesFactory.wasmJs.kt b/oidc-preferences/src/webMain/kotlin/org/publicvalue/multiplatform/oidc/preferences/PreferencesFactory.web.kt similarity index 100% rename from oidc-preferences/src/wasmJsMain/kotlin/org/publicvalue/multiplatform/oidc/preferences/PreferencesFactory.wasmJs.kt rename to oidc-preferences/src/webMain/kotlin/org/publicvalue/multiplatform/oidc/preferences/PreferencesFactory.web.kt diff --git a/oidc-preferences/src/wasmJsMain/kotlin/org/publicvalue/multiplatform/oidc/preferences/PreferencesSession.kt b/oidc-preferences/src/webMain/kotlin/org/publicvalue/multiplatform/oidc/preferences/PreferencesSession.kt similarity index 100% rename from oidc-preferences/src/wasmJsMain/kotlin/org/publicvalue/multiplatform/oidc/preferences/PreferencesSession.kt rename to oidc-preferences/src/webMain/kotlin/org/publicvalue/multiplatform/oidc/preferences/PreferencesSession.kt diff --git a/oidc-tokenstore/build.gradle.kts b/oidc-tokenstore/build.gradle.kts index ce313fc5..66ef1da4 100644 --- a/oidc-tokenstore/build.gradle.kts +++ b/oidc-tokenstore/build.gradle.kts @@ -1,4 +1,5 @@ import org.publicvalue.convention.config.configureIosTargets +import org.publicvalue.convention.config.configureJsTarget import org.publicvalue.convention.config.configureWasmTarget plugins { @@ -14,6 +15,7 @@ kotlin { jvm() configureIosTargets() configureWasmTarget() + configureJsTarget() sourceSets { val commonMain by getting { dependencies { diff --git a/sample-app/settings/build.gradle.kts b/sample-app/settings/build.gradle.kts index 86ec3a68..5c6f071a 100644 --- a/sample-app/settings/build.gradle.kts +++ b/sample-app/settings/build.gradle.kts @@ -1,4 +1,5 @@ import org.publicvalue.convention.config.configureIosTargets +import org.publicvalue.convention.config.configureJsTarget import org.publicvalue.convention.config.configureWasmTarget plugins { @@ -9,9 +10,11 @@ plugins { kotlin { jvm() + configureIosTargets() + configureWasmTarget() + configureJsTarget() + sourceSets { - configureIosTargets() - configureWasmTarget() val commonMain by getting { dependencies { implementation("io.github.kalinjul.kotlin.multiplatform:oidc-core") @@ -21,7 +24,7 @@ kotlin { } } - wasmJsMain { + webMain { dependencies { implementation(libs.kotlinx.browser) } diff --git a/sample-app/settings/src/wasmJsMain/kotlin/org/publicvalue/multiplatform/oidc/settings/WasmJsSettingsStore.kt b/sample-app/settings/src/webMain/kotlin/org/publicvalue/multiplatform/oidc/settings/WebMainSettingsStore.kt similarity index 64% rename from sample-app/settings/src/wasmJsMain/kotlin/org/publicvalue/multiplatform/oidc/settings/WasmJsSettingsStore.kt rename to sample-app/settings/src/webMain/kotlin/org/publicvalue/multiplatform/oidc/settings/WebMainSettingsStore.kt index 3231b107..d4ad5af5 100644 --- a/sample-app/settings/src/wasmJsMain/kotlin/org/publicvalue/multiplatform/oidc/settings/WasmJsSettingsStore.kt +++ b/sample-app/settings/src/webMain/kotlin/org/publicvalue/multiplatform/oidc/settings/WebMainSettingsStore.kt @@ -2,19 +2,10 @@ package org.publicvalue.multiplatform.oidc.settings import com.russhwolf.settings.StorageSettings import com.russhwolf.settings.get -import kotlinx.browser.localStorage -import org.w3c.dom.Storage -class WasmJsSettingsStore: SettingsStore { - - val prefs: StorageSettings - - constructor(storage: Storage) { - prefs = StorageSettings(storage) - } - - constructor(): this(localStorage) +class WebMainSettingsStore : SettingsStore { + private val prefs: StorageSettings = StorageSettings() override suspend fun get(key: String): String? { return prefs[key] diff --git a/sample-app/shared/build.gradle.kts b/sample-app/shared/build.gradle.kts index 3a3aec0b..a7341925 100644 --- a/sample-app/shared/build.gradle.kts +++ b/sample-app/shared/build.gradle.kts @@ -2,6 +2,7 @@ import org.jetbrains.kotlin.gradle.plugin.mpp.Framework import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget import org.publicvalue.convention.addParcelizeAnnotation import org.publicvalue.convention.config.configureIosTargets +import org.publicvalue.convention.config.configureJsTarget import org.publicvalue.convention.config.configureWasmTarget plugins { @@ -17,6 +18,7 @@ kotlin { jvm() configureIosTargets() configureWasmTarget() + configureJsTarget() sourceSets { val commonMain by getting { dependencies { @@ -50,6 +52,12 @@ kotlin { implementation(libs.kotlinx.coroutines.test) } } + + webMain { + dependencies { + implementation(libs.kotlinx.browser) + } + } } targets.withType().configureEach { diff --git a/sample-app/shared/src/wasmJsMain/kotlin/main.wasmJs.kt b/sample-app/shared/src/webMain/kotlin/main.web.kt similarity index 74% rename from sample-app/shared/src/wasmJsMain/kotlin/main.wasmJs.kt rename to sample-app/shared/src/webMain/kotlin/main.web.kt index 36e9bbb0..1dc4e609 100644 --- a/sample-app/shared/src/wasmJsMain/kotlin/main.wasmJs.kt +++ b/sample-app/shared/src/webMain/kotlin/main.web.kt @@ -3,9 +3,9 @@ import com.slack.circuit.backstack.rememberSaveableBackStack import com.slack.circuit.foundation.rememberCircuitNavigator import kotlinx.browser.window import org.publicvalue.multiplatform.oidc.ExperimentalOpenIdConnect -import org.publicvalue.multiplatform.oidc.appsupport.WasmCodeAuthFlowFactory +import org.publicvalue.multiplatform.oidc.appsupport.WebCodeAuthFlowFactory import org.publicvalue.multiplatform.oidc.sample.screens.HomeScreen -import org.publicvalue.multiplatform.oidc.settings.WasmJsSettingsStore +import org.publicvalue.multiplatform.oidc.settings.WebMainSettingsStore @OptIn(ExperimentalOpenIdConnect::class) @Composable @@ -14,13 +14,13 @@ fun MainView() { val navigator = rememberCircuitNavigator(backstack) {} - val settingsStore = WasmJsSettingsStore() + val settingsStore = WebMainSettingsStore() App( backstack = backstack, navigator = navigator, settingsStore = settingsStore, - authFlowFactory = WasmCodeAuthFlowFactory( + authFlowFactory = WebCodeAuthFlowFactory( redirectOrigin = window.location.origin ) ) diff --git a/sample-app/shared/src/wasmJsMain/kotlin/org/publicvalue/multiplatform/oidc/sample/Constants.wasmJs.kt b/sample-app/shared/src/webMain/kotlin/org/publicvalue/multiplatform/oidc/sample/Constants.wasmJs.kt similarity index 100% rename from sample-app/shared/src/wasmJsMain/kotlin/org/publicvalue/multiplatform/oidc/sample/Constants.wasmJs.kt rename to sample-app/shared/src/webMain/kotlin/org/publicvalue/multiplatform/oidc/sample/Constants.wasmJs.kt diff --git a/sample-app/shared/src/wasmJsMain/kotlin/org/publicvalue/multiplatform/oidc/sample/screens/Parcelize.wasmJs.kt b/sample-app/shared/src/webMain/kotlin/org/publicvalue/multiplatform/oidc/sample/screens/Parcelize.wasmJs.kt similarity index 100% rename from sample-app/shared/src/wasmJsMain/kotlin/org/publicvalue/multiplatform/oidc/sample/screens/Parcelize.wasmJs.kt rename to sample-app/shared/src/webMain/kotlin/org/publicvalue/multiplatform/oidc/sample/screens/Parcelize.wasmJs.kt diff --git a/sample-app/wasm-js-app/build.gradle.kts b/sample-app/wasm-js-app/build.gradle.kts index cb4c997e..23f97c8e 100644 --- a/sample-app/wasm-js-app/build.gradle.kts +++ b/sample-app/wasm-js-app/build.gradle.kts @@ -8,6 +8,12 @@ plugins { kotlin { jvm() + // Explicitly apply the default KMP hierarchy so js and wasmJs get a shared 'webMain' source set. + applyDefaultHierarchyTemplate() + js(IR) { + browser() + binaries.executable() + } @OptIn(ExperimentalWasmDsl::class) wasmJs { outputModuleName = "wasm-js-app" @@ -27,7 +33,7 @@ kotlin { } sourceSets { - val wasmJsMain by getting { + val webMain by getting { dependencies { implementation(compose.runtime) implementation(compose.foundation)