diff --git a/CHANGELOG.md b/CHANGELOG.md index 9604502..afbd034 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,12 @@ All notable changes to this project will be documented in this file. [//]: # (## [next]) +## 0.0.6-dev +* Update to support ktor 3 +* Update dependencies: + * kotlin = "2.1.10" + ktor = "3.1.1" + * Move the dependencies's versions to catalog ## 0.0.5-dev * Update the versions to use kotlin `1.9.21` and ktor `2.3.6` diff --git a/example/build.gradle.kts b/example/build.gradle.kts index ba99cec..d94796f 100644 --- a/example/build.gradle.kts +++ b/example/build.gradle.kts @@ -1,7 +1,3 @@ -val kotlinVersion = libs.versions.kotlin.get() -val ktorVersion = libs.versions.ktor.get() -val logbackVersion = libs.versions.logback.get() - plugins { alias(libs.plugins.kotlin.jvm) application @@ -23,19 +19,19 @@ repositories { } dependencies { - implementation("io.ktor:ktor-server-auth-jvm:$ktorVersion") - implementation("io.ktor:ktor-server-core-jvm:$ktorVersion") - implementation("io.ktor:ktor-server-auth-jwt-jvm:$ktorVersion") - implementation("io.ktor:ktor-server-host-common-jvm:$ktorVersion") - implementation("io.ktor:ktor-server-status-pages-jvm:$ktorVersion") - implementation("io.ktor:ktor-server-compression-jvm:$ktorVersion") - implementation("io.ktor:ktor-server-caching-headers-jvm:$ktorVersion") - implementation("io.ktor:ktor-server-content-negotiation-jvm:$ktorVersion") - implementation("io.ktor:ktor-serialization-kotlinx-json-jvm:$ktorVersion") - implementation("io.ktor:ktor-server-netty-jvm:$ktorVersion") - implementation("ch.qos.logback:logback-classic:$logbackVersion") + implementation(libs.ktor.server.core) + implementation(libs.ktor.server.auth.jvm) + implementation(libs.ktor.server.auth.jwt) + implementation(libs.ktor.server.host) + implementation(libs.ktor.server.status.pages) + implementation(libs.ktor.server.compression) + implementation(libs.ktor.server.content.negotiation) + implementation(libs.ktor.server.netty) + implementation(libs.ktor.serialization.kotlinx.json) + implementation(libs.ktor.server.caching.headers) + implementation(libs.logback.classic) - testImplementation("io.ktor:ktor-server-tests-jvm:$ktorVersion") - testImplementation("org.jetbrains.kotlin:kotlin-test-junit:$kotlinVersion") + testImplementation(libs.ktor.server.test.jvm) + testImplementation(libs.kotlin.test) implementation(project(":library")) } \ No newline at end of file diff --git a/example/src/main/kotlin/Application.kt b/example/src/main/kotlin/Application.kt index 3773937..62c4c6e 100644 --- a/example/src/main/kotlin/Application.kt +++ b/example/src/main/kotlin/Application.kt @@ -1,6 +1,8 @@ -import io.ktor.server.application.* -import io.ktor.server.engine.* -import io.ktor.server.netty.* +import io.ktor.server.application.Application +import io.ktor.server.application.serverConfig +import io.ktor.server.engine.connector +import io.ktor.server.engine.embeddedServer +import io.ktor.server.netty.Netty import plugins.configureHTTP import plugins.configureRouting import plugins.configureSecurity @@ -9,17 +11,18 @@ import plugins.configureSerialization fun main() { embeddedServer( factory = Netty, - environment = applicationEngineEnvironment { - watchPaths = listOf("classes", "resources") + rootConfig = serverConfig { developmentMode = true + watchPaths = listOf("classes", "resources") + module(Application::module) + }, + configure = { connector { - port = 8080 host = "0.0.0.0" + port = 12345 } - module(Application::module) - }, - ) - .start(wait = true) + } + ).start(wait = true) } fun Application.module() { diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 2d7d110..9df6af9 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,7 +1,8 @@ [versions] -kotlin = "1.9.23" -ktor = "2.3.10" -library = "0.0.5-dev" +kotlin = "2.1.10" +ktor = "3.1.1" + +library = "0.0.6-dev" # Example logback = "1.5.4" @@ -9,14 +10,25 @@ logback = "1.5.4" # Library auth0-java-jwt = "4.4.0" auth0-java-jwksRsa = "0.22.1" - -kotlinx-coroutines = "1.8.0" -kotlinx-serialization = "1.6.3" +kotlinx-coroutines = "1.10.1" [libraries] -kotlin-test = { module = "org.jetbrains.kotlin:kotlin-test", version.ref = "kotlin" } +# Library +ktor-server-core = { module = "io.ktor:ktor-server-core-jvm", version.ref = "ktor" } +ktor-server-test-jvm = { module = "io.ktor:ktor-server-test-host", version.ref = "ktor" } +kotlin-test = { module = "org.jetbrains.kotlin:kotlin-test-junit", version.ref = "kotlin" } kotlinx-coroutines = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "kotlinx-coroutines" } -kotlinx-serialization-json = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json", version.ref = "kotlinx-serialization" } +# Example +ktor-server-auth-jvm = { module = "io.ktor:ktor-server-auth-jvm", version.ref = "ktor" } +ktor-server-auth-jwt = { module = "io.ktor:ktor-server-auth-jwt-jvm", version.ref = "ktor" } +ktor-server-host = { module = "io.ktor:ktor-server-host-common-jvm", version.ref = "ktor" } +ktor-server-status-pages = { module = "io.ktor:ktor-server-status-pages", version.ref = "ktor" } +ktor-server-compression = { module = "io.ktor:ktor-server-compression", version.ref = "ktor" } +ktor-server-content-negotiation = { module = "io.ktor:ktor-server-content-negotiation-jvm", version.ref = "ktor" } +ktor-server-netty = { module = "io.ktor:ktor-server-netty-jvm", version.ref = "ktor" } +ktor-serialization-kotlinx-json = { module = "io.ktor:ktor-serialization-kotlinx-json-jvm", version.ref = "ktor" } +ktor-server-caching-headers = { module = "io.ktor:ktor-server-caching-headers-jvm", version.ref = "ktor" } +logback-classic = { module = "ch.qos.logback:logback-classic", version.ref = "logback" } # JVM auth0-java-jwt = { module = "com.auth0:java-jwt", version.ref = "auth0-java-jwt" } diff --git a/library/build.gradle.kts b/library/build.gradle.kts index 5734386..89847d9 100644 --- a/library/build.gradle.kts +++ b/library/build.gradle.kts @@ -3,9 +3,6 @@ plugins { id("maven-publish") } -val kotlinVersion = libs.versions.kotlin.get() -val ktorVersion = libs.versions.ktor.get() - group = "net.freshplatform" version = libs.versions.library.get() description = @@ -13,32 +10,29 @@ description = kotlin { jvm() - linuxX64() - macosArm64() sourceSets { val commonMain by getting { dependencies { - implementation("io.ktor:ktor-server-core:$ktorVersion") + implementation(libs.ktor.server.core) implementation(libs.kotlinx.coroutines) } } val commonTest by getting { dependencies { - implementation("org.jetbrains.kotlin:kotlin-test-junit:$kotlinVersion") + implementation(libs.kotlin.test) } } val jvmMain by getting { dependencies { - implementation("io.ktor:ktor-server-core-jvm:$ktorVersion") + implementation(libs.ktor.server.core) implementation(libs.auth0.java.jwt) implementation(libs.auth0.java.jwksRsa) -// implementation("io.ktor:ktor-server-auth-jwt-jvm") } } val jvmTest by getting { dependencies { - implementation("io.ktor:ktor-server-tests-jvm:$ktorVersion") + implementation(libs.ktor.server.test.jvm) } } } @@ -65,4 +59,4 @@ kotlin { // content { includeGroup(jitpackGroupId) } // } // } -//} \ No newline at end of file +//} diff --git a/library/src/commonMain/kotlin/net/freshplatform/ktor_server/firebase_app_check/FirebaseAppCheck.kt b/library/src/commonMain/kotlin/net/freshplatform/ktor_server/firebase_app_check/FirebaseAppCheck.kt index 6393fb9..99fca50 100644 --- a/library/src/commonMain/kotlin/net/freshplatform/ktor_server/firebase_app_check/FirebaseAppCheck.kt +++ b/library/src/commonMain/kotlin/net/freshplatform/ktor_server/firebase_app_check/FirebaseAppCheck.kt @@ -1,8 +1,10 @@ package net.freshplatform.ktor_server.firebase_app_check -import io.ktor.server.application.* -import io.ktor.server.request.* -import io.ktor.util.* +import io.ktor.server.application.ApplicationCallPipeline +import io.ktor.server.application.BaseApplicationPlugin +import io.ktor.server.application.call +import io.ktor.server.request.uri +import io.ktor.util.AttributeKey import net.freshplatform.ktor_server.firebase_app_check.configurations.FirebaseAppCheckPluginConfiguration import net.freshplatform.ktor_server.firebase_app_check.configurations.FirebaseAppCheckSecureStrategy import net.freshplatform.ktor_server.firebase_app_check.service.FirebaseAppCheckTokenVerifierServiceImpl @@ -39,7 +41,7 @@ class FirebaseAppCheckPlugin( "The firebase project id should not be blank." } - val isShouldVerifyToken = configuration.isShouldVerifyToken(pipeline.environment) + val isShouldVerifyToken = configuration.isShouldVerifyToken(pipeline.developmentMode) val secureStrategy = configuration.secureStrategy if (isShouldVerifyToken && secureStrategy !is FirebaseAppCheckSecureStrategy.ProtectSpecificRoutes) { pipeline.intercept(ApplicationCallPipeline.Call) { diff --git a/library/src/commonMain/kotlin/net/freshplatform/ktor_server/firebase_app_check/configurations/FirebaseAppCheckPluginConfiguration.kt b/library/src/commonMain/kotlin/net/freshplatform/ktor_server/firebase_app_check/configurations/FirebaseAppCheckPluginConfiguration.kt index e2c5011..b98bb16 100644 --- a/library/src/commonMain/kotlin/net/freshplatform/ktor_server/firebase_app_check/configurations/FirebaseAppCheckPluginConfiguration.kt +++ b/library/src/commonMain/kotlin/net/freshplatform/ktor_server/firebase_app_check/configurations/FirebaseAppCheckPluginConfiguration.kt @@ -182,14 +182,10 @@ class FirebaseAppCheckPluginConfiguration( /** * Determines whether token verification should be performed based on the environment (developmentMode). * - * @param environment The application environment. + * @param isDevMode A boolean indicating whether dev mode is enabled or not. * @return `true` if token verification should be performed; otherwise, `false`. */ - fun isShouldVerifyToken(environment: ApplicationEnvironment?): Boolean { - isShouldVerifyToken?.let { - return it - } - val isDevMode = environment?.developmentMode ?: false - return !isDevMode - } + fun isShouldVerifyToken(isDevMode: Boolean): Boolean = + isShouldVerifyToken ?: !isDevMode + } \ No newline at end of file diff --git a/library/src/commonMain/kotlin/net/freshplatform/ktor_server/firebase_app_check/utils/ApplicationCallExtensions.kt b/library/src/commonMain/kotlin/net/freshplatform/ktor_server/firebase_app_check/utils/ApplicationCallExtensions.kt index fdc9cc7..379603c 100644 --- a/library/src/commonMain/kotlin/net/freshplatform/ktor_server/firebase_app_check/utils/ApplicationCallExtensions.kt +++ b/library/src/commonMain/kotlin/net/freshplatform/ktor_server/firebase_app_check/utils/ApplicationCallExtensions.kt @@ -1,10 +1,18 @@ package net.freshplatform.ktor_server.firebase_app_check.utils -import io.ktor.http.* -import io.ktor.server.application.* -import io.ktor.server.request.* -import io.ktor.server.response.* -import io.ktor.server.routing.* +import io.ktor.http.HttpStatusCode +import io.ktor.server.application.ApplicationCall +import io.ktor.server.application.ApplicationCallPipeline +import io.ktor.server.application.call +import io.ktor.server.application.plugin +import io.ktor.server.request.header +import io.ktor.server.response.respond +import io.ktor.server.routing.Route +import io.ktor.server.routing.RouteSelector +import io.ktor.server.routing.RouteSelectorEvaluation +import io.ktor.server.routing.RoutingResolveContext +import io.ktor.server.routing.application +import io.ktor.server.routing.intercept import net.freshplatform.ktor_server.firebase_app_check.FirebaseAppCheckPlugin import net.freshplatform.ktor_server.firebase_app_check.configurations.FirebaseAppCheckSecureStrategy @@ -103,7 +111,7 @@ fun Route.protectRouteWithAppCheck( val configuration = application.plugin(FirebaseAppCheckPlugin).config val protectedRoute = createChild(ProtectedRouteSelector()) - val isShouldVerifyToken = configuration.isShouldVerifyToken(environment) + val isShouldVerifyToken = configuration.isShouldVerifyToken(application.developmentMode) if (isShouldVerifyToken) { protectedRoute.intercept(ApplicationCallPipeline.Call) { _ -> @@ -114,7 +122,7 @@ fun Route.protectRouteWithAppCheck( } class ProtectedRouteSelector : RouteSelector() { - override fun evaluate(context: RoutingResolveContext, segmentIndex: Int): RouteSelectorEvaluation { + override suspend fun evaluate(context: RoutingResolveContext, segmentIndex: Int): RouteSelectorEvaluation { return RouteSelectorEvaluation.Transparent }