diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index a6f5da0..bcd48d3 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -17,5 +17,9 @@ jobs: java-version: 17 distribution: 'adopt' cache: gradle + - name: Make sure the `./gradlew` is executable + run: chmod +x ./gradlew - name: Build with Gradle run: ./gradlew build + - name: Double check the Tests + run: ./gradlew allTests diff --git a/CHANGELOG.md b/CHANGELOG.md index 583bd97..5194b8c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,18 @@ All notable changes to this project will be documented in this file. [//]: # (## [next]) +## 0.0.5-dev +* Update the versions to use kotlin `1.9.21` and ktor `2.3.6` +* Prepare the library to be a KMP Library by using the Kotlin Multiplatform Gradle plugin +and add the source sets (`jvmMain` and `commonMain`) +* Share some +* Update `README` by add a status section +* Fix a few typos in the docs +* Update the `build.gradle.kts` to make it less specific to JVM, and remove unused gradle ktor plugin +* Fix the `group` of the dependency +* Update GitHub Main workflow +* Add `before-push.sh` script + ## 0.0.4-dev * The library is now dev state * Improve the tests diff --git a/README.md b/README.md index 63e06e5..0c68697 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,7 @@ feel free to share your opinion in the discussions - [About](#about) - [Installation](#installation) - [Usage](#usage) +- [Status](#status) - [Features](#features) - [Contributing](#contributing) - [Acknowledgments](#acknowledgments) @@ -137,12 +138,25 @@ Token for testing purposes: eyJraWQiOiJ2Yy1sVEEiLCJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJzdWIiOiIxOjgwMjA4OTE0MjU1OTphbmRyb2lkOjI2ZDhjMDA3ZGVkMDNmODQyYTg4MmEiLCJhdWQiOlsicHJvamVjdHNcLzgwMjA4OTE0MjU1OSIsInByb2plY3RzXC9teW5vdGVzLWViNzE3Il0sInByb3ZpZGVyIjoiZGVidWciLCJpc3MiOiJodHRwczpcL1wvZmlyZWJhc2VhcHBjaGVjay5nb29nbGVhcGlzLmNvbVwvODAyMDg5MTQyNTU5IiwiZXhwIjoxNjk3MTM0NDg3LCJpYXQiOjE2OTcxMzA4ODcsImp0aSI6InZLZERfNTRhQ2tzVmpHV0xBN3d1TjZmWlFUQWRYZzRBWGJhYVBzRUZDV0EifQ.H_LGsCe5I-Z2uAgYU1isDmxQ-6PecdmjEqvkrZp9AWthNhsiMdlVYjUe2DaSmt3lhIlwCJyCh2YooOLvSlFAvdx5n__kB5O5C9Fw-Vw-zjSTOAi6lNB0hi8OEkIJhNgw2b_UipeVFd1I6ICkCdV93Ewr-clv-eDeMIg_b8vr3w6HtypZDVu3hAl6BjfxY9r7cm5eBmHGnOxwb1-flSKRJdBmrh4Bm0_imaDPSHw_rUwCUXHOAM-QfdQ-D4C15L_IJH4X6kT7nm8GMj47rQjr1d6CQZbW3xoIsTJvnpreOR1xyiHZiLydj1cwPt6r2DfmjRL6-tFs2u8c72CcoqQ4hhsJE9ZSk1BHXpnGw6t5PLPWmk-K7wCrn49U20SYsbOGzyMmwPs-nRyYL3QeV00brlaQWFN7pnjquYHtgJZgkVZlIe1Hh_8mBzTSLygc3-0Xw3FKf1X6p_jOyyN7Qi3Wf5GHvBdp_sYyuBtXMYVwhKQ56lYBX3waLP0KHSiDiDUW ``` +## Status + +Is this library ready for production use?? +The short answer is yes, the long one is no, because we do have +plans to change too many things that are not related to how the logic +of Firebase App Check works, the logic will likely still be the same + +It will only update when the official one updates. +What could be changes then? +only cosmetic changes to change the way to use the library, +for example, we might change the library name to `KotlinGuardian` or `KtorGuardian` +and add support for different providers to use instead of firebase alone, add more features +and things, so we expect to do too many breaking changes but other than that + +The library should work just fine as long it follows the official docs of firebase ## Features List the key features of the library -please notice the library is still **Alpha** - ```markdown ## Features @@ -156,7 +170,8 @@ please notice the library is still **Alpha** We welcome contributions! -Please follow these guidelines when contributing to our project. See [CONTRIBUTING.md](./docs/CONTRIBUTING.md) for more details. +Please follow these guidelines when contributing to this project. +See [CONTRIBUTING.md](./docs/CONTRIBUTING.md) for more details. ## Acknowledgments diff --git a/example/build.gradle.kts b/example/build.gradle.kts index e9c4e68..f9988f8 100644 --- a/example/build.gradle.kts +++ b/example/build.gradle.kts @@ -5,8 +5,9 @@ val auth0JwksRsaVersion = extra["auth0JwksRsa.version"] as String val auth0JavaJwtVersion = extra["auth0JavaJwt.version"] as String plugins { - kotlin("jvm") - id("io.ktor.plugin") + kotlin("multiplatform") +// id("io.ktor.plugin") + application id("org.jetbrains.kotlin.plugin.serialization") } @@ -14,7 +15,7 @@ group = "net.freshplatform" version = "0.0.1" application { - mainClass.set("net.freshplatform.ApplicationKt") + mainClass.set("ApplicationKt") val isDevelopment: Boolean = project.ext.has("development") applicationDefaultJvmArgs = listOf("-Dio.ktor.development=$isDevelopment") @@ -22,7 +23,6 @@ application { repositories { mavenCentral() -// mavenLocal() val jitpackGroupId = "com.github.freshtechtips" maven { name = "jitpack" @@ -31,20 +31,35 @@ repositories { } } -dependencies { - implementation("io.ktor:ktor-server-auth-jvm") - implementation("io.ktor:ktor-server-core-jvm") - implementation("io.ktor:ktor-server-auth-jwt-jvm") - implementation("io.ktor:ktor-server-host-common-jvm") - implementation("io.ktor:ktor-server-status-pages-jvm") - implementation("io.ktor:ktor-server-compression-jvm") - implementation("io.ktor:ktor-server-caching-headers-jvm") - implementation("io.ktor:ktor-server-content-negotiation-jvm") - implementation("io.ktor:ktor-serialization-kotlinx-json-jvm") - implementation("io.ktor:ktor-server-netty-jvm") - implementation("ch.qos.logback:logback-classic:$logbackVersion") - testImplementation("io.ktor:ktor-server-tests-jvm") - testImplementation("org.jetbrains.kotlin:kotlin-test-junit:$kotlinVersion") +kotlin { + jvm() - implementation(project(":library")) -} + sourceSets { + val commonMain by getting { + dependencies { + implementation(project(":library")) + } + } + val jvmMain by getting { + 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") + } + } + val jvmTest by getting { + dependencies { + implementation("io.ktor:ktor-server-tests-jvm:$ktorVersion") + implementation("org.jetbrains.kotlin:kotlin-test-junit:$kotlinVersion") + } + } + } +} \ No newline at end of file diff --git a/example/src/main/kotlin/net/freshplatform/Application.kt b/example/src/jvmMain/kotlin/Application.kt similarity index 82% rename from example/src/main/kotlin/net/freshplatform/Application.kt rename to example/src/jvmMain/kotlin/Application.kt index 3891a30..3773937 100644 --- a/example/src/main/kotlin/net/freshplatform/Application.kt +++ b/example/src/jvmMain/kotlin/Application.kt @@ -1,10 +1,10 @@ -package net.freshplatform - -import io.ktor.network.sockets.* import io.ktor.server.application.* import io.ktor.server.engine.* import io.ktor.server.netty.* -import net.freshplatform.plugins.* +import plugins.configureHTTP +import plugins.configureRouting +import plugins.configureSecurity +import plugins.configureSerialization fun main() { embeddedServer( diff --git a/example/src/jvmMain/kotlin/plugins/AppCheck.kt b/example/src/jvmMain/kotlin/plugins/AppCheck.kt new file mode 100644 index 0000000..d4a602c --- /dev/null +++ b/example/src/jvmMain/kotlin/plugins/AppCheck.kt @@ -0,0 +1,26 @@ +package plugins + +import io.ktor.server.application.* +//import net.freshplatform.ktor_server.firebase_app_check.FirebaseAppCheckPlugin +//import net.freshplatform.ktor_server.firebase_app_check.core.FirebaseAppCheckSecureStrategy +//import net.freshplatform.ktor_server.firebase_app_check.utils.FirebaseAppCheckMessages + +fun Application.configureAppCheck() { +// install(FirebaseAppCheckPlugin) { +// firebaseProjectNumber = System.getenv("FIREBASE_PROJECT_NUMBER") +// ?: throw MissingEnvironmentVariableException("FIREBASE_PROJECT_NUMBER") +// firebaseProjectId = System.getenv("FIREBASE_PROJECT_ID") +// ?: throw MissingEnvironmentVariableException("FIREBASE_PROJECT_ID") +// isShouldVerifyToken = true +// secureStrategy = FirebaseAppCheckSecureStrategy.ProtectSpecificRoutes +// pluginMessagesBuilder = { configuration -> +// // Example of override a response message +// FirebaseAppCheckMessages( +// configuration, +// appCheckIsNotDefinedResponse = mapOf( +// "error" to "${configuration.firebaseAppCheckHeaderName} is required" +// ), +// ) +// } +// } +} \ No newline at end of file diff --git a/example/src/main/kotlin/net/freshplatform/plugins/HTTP.kt b/example/src/jvmMain/kotlin/plugins/HTTP.kt similarity index 95% rename from example/src/main/kotlin/net/freshplatform/plugins/HTTP.kt rename to example/src/jvmMain/kotlin/plugins/HTTP.kt index 237e247..ed408da 100644 --- a/example/src/main/kotlin/net/freshplatform/plugins/HTTP.kt +++ b/example/src/jvmMain/kotlin/plugins/HTTP.kt @@ -1,4 +1,4 @@ -package net.freshplatform.plugins +package plugins import io.ktor.http.* import io.ktor.http.content.* diff --git a/example/src/main/kotlin/net/freshplatform/plugins/Routing.kt b/example/src/jvmMain/kotlin/plugins/Routing.kt similarity index 60% rename from example/src/main/kotlin/net/freshplatform/plugins/Routing.kt rename to example/src/jvmMain/kotlin/plugins/Routing.kt index 68d2850..b2ed5f8 100644 --- a/example/src/main/kotlin/net/freshplatform/plugins/Routing.kt +++ b/example/src/jvmMain/kotlin/plugins/Routing.kt @@ -1,11 +1,11 @@ -package net.freshplatform.plugins +package plugins import io.ktor.http.* import io.ktor.server.application.* import io.ktor.server.plugins.statuspages.* import io.ktor.server.response.* import io.ktor.server.routing.* -import net.freshplatform.ktor_server.firebase_app_check.utils.extensions.protectRouteWithAppCheck +//import net.freshplatform.ktor_server.firebase_app_check.utils.extensions.protectRouteWithAppCheck class MissingEnvironmentVariableException(variableName: String) : RuntimeException("The required environment variable '$variableName' is missing.") @@ -21,16 +21,16 @@ fun Application.configureRouting() { get("/") { call.respondText("Hello World! this route is not using app firebase app check") } - protectRouteWithAppCheck { - route("/products") { - get("/1") { - call.respondText { "Product 1, Firebase app check" } - } - get("/2") { - call.respondText { "Product 2, Firebase app check" } - } - } - } +// protectRouteWithAppCheck { +// route("/products") { +// get("/1") { +// call.respondText { "Product 1, Firebase app check" } +// } +// get("/2") { +// call.respondText { "Product 2, Firebase app check" } +// } +// } +// } route("/products") { get("/3") { call.respondText { "Product 2, Firebase app check is not required." } @@ -39,10 +39,10 @@ fun Application.configureRouting() { get("/test") { call.respondText { "This get /test doesn't use firebase app check!" } } - protectRouteWithAppCheck { - post("/test") { - call.respondText { "This post /test is protected!" } - } - } +// protectRouteWithAppCheck { +// post("/test") { +// call.respondText { "This post /test is protected!" } +// } +// } } } diff --git a/example/src/main/kotlin/net/freshplatform/plugins/Security.kt b/example/src/jvmMain/kotlin/plugins/Security.kt similarity index 74% rename from example/src/main/kotlin/net/freshplatform/plugins/Security.kt rename to example/src/jvmMain/kotlin/plugins/Security.kt index 79204c4..9eeb544 100644 --- a/example/src/main/kotlin/net/freshplatform/plugins/Security.kt +++ b/example/src/jvmMain/kotlin/plugins/Security.kt @@ -1,4 +1,4 @@ -package net.freshplatform.plugins +package plugins import io.ktor.server.application.* diff --git a/example/src/main/kotlin/net/freshplatform/plugins/Serialization.kt b/example/src/jvmMain/kotlin/plugins/Serialization.kt similarity index 89% rename from example/src/main/kotlin/net/freshplatform/plugins/Serialization.kt rename to example/src/jvmMain/kotlin/plugins/Serialization.kt index 3d860bd..59b7ea2 100644 --- a/example/src/main/kotlin/net/freshplatform/plugins/Serialization.kt +++ b/example/src/jvmMain/kotlin/plugins/Serialization.kt @@ -1,4 +1,4 @@ -package net.freshplatform.plugins +package plugins import io.ktor.serialization.kotlinx.json.* import io.ktor.server.application.* diff --git a/example/src/main/resources/logback.xml b/example/src/jvmMain/resources/logback.xml similarity index 100% rename from example/src/main/resources/logback.xml rename to example/src/jvmMain/resources/logback.xml diff --git a/example/src/test/kotlin/net/freshplatform/ApplicationTest.kt b/example/src/jvmTest/kotlin/ApplicationTest.kt similarity index 66% rename from example/src/test/kotlin/net/freshplatform/ApplicationTest.kt rename to example/src/jvmTest/kotlin/ApplicationTest.kt index 00e6655..3381432 100644 --- a/example/src/test/kotlin/net/freshplatform/ApplicationTest.kt +++ b/example/src/jvmTest/kotlin/ApplicationTest.kt @@ -1,11 +1,5 @@ -package net.freshplatform - -import io.ktor.client.request.* -import io.ktor.client.statement.* -import io.ktor.http.* import io.ktor.server.testing.* -import kotlin.test.* -import net.freshplatform.plugins.* +import kotlin.test.Test class ApplicationTest { @Test diff --git a/example/src/main/kotlin/net/freshplatform/plugins/AppCheck.kt b/example/src/main/kotlin/net/freshplatform/plugins/AppCheck.kt deleted file mode 100644 index e3226a4..0000000 --- a/example/src/main/kotlin/net/freshplatform/plugins/AppCheck.kt +++ /dev/null @@ -1,26 +0,0 @@ -package net.freshplatform.plugins - -import io.ktor.server.application.* -import net.freshplatform.ktor_server.firebase_app_check.FirebaseAppCheckPlugin -import net.freshplatform.ktor_server.firebase_app_check.core.FirebaseAppCheckSecureStrategy -import net.freshplatform.ktor_server.firebase_app_check.utils.FirebaseAppCheckMessages - -fun Application.configureAppCheck() { - install(FirebaseAppCheckPlugin) { - firebaseProjectNumber = System.getenv("FIREBASE_PROJECT_NUMBER") - ?: throw MissingEnvironmentVariableException("FIREBASE_PROJECT_NUMBER") - firebaseProjectId = System.getenv("FIREBASE_PROJECT_ID") - ?: throw MissingEnvironmentVariableException("FIREBASE_PROJECT_ID") - isShouldVerifyToken = true - secureStrategy = FirebaseAppCheckSecureStrategy.ProtectSpecificRoutes - pluginMessagesBuilder = { configuration -> - // Example of override a response message - FirebaseAppCheckMessages( - configuration, - appCheckIsNotDefinedResponse = mapOf( - "error" to "${configuration.firebaseAppCheckHeaderName} is required" - ), - ) - } - } -} \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index 4284773..c86e89f 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,13 +1,14 @@ kotlin.code.style=official + # Versions # Shared -kotlin.version=1.9.20 -ktor.version=2.3.5 +kotlin.version=1.9.21 +ktor.version=2.3.6 # Example logback.version=1.4.11 # Library auth0JwksRsa.version=0.22.1 -auth0JavaJwt.version=4.4.0 +auth0JavaJwt.version=4.4.0 \ No newline at end of file diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml new file mode 100644 index 0000000..6ed4ba9 --- /dev/null +++ b/gradle/libs.versions.toml @@ -0,0 +1,5 @@ +[versions] + +[libraries] + +[plugins] \ No newline at end of file diff --git a/library/build.gradle.kts b/library/build.gradle.kts index 4b6e977..9906841 100644 --- a/library/build.gradle.kts +++ b/library/build.gradle.kts @@ -4,36 +4,67 @@ val auth0JwksRsaVersion = extra["auth0JwksRsa.version"] as String val auth0JavaJwtVersion = extra["auth0JavaJwt.version"] as String plugins { - kotlin("jvm") - id("io.ktor.plugin") + kotlin("multiplatform") + application id("maven-publish") id("java-library") } -group = "net.freshplatform.ktor_server.firebase_app_check" -version = "0.0.4-dev" -description = "A Ktor server plugin for configuring Firebase App Check easily and with simplicity. It is not affiliated with Firebase or Google and may not be suitable for production use yet." +group = "net.freshplatform" +version = "0.0.5-dev" +description = + "A Ktor server plugin for configuring Firebase App Check easily and with simplicity. It is not affiliated with Firebase or Google and may not be suitable for production use yet." application { - mainClass.set("${group}.FirebaseAppCheckKt") + mainClass.set("${group}.ktor_server.firebase_app_check.FirebaseAppCheckKt") +} + +kotlin { + jvm { + jvmToolchain(17) + } + + sourceSets { + val commonMain by getting { + dependencies { + implementation("io.ktor:ktor-server-core:$ktorVersion") + } + } + val commonTest by getting { + dependencies { + implementation("org.jetbrains.kotlin:kotlin-test-junit:$kotlinVersion") + } + } + val jvmMain by getting { + dependencies { + implementation("io.ktor:ktor-server-core-jvm:$ktorVersion") + implementation("com.auth0:jwks-rsa:$auth0JwksRsaVersion") + implementation("com.auth0:java-jwt:$auth0JavaJwtVersion") +// implementation("io.ktor:ktor-server-auth-jwt-jvm") + } + } + val jvmTest by getting { + dependencies { + implementation("io.ktor:ktor-server-tests-jvm:$ktorVersion") + } + } +// val nativeMain by creating { +// dependsOn(commonMain) +// } +// val nativeTest by creating { +// dependsOn(nativeMain) +// } + } } repositories { mavenCentral() } -dependencies { - implementation("io.ktor:ktor-server-core-jvm") - implementation("com.auth0:jwks-rsa:$auth0JwksRsaVersion") - implementation("com.auth0:java-jwt:$auth0JavaJwtVersion") -// implementation("io.ktor:ktor-server-auth-jwt-jvm") - testImplementation("io.ktor:ktor-server-tests-jvm") - testImplementation("org.jetbrains.kotlin:kotlin-test-junit:$kotlinVersion") -} +publishing { -val jitpackGroupId = "com.github.freshtechtips" + val jitpackGroupId = "com.github.freshtechtips" -publishing { publications { create("jitpack") { from(components["java"]) @@ -45,7 +76,6 @@ publishing { } repositories { - mavenLocal() maven { name = "jitpack" setUrl("https://jitpack.io") diff --git a/library/src/main/kotlin/net/freshplatform/ktor_server/firebase_app_check/core/FirebaseAppCheckSecureStrategy.kt b/library/src/commonMain/kotlin/net/freshplatform/ktor_server/firebase_app_check/core/FirebaseAppCheckSecureStrategy.kt similarity index 80% rename from library/src/main/kotlin/net/freshplatform/ktor_server/firebase_app_check/core/FirebaseAppCheckSecureStrategy.kt rename to library/src/commonMain/kotlin/net/freshplatform/ktor_server/firebase_app_check/core/FirebaseAppCheckSecureStrategy.kt index d6c0225..f16dac1 100644 --- a/library/src/main/kotlin/net/freshplatform/ktor_server/firebase_app_check/core/FirebaseAppCheckSecureStrategy.kt +++ b/library/src/commonMain/kotlin/net/freshplatform/ktor_server/firebase_app_check/core/FirebaseAppCheckSecureStrategy.kt @@ -1,12 +1,10 @@ package net.freshplatform.ktor_server.firebase_app_check.core -import net.freshplatform.ktor_server.firebase_app_check.utils.extensions.protectRouteWithAppCheck - /** * A sealed class that defines different strategies for securing routes with Firebase App Check. - * if you want to secure the whole app use [FirebaseAppCheckSecureStrategy.ProtectAll] for all the requests + * If you want to secure the whole app use [FirebaseAppCheckSecureStrategy.ProtectAll] for all the requests * if you want a specific routes in the app use [FirebaseAppCheckSecureStrategy.ProtectSpecificRoutes] - * * and then protect the routes in the routing by surround them with [protectRouteWithAppCheck] + * * and then protect the routes in the routing by surround them with [protectRouteWithAppCheck] // TODO: Import this * if you want to protect routes by the path of the route as string use * [FirebaseAppCheckSecureStrategy.ProtectRoutesByPaths] */ diff --git a/library/src/main/kotlin/net/freshplatform/ktor_server/firebase_app_check/exceptions/FirebaseAppCheckExceptions.kt b/library/src/commonMain/kotlin/net/freshplatform/ktor_server/firebase_app_check/exceptions/FirebaseAppCheckExceptions.kt similarity index 98% rename from library/src/main/kotlin/net/freshplatform/ktor_server/firebase_app_check/exceptions/FirebaseAppCheckExceptions.kt rename to library/src/commonMain/kotlin/net/freshplatform/ktor_server/firebase_app_check/exceptions/FirebaseAppCheckExceptions.kt index 0900e9b..b52507a 100644 --- a/library/src/main/kotlin/net/freshplatform/ktor_server/firebase_app_check/exceptions/FirebaseAppCheckExceptions.kt +++ b/library/src/commonMain/kotlin/net/freshplatform/ktor_server/firebase_app_check/exceptions/FirebaseAppCheckExceptions.kt @@ -1,7 +1,5 @@ package net.freshplatform.ktor_server.firebase_app_check.exceptions -import java.lang.Exception - /** * A custom exception class for Firebase App Check-related errors. * diff --git a/library/src/main/kotlin/net/freshplatform/ktor_server/firebase_app_check/services/FirebaseAppCheckTokenVerifierService.kt b/library/src/commonMain/kotlin/net/freshplatform/ktor_server/firebase_app_check/service/FirebaseAppCheckTokenVerifierService.kt similarity index 99% rename from library/src/main/kotlin/net/freshplatform/ktor_server/firebase_app_check/services/FirebaseAppCheckTokenVerifierService.kt rename to library/src/commonMain/kotlin/net/freshplatform/ktor_server/firebase_app_check/service/FirebaseAppCheckTokenVerifierService.kt index 99bdbb1..1d6b42b 100644 --- a/library/src/main/kotlin/net/freshplatform/ktor_server/firebase_app_check/services/FirebaseAppCheckTokenVerifierService.kt +++ b/library/src/commonMain/kotlin/net/freshplatform/ktor_server/firebase_app_check/service/FirebaseAppCheckTokenVerifierService.kt @@ -1,4 +1,4 @@ -package net.freshplatform.ktor_server.firebase_app_check.services +package net.freshplatform.ktor_server.firebase_app_check.service import com.auth0.jwt.interfaces.DecodedJWT import java.security.PublicKey diff --git a/library/src/commonTest/kotlin/net/freshplatform/ktor_server/firebase_app_check/.gitignore b/library/src/commonTest/kotlin/net/freshplatform/ktor_server/firebase_app_check/.gitignore new file mode 100644 index 0000000..e69de29 diff --git a/library/src/main/kotlin/net/freshplatform/ktor_server/firebase_app_check/FirebaseAppCheck.kt b/library/src/jvmMain/kotlin/net/freshplatform/ktor_server/firebase_app_check/FirebaseAppCheck.kt similarity index 93% rename from library/src/main/kotlin/net/freshplatform/ktor_server/firebase_app_check/FirebaseAppCheck.kt rename to library/src/jvmMain/kotlin/net/freshplatform/ktor_server/firebase_app_check/FirebaseAppCheck.kt index 74d559a..d351974 100644 --- a/library/src/main/kotlin/net/freshplatform/ktor_server/firebase_app_check/FirebaseAppCheck.kt +++ b/library/src/jvmMain/kotlin/net/freshplatform/ktor_server/firebase_app_check/FirebaseAppCheck.kt @@ -5,8 +5,6 @@ import io.ktor.server.request.* import io.ktor.util.* import net.freshplatform.ktor_server.firebase_app_check.core.FirebaseAppCheckPluginConfiguration import net.freshplatform.ktor_server.firebase_app_check.core.FirebaseAppCheckSecureStrategy -import net.freshplatform.ktor_server.firebase_app_check.services.FirebaseAppCheckTokenVerifierService -import net.freshplatform.ktor_server.firebase_app_check.services.FirebaseAppCheckTokenVerifierServiceImpl import net.freshplatform.ktor_server.firebase_app_check.utils.extensions.verifyAppTokenRequest /** diff --git a/library/src/main/kotlin/net/freshplatform/ktor_server/firebase_app_check/core/FirebaseAppCheckPluginConfiguration.kt b/library/src/jvmMain/kotlin/net/freshplatform/ktor_server/firebase_app_check/core/FirebaseAppCheckPluginConfiguration.kt similarity index 97% rename from library/src/main/kotlin/net/freshplatform/ktor_server/firebase_app_check/core/FirebaseAppCheckPluginConfiguration.kt rename to library/src/jvmMain/kotlin/net/freshplatform/ktor_server/firebase_app_check/core/FirebaseAppCheckPluginConfiguration.kt index c8a0658..9789e5d 100644 --- a/library/src/main/kotlin/net/freshplatform/ktor_server/firebase_app_check/core/FirebaseAppCheckPluginConfiguration.kt +++ b/library/src/jvmMain/kotlin/net/freshplatform/ktor_server/firebase_app_check/core/FirebaseAppCheckPluginConfiguration.kt @@ -10,8 +10,8 @@ import net.freshplatform.ktor_server.firebase_app_check.exceptions.FirebaseAppCh import net.freshplatform.ktor_server.firebase_app_check.exceptions.FirebaseAppCheckVerifyJwtErrorType import net.freshplatform.ktor_server.firebase_app_check.exceptions.FirebaseAppCheckVerifyJwtErrorType.* import net.freshplatform.ktor_server.firebase_app_check.exceptions.FirebaseAppCheckVerifyJwtException -import net.freshplatform.ktor_server.firebase_app_check.services.FirebaseAppCheckTokenVerifierService -import net.freshplatform.ktor_server.firebase_app_check.services.FirebaseAppCheckTokenVerifierServiceImpl +import net.freshplatform.ktor_server.firebase_app_check.service.FirebaseAppCheckTokenVerifierService +import net.freshplatform.ktor_server.firebase_app_check.service.FirebaseAppCheckTokenVerifierServiceImpl import net.freshplatform.ktor_server.firebase_app_check.utils.FirebaseAppCheckMessages /** @@ -161,7 +161,7 @@ class FirebaseAppCheckPluginConfiguration( } } } - // You can also handle it using StatusPage ktor server plugin. + // You can also handle it using the StatusPage ktor server plugin. // but we shouldn't handle all the exceptions in that case else -> { call.respond( diff --git a/library/src/main/kotlin/net/freshplatform/ktor_server/firebase_app_check/services/FirebaseAppCheckTokenVerifierServiceImpl.kt b/library/src/jvmMain/kotlin/net/freshplatform/ktor_server/firebase_app_check/service/FirebaseAppCheckTokenVerifierServiceImpl.kt similarity index 99% rename from library/src/main/kotlin/net/freshplatform/ktor_server/firebase_app_check/services/FirebaseAppCheckTokenVerifierServiceImpl.kt rename to library/src/jvmMain/kotlin/net/freshplatform/ktor_server/firebase_app_check/service/FirebaseAppCheckTokenVerifierServiceImpl.kt index b262e18..43b4280 100644 --- a/library/src/main/kotlin/net/freshplatform/ktor_server/firebase_app_check/services/FirebaseAppCheckTokenVerifierServiceImpl.kt +++ b/library/src/jvmMain/kotlin/net/freshplatform/ktor_server/firebase_app_check/service/FirebaseAppCheckTokenVerifierServiceImpl.kt @@ -1,4 +1,4 @@ -package net.freshplatform.ktor_server.firebase_app_check.services +package net.freshplatform.ktor_server.firebase_app_check.service import com.auth0.jwk.* import com.auth0.jwt.JWT diff --git a/library/src/main/kotlin/net/freshplatform/ktor_server/firebase_app_check/utils/FirebaseAppCheckResponses.kt b/library/src/jvmMain/kotlin/net/freshplatform/ktor_server/firebase_app_check/utils/FirebaseAppCheckResponses.kt similarity index 100% rename from library/src/main/kotlin/net/freshplatform/ktor_server/firebase_app_check/utils/FirebaseAppCheckResponses.kt rename to library/src/jvmMain/kotlin/net/freshplatform/ktor_server/firebase_app_check/utils/FirebaseAppCheckResponses.kt diff --git a/library/src/main/kotlin/net/freshplatform/ktor_server/firebase_app_check/utils/extensions/ApplicationCallExtensions.kt b/library/src/jvmMain/kotlin/net/freshplatform/ktor_server/firebase_app_check/utils/extensions/ApplicationCallExtensions.kt similarity index 97% rename from library/src/main/kotlin/net/freshplatform/ktor_server/firebase_app_check/utils/extensions/ApplicationCallExtensions.kt rename to library/src/jvmMain/kotlin/net/freshplatform/ktor_server/firebase_app_check/utils/extensions/ApplicationCallExtensions.kt index f23c414..2254168 100644 --- a/library/src/main/kotlin/net/freshplatform/ktor_server/firebase_app_check/utils/extensions/ApplicationCallExtensions.kt +++ b/library/src/jvmMain/kotlin/net/freshplatform/ktor_server/firebase_app_check/utils/extensions/ApplicationCallExtensions.kt @@ -7,7 +7,7 @@ import io.ktor.server.response.* import io.ktor.server.routing.* import net.freshplatform.ktor_server.firebase_app_check.FirebaseAppCheckPlugin import net.freshplatform.ktor_server.firebase_app_check.core.FirebaseAppCheckSecureStrategy -import net.freshplatform.ktor_server.firebase_app_check.services.FetchFirebaseAppCheckPublicKeyConfig +import net.freshplatform.ktor_server.firebase_app_check.service.FetchFirebaseAppCheckPublicKeyConfig /** * A suspended function that verifies an incoming Firebase App Check token for an [ApplicationCall]. diff --git a/library/src/test/kotlin/freshplatform/ktor_server/firebase_app_check/ApplicationTest.kt b/library/src/jvmTest/kotlin/net/freshplatform/ktor_server/firebase_app_check/ApplicationTest.kt similarity index 97% rename from library/src/test/kotlin/freshplatform/ktor_server/firebase_app_check/ApplicationTest.kt rename to library/src/jvmTest/kotlin/net/freshplatform/ktor_server/firebase_app_check/ApplicationTest.kt index 6b88a62..dd3bb19 100644 --- a/library/src/test/kotlin/freshplatform/ktor_server/firebase_app_check/ApplicationTest.kt +++ b/library/src/jvmTest/kotlin/net/freshplatform/ktor_server/firebase_app_check/ApplicationTest.kt @@ -1,4 +1,4 @@ -package freshplatform.ktor_server.firebase_app_check +package net.freshplatform.ktor_server.firebase_app_check import io.ktor.client.request.* import io.ktor.client.statement.* @@ -7,11 +7,10 @@ import io.ktor.server.application.* import io.ktor.server.response.* import io.ktor.server.routing.* import io.ktor.server.testing.* -import net.freshplatform.ktor_server.firebase_app_check.FirebaseAppCheckPlugin import net.freshplatform.ktor_server.firebase_app_check.core.FirebaseAppCheckPluginConfiguration import net.freshplatform.ktor_server.firebase_app_check.exceptions.FirebaseAppCheckVerifyJwtErrorType import net.freshplatform.ktor_server.firebase_app_check.exceptions.FirebaseAppCheckVerifyJwtException -import net.freshplatform.ktor_server.firebase_app_check.services.FirebaseAppCheckTokenVerifierService +import net.freshplatform.ktor_server.firebase_app_check.service.FirebaseAppCheckTokenVerifierService import net.freshplatform.ktor_server.firebase_app_check.utils.FirebaseAppCheckMessages import net.freshplatform.ktor_server.firebase_app_check.utils.extensions.protectRouteWithAppCheck import kotlin.test.Test diff --git a/library/src/test/kotlin/freshplatform/ktor_server/firebase_app_check/FirebaseAppCheckTokenVerifierServiceMock.kt b/library/src/jvmTest/kotlin/net/freshplatform/ktor_server/firebase_app_check/FirebaseAppCheckTokenVerifierServiceMock.kt similarity index 90% rename from library/src/test/kotlin/freshplatform/ktor_server/firebase_app_check/FirebaseAppCheckTokenVerifierServiceMock.kt rename to library/src/jvmTest/kotlin/net/freshplatform/ktor_server/firebase_app_check/FirebaseAppCheckTokenVerifierServiceMock.kt index 0482829..955d7bb 100644 --- a/library/src/test/kotlin/freshplatform/ktor_server/firebase_app_check/FirebaseAppCheckTokenVerifierServiceMock.kt +++ b/library/src/jvmTest/kotlin/net/freshplatform/ktor_server/firebase_app_check/FirebaseAppCheckTokenVerifierServiceMock.kt @@ -1,4 +1,4 @@ -package freshplatform.ktor_server.firebase_app_check +package net.freshplatform.ktor_server.firebase_app_check import com.auth0.jwt.JWT import com.auth0.jwt.exceptions.JWTDecodeException @@ -6,8 +6,8 @@ import com.auth0.jwt.interfaces.DecodedJWT import kotlinx.coroutines.delay import net.freshplatform.ktor_server.firebase_app_check.exceptions.FirebaseAppCheckVerifyJwtErrorType import net.freshplatform.ktor_server.firebase_app_check.exceptions.FirebaseAppCheckVerifyJwtException -import net.freshplatform.ktor_server.firebase_app_check.services.FetchFirebaseAppCheckPublicKeyConfig -import net.freshplatform.ktor_server.firebase_app_check.services.FirebaseAppCheckTokenVerifierService +import net.freshplatform.ktor_server.firebase_app_check.service.FetchFirebaseAppCheckPublicKeyConfig +import net.freshplatform.ktor_server.firebase_app_check.service.FirebaseAppCheckTokenVerifierService import java.security.PublicKey import kotlin.time.Duration.Companion.milliseconds @@ -64,7 +64,6 @@ class FirebaseAppCheckTokenVerifierServiceMock : FirebaseAppCheckTokenVerifierSe } return verified } catch (e: JWTDecodeException) { - println("Fuck: $e") throw FirebaseAppCheckVerifyJwtException( "Token is not valid: $e", errorType = FirebaseAppCheckVerifyJwtErrorType.TokenIsNotValid diff --git a/library/src/test/kotlin/freshplatform/ktor_server/firebase_app_check/TestConstants.kt b/library/src/jvmTest/kotlin/net/freshplatform/ktor_server/firebase_app_check/TestConstants.kt similarity index 95% rename from library/src/test/kotlin/freshplatform/ktor_server/firebase_app_check/TestConstants.kt rename to library/src/jvmTest/kotlin/net/freshplatform/ktor_server/firebase_app_check/TestConstants.kt index 611e099..f49e654 100644 --- a/library/src/test/kotlin/freshplatform/ktor_server/firebase_app_check/TestConstants.kt +++ b/library/src/jvmTest/kotlin/net/freshplatform/ktor_server/firebase_app_check/TestConstants.kt @@ -1,4 +1,4 @@ -package freshplatform.ktor_server.firebase_app_check +package net.freshplatform.ktor_server.firebase_app_check object TestConstants { const val FIREBASE_PROJECT_ID = "mynotes-eb717" diff --git a/scripts/before-push.sh b/scripts/before-push.sh new file mode 100755 index 0000000..f248195 --- /dev/null +++ b/scripts/before-push.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +echo "Build with Gradle..." +echo "" +./gradlew build \ No newline at end of file diff --git a/settings.gradle.kts b/settings.gradle.kts index fb4827f..0e31d1f 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -4,12 +4,14 @@ rootProject.name = "FirebaseAppCheck" include(":example", ":library") pluginManagement { + plugins { val kotlinVersion = extra["kotlin.version"] as String - val ktorVersion = extra["ktor.version"] as String +// val ktorVersion = extra["ktor.version"] as String - kotlin("jvm").version(kotlinVersion).apply(false) - id("io.ktor.plugin").version(ktorVersion).apply(false) - id("org.jetbrains.kotlin.plugin.serialization").version(kotlinVersion).apply(false) // For the `example` + kotlin("multiplatform") version(kotlinVersion) apply(false) +// kotlin("jvm") version(kotlinVersion) apply(false) +// id("io.ktor.plugin") version(ktorVersion) apply(false) + id("org.jetbrains.kotlin.plugin.serialization") version(kotlinVersion) apply(false) // For the `example` } } \ No newline at end of file