From a87b92c2f446e36dba49138a20b3bf0ff010fe80 Mon Sep 17 00:00:00 2001 From: Ellet Date: Sat, 2 Dec 2023 08:49:06 +0300 Subject: [PATCH] Not ready yet --- example/build.gradle.kts | 64 +++++--------- .../src/jvmMain/kotlin/plugins/AppCheck.kt | 26 ------ .../{jvmMain => main}/kotlin/Application.kt | 0 example/src/main/kotlin/plugins/AppCheck.kt | 28 ++++++ .../{jvmMain => main}/kotlin/plugins/HTTP.kt | 0 .../kotlin/plugins/Routing.kt | 32 +++---- .../kotlin/plugins/Security.kt | 0 .../kotlin/plugins/Serialization.kt | 0 .../{jvmMain => main}/resources/logback.xml | 0 .../kotlin/ApplicationTest.kt | 0 gradle.properties | 15 +--- gradle/libs.versions.toml | 25 +++++- library/build.gradle.kts | 75 ++++++++-------- .../firebase_app_check/FirebaseAppCheck.kt | 5 +- .../FirebaseAppCheckPluginConfiguration.kt | 4 +- .../core/FirebaseAppCheckSecureStrategy.kt | 4 +- .../FirebaseAppCheckTokenVerifierService.kt | 20 +++++ .../services/jwt/DecodedJwt.kt | 88 +++++++++++++++++++ .../utils/FirebaseAppCheckResponses.kt | 0 .../extensions/ApplicationCallExtensions.kt | 0 ...irebaseAppCheckTokenVerifierServiceImpl.kt | 4 +- .../services/jwt/DecodedJwt.kt | 6 ++ settings.gradle.kts | 18 ++-- 23 files changed, 257 insertions(+), 157 deletions(-) delete mode 100644 example/src/jvmMain/kotlin/plugins/AppCheck.kt rename example/src/{jvmMain => main}/kotlin/Application.kt (100%) create mode 100644 example/src/main/kotlin/plugins/AppCheck.kt rename example/src/{jvmMain => main}/kotlin/plugins/HTTP.kt (100%) rename example/src/{jvmMain => main}/kotlin/plugins/Routing.kt (61%) rename example/src/{jvmMain => main}/kotlin/plugins/Security.kt (100%) rename example/src/{jvmMain => main}/kotlin/plugins/Serialization.kt (100%) rename example/src/{jvmMain => main}/resources/logback.xml (100%) rename example/src/{jvmTest => test}/kotlin/ApplicationTest.kt (100%) rename library/src/{jvmMain => commonMain}/kotlin/net/freshplatform/ktor_server/firebase_app_check/FirebaseAppCheck.kt (93%) rename library/src/{jvmMain => commonMain}/kotlin/net/freshplatform/ktor_server/firebase_app_check/core/FirebaseAppCheckPluginConfiguration.kt (97%) create mode 100644 library/src/commonMain/kotlin/net/freshplatform/ktor_server/firebase_app_check/services/jwt/DecodedJwt.kt rename library/src/{jvmMain => commonMain}/kotlin/net/freshplatform/ktor_server/firebase_app_check/utils/FirebaseAppCheckResponses.kt (100%) rename library/src/{jvmMain => commonMain}/kotlin/net/freshplatform/ktor_server/firebase_app_check/utils/extensions/ApplicationCallExtensions.kt (100%) rename library/src/jvmMain/kotlin/net/freshplatform/ktor_server/firebase_app_check/{service => services}/FirebaseAppCheckTokenVerifierServiceImpl.kt (97%) create mode 100644 library/src/jvmMain/kotlin/net/freshplatform/ktor_server/firebase_app_check/services/jwt/DecodedJwt.kt diff --git a/example/build.gradle.kts b/example/build.gradle.kts index f9988f8..ba99cec 100644 --- a/example/build.gradle.kts +++ b/example/build.gradle.kts @@ -1,14 +1,11 @@ -val kotlinVersion = extra["kotlin.version"] as String -val ktorVersion = extra["ktor.version"] as String -val logbackVersion = extra["logback.version"] as String -val auth0JwksRsaVersion = extra["auth0JwksRsa.version"] as String -val auth0JavaJwtVersion = extra["auth0JavaJwt.version"] as String +val kotlinVersion = libs.versions.kotlin.get() +val ktorVersion = libs.versions.ktor.get() +val logbackVersion = libs.versions.logback.get() plugins { - kotlin("multiplatform") -// id("io.ktor.plugin") + alias(libs.plugins.kotlin.jvm) application - id("org.jetbrains.kotlin.plugin.serialization") + alias(libs.plugins.kotlinx.serialization) } group = "net.freshplatform" @@ -23,43 +20,22 @@ application { repositories { mavenCentral() - val jitpackGroupId = "com.github.freshtechtips" - maven { - name = "jitpack" - setUrl("https://jitpack.io") - content { includeGroup(jitpackGroupId) } - } } -kotlin { - jvm() +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") - 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") - } - } - } + testImplementation("io.ktor:ktor-server-tests-jvm:$ktorVersion") + testImplementation("org.jetbrains.kotlin:kotlin-test-junit:$kotlinVersion") + implementation(project(":library")) } \ No newline at end of file diff --git a/example/src/jvmMain/kotlin/plugins/AppCheck.kt b/example/src/jvmMain/kotlin/plugins/AppCheck.kt deleted file mode 100644 index d4a602c..0000000 --- a/example/src/jvmMain/kotlin/plugins/AppCheck.kt +++ /dev/null @@ -1,26 +0,0 @@ -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/jvmMain/kotlin/Application.kt b/example/src/main/kotlin/Application.kt similarity index 100% rename from example/src/jvmMain/kotlin/Application.kt rename to example/src/main/kotlin/Application.kt diff --git a/example/src/main/kotlin/plugins/AppCheck.kt b/example/src/main/kotlin/plugins/AppCheck.kt new file mode 100644 index 0000000..ecdc45a --- /dev/null +++ b/example/src/main/kotlin/plugins/AppCheck.kt @@ -0,0 +1,28 @@ +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.services.FirebaseAppCheckTokenVerifierServiceImpl +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 + serviceImpl = FirebaseAppCheckTokenVerifierServiceImpl() + 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/jvmMain/kotlin/plugins/HTTP.kt b/example/src/main/kotlin/plugins/HTTP.kt similarity index 100% rename from example/src/jvmMain/kotlin/plugins/HTTP.kt rename to example/src/main/kotlin/plugins/HTTP.kt diff --git a/example/src/jvmMain/kotlin/plugins/Routing.kt b/example/src/main/kotlin/plugins/Routing.kt similarity index 61% rename from example/src/jvmMain/kotlin/plugins/Routing.kt rename to example/src/main/kotlin/plugins/Routing.kt index b2ed5f8..6769667 100644 --- a/example/src/jvmMain/kotlin/plugins/Routing.kt +++ b/example/src/main/kotlin/plugins/Routing.kt @@ -5,7 +5,7 @@ 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/jvmMain/kotlin/plugins/Security.kt b/example/src/main/kotlin/plugins/Security.kt similarity index 100% rename from example/src/jvmMain/kotlin/plugins/Security.kt rename to example/src/main/kotlin/plugins/Security.kt diff --git a/example/src/jvmMain/kotlin/plugins/Serialization.kt b/example/src/main/kotlin/plugins/Serialization.kt similarity index 100% rename from example/src/jvmMain/kotlin/plugins/Serialization.kt rename to example/src/main/kotlin/plugins/Serialization.kt diff --git a/example/src/jvmMain/resources/logback.xml b/example/src/main/resources/logback.xml similarity index 100% rename from example/src/jvmMain/resources/logback.xml rename to example/src/main/resources/logback.xml diff --git a/example/src/jvmTest/kotlin/ApplicationTest.kt b/example/src/test/kotlin/ApplicationTest.kt similarity index 100% rename from example/src/jvmTest/kotlin/ApplicationTest.kt rename to example/src/test/kotlin/ApplicationTest.kt diff --git a/gradle.properties b/gradle.properties index c86e89f..29e08e8 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,14 +1 @@ -kotlin.code.style=official - -# Versions - -# Shared -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 \ No newline at end of file +kotlin.code.style=official \ No newline at end of file diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 6ed4ba9..35f03a9 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,5 +1,28 @@ [versions] +kotlin = "1.9.21" +ktor = "2.3.6" +library = "0.0.5-dev" + +# Example +logback = "1.4.11" + +# Library +auth0-java-jwt = "4.4.0" +auth0-java-jwksRsa = "0.22.1" + +kotlinx-coroutines = "1.7.3" +kotlinx-serialization = "1.6.2" [libraries] +kotlin-test = { module = "org.jetbrains.kotlin:kotlin-test", 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" } + +# JVM +auth0-java-jwt = { module = "com.auth0:java-jwt", version.ref = "auth0-java-jwt" } +auth0-java-jwksRsa = { module = "com.auth0:jwks-rsa", version.ref = "auth0-java-jwksRsa" } -[plugins] \ No newline at end of file +[plugins] +kotlin-multiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" } +kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" } +kotlinx-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" } \ No newline at end of file diff --git a/library/build.gradle.kts b/library/build.gradle.kts index 9906841..b1e0639 100644 --- a/library/build.gradle.kts +++ b/library/build.gradle.kts @@ -1,33 +1,30 @@ -val kotlinVersion = extra["kotlin.version"] as String -val ktorVersion = extra["ktor.version"] as String -val auth0JwksRsaVersion = extra["auth0JwksRsa.version"] as String -val auth0JavaJwtVersion = extra["auth0JavaJwt.version"] as String - plugins { - kotlin("multiplatform") - application + alias(libs.plugins.kotlin.multiplatform) +// application id("maven-publish") - id("java-library") +// id("java-library") } +val kotlinVersion = libs.versions.kotlin.get() +val ktorVersion = libs.versions.ktor.get() + group = "net.freshplatform" -version = "0.0.5-dev" +version = libs.versions.library.get() 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}.ktor_server.firebase_app_check.FirebaseAppCheckKt") -} +//application { +// mainClass.set("${group}.ktor_server.firebase_app_check.FirebaseAppCheckKt") +//} kotlin { - jvm { - jvmToolchain(17) - } + jvm() sourceSets { val commonMain by getting { dependencies { implementation("io.ktor:ktor-server-core:$ktorVersion") + implementation(libs.kotlinx.coroutines) } } val commonTest by getting { @@ -38,8 +35,8 @@ kotlin { 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(libs.auth0.java.jwt) + implementation(libs.auth0.java.jwksRsa) // implementation("io.ktor:ktor-server-auth-jwt-jvm") } } @@ -61,25 +58,25 @@ repositories { mavenCentral() } -publishing { - - val jitpackGroupId = "com.github.freshtechtips" - - publications { - create("jitpack") { - from(components["java"]) - - groupId = jitpackGroupId - artifactId = "ktor-server-firebase-app-check" - version = project.version.toString() - } - } - - repositories { - maven { - name = "jitpack" - setUrl("https://jitpack.io") - content { includeGroup(jitpackGroupId) } - } - } -} \ No newline at end of file +//publishing { +// +// val jitpackGroupId = "com.github.freshtechtips" +// +// publications { +// create("jitpack") { +// from(components["java"]) +// +// groupId = jitpackGroupId +// artifactId = "ktor-server-firebase-app-check" +// version = project.version.toString() +// } +// } +// +// repositories { +// maven { +// name = "jitpack" +// setUrl("https://jitpack.io") +// content { includeGroup(jitpackGroupId) } +// } +// } +//} \ No newline at end of file diff --git a/library/src/jvmMain/kotlin/net/freshplatform/ktor_server/firebase_app_check/FirebaseAppCheck.kt b/library/src/commonMain/kotlin/net/freshplatform/ktor_server/firebase_app_check/FirebaseAppCheck.kt similarity index 93% rename from library/src/jvmMain/kotlin/net/freshplatform/ktor_server/firebase_app_check/FirebaseAppCheck.kt rename to library/src/commonMain/kotlin/net/freshplatform/ktor_server/firebase_app_check/FirebaseAppCheck.kt index d351974..dd8ed7d 100644 --- a/library/src/jvmMain/kotlin/net/freshplatform/ktor_server/firebase_app_check/FirebaseAppCheck.kt +++ b/library/src/commonMain/kotlin/net/freshplatform/ktor_server/firebase_app_check/FirebaseAppCheck.kt @@ -5,6 +5,7 @@ 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.service.FirebaseAppCheckTokenVerifierServiceUnimplemented import net.freshplatform.ktor_server.firebase_app_check.utils.extensions.verifyAppTokenRequest /** @@ -27,7 +28,9 @@ class FirebaseAppCheckPlugin( pipeline: ApplicationCallPipeline, configure: FirebaseAppCheckPluginConfiguration.() -> Unit ): FirebaseAppCheckPlugin { - val configuration = FirebaseAppCheckPluginConfiguration() + val configuration = FirebaseAppCheckPluginConfiguration( + serviceImpl = FirebaseAppCheckTokenVerifierServiceUnimplemented() + ) .apply(configure) require(configuration.firebaseProjectNumber.isNotBlank()) { "The firebase project number should not be blank." diff --git a/library/src/jvmMain/kotlin/net/freshplatform/ktor_server/firebase_app_check/core/FirebaseAppCheckPluginConfiguration.kt b/library/src/commonMain/kotlin/net/freshplatform/ktor_server/firebase_app_check/core/FirebaseAppCheckPluginConfiguration.kt similarity index 97% rename from library/src/jvmMain/kotlin/net/freshplatform/ktor_server/firebase_app_check/core/FirebaseAppCheckPluginConfiguration.kt rename to library/src/commonMain/kotlin/net/freshplatform/ktor_server/firebase_app_check/core/FirebaseAppCheckPluginConfiguration.kt index 9789e5d..1fcf967 100644 --- a/library/src/jvmMain/kotlin/net/freshplatform/ktor_server/firebase_app_check/core/FirebaseAppCheckPluginConfiguration.kt +++ b/library/src/commonMain/kotlin/net/freshplatform/ktor_server/firebase_app_check/core/FirebaseAppCheckPluginConfiguration.kt @@ -11,8 +11,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.FirebaseAppCheckVerifyJwtException 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 +import net.freshplatform.ktor_server.firebase_app_check.utils.extensions.protectRouteWithAppCheck /** * Configuration class for Firebase App Check plugin. @@ -176,7 +176,7 @@ class FirebaseAppCheckPluginConfiguration( pluginConfiguration = it ) }, - var serviceImpl: FirebaseAppCheckTokenVerifierService = FirebaseAppCheckTokenVerifierServiceImpl(), + var serviceImpl: FirebaseAppCheckTokenVerifierService, ) { /** diff --git a/library/src/commonMain/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 index f16dac1..96152a9 100644 --- a/library/src/commonMain/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,10 +1,12 @@ 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 a specific routes in the app use [FirebaseAppCheckSecureStrategy.ProtectSpecificRoutes] - * * and then protect the routes in the routing by surround them with [protectRouteWithAppCheck] // TODO: Import this + * * and then protect the routes in the routing by surround them with [protectRouteWithAppCheck] * if you want to protect routes by the path of the route as string use * [FirebaseAppCheckSecureStrategy.ProtectRoutesByPaths] */ diff --git a/library/src/commonMain/kotlin/net/freshplatform/ktor_server/firebase_app_check/service/FirebaseAppCheckTokenVerifierService.kt b/library/src/commonMain/kotlin/net/freshplatform/ktor_server/firebase_app_check/service/FirebaseAppCheckTokenVerifierService.kt index 1d6b42b..a2f099e 100644 --- a/library/src/commonMain/kotlin/net/freshplatform/ktor_server/firebase_app_check/service/FirebaseAppCheckTokenVerifierService.kt +++ b/library/src/commonMain/kotlin/net/freshplatform/ktor_server/firebase_app_check/service/FirebaseAppCheckTokenVerifierService.kt @@ -78,4 +78,24 @@ interface FirebaseAppCheckTokenVerifierService { firebaseProjectNumber: String, issuerBaseUrl: String ): DecodedJWT +} + +class FirebaseAppCheckTokenVerifierServiceUnimplemented: FirebaseAppCheckTokenVerifierService { + override suspend fun fetchFirebaseAppCheckPublicKey( + jwtString: String, + url: String, + config: FetchFirebaseAppCheckPublicKeyConfig + ): PublicKey { + TODO("Not yet implemented") + } + + override suspend fun verifyFirebaseAppCheckToken( + jwtString: String, + publicKey: PublicKey, + firebaseProjectId: String, + firebaseProjectNumber: String, + issuerBaseUrl: String + ): DecodedJWT { + TODO("Not yet implemented") + } } \ No newline at end of file diff --git a/library/src/commonMain/kotlin/net/freshplatform/ktor_server/firebase_app_check/services/jwt/DecodedJwt.kt b/library/src/commonMain/kotlin/net/freshplatform/ktor_server/firebase_app_check/services/jwt/DecodedJwt.kt new file mode 100644 index 0000000..575e7ee --- /dev/null +++ b/library/src/commonMain/kotlin/net/freshplatform/ktor_server/firebase_app_check/services/jwt/DecodedJwt.kt @@ -0,0 +1,88 @@ +package net.freshplatform.ktor_server.firebase_app_check.services.jwt + +import com.auth0.jwt.interfaces.Claim +import java.time.DateTimeException +import java.time.Instant +import java.util.* + +fun main() { + +} + +data class DecodedJwt( + val token: String, + val header: String, + val payload: String, + val signature: String +) + +data class JwtPayload( + val issuer: String, + val subject: String, + val audience: String, + val expiresAt: Long, + val notBefore: Long, + val issuedAt: Long, + val id: String, + val getClaim: () -> Unit, + val claims: Map?, +) + +interface PayloadBase { + + /** + * Get a Claim given its name. If the Claim wasn't specified in the Payload, a 'null claim' + * will be returned. All the methods of that claim will return `null`. + * + * @param name the name of the Claim to retrieve. + * @return a non-null Claim. + */ + fun getClaim(name: String?): Claim? + + /** + * Get the Claims defined in the Token. + * + * @return a non-null Map containing the Claims defined in the Token. + */ + val claims: Map? +} + +interface HeaderBase { + + /** + * Getter for the Algorithm "alg" claim defined in the JWT's Header. If the claim is missing, it will return null. + * + * @return the Algorithm defined or null. + */ + fun getAlgorithm(): String? + + /** + * Getter for the Type "typ" claim defined in the JWT's Header. If the claim is missing, it will return null. + * + * @return the Type defined or null. + */ + fun getType(): String? + + /** + * Getter for the Content Type "cty" claim defined in the JWT's Header. If the claim is missing, it will return null. + * + * @return the Content Type defined or null. + */ + fun getContentType(): String? + + /** + * Get the value of the "kid" claim, or null if it's not available. + * + * @return the Key ID value or null. + */ + fun getKeyId(): String? + + /** + * Get a Private Claim given its name. If the Claim wasn't specified in the Header, a 'null claim' will be + * returned. All the methods of that claim will return `null`. + * + * @param name the name of the Claim to retrieve. + * @return a non-null Claim. + */ + fun getHeaderClaim(name: String?): Claim? +} \ No newline at end of file diff --git a/library/src/jvmMain/kotlin/net/freshplatform/ktor_server/firebase_app_check/utils/FirebaseAppCheckResponses.kt b/library/src/commonMain/kotlin/net/freshplatform/ktor_server/firebase_app_check/utils/FirebaseAppCheckResponses.kt similarity index 100% rename from library/src/jvmMain/kotlin/net/freshplatform/ktor_server/firebase_app_check/utils/FirebaseAppCheckResponses.kt rename to library/src/commonMain/kotlin/net/freshplatform/ktor_server/firebase_app_check/utils/FirebaseAppCheckResponses.kt diff --git a/library/src/jvmMain/kotlin/net/freshplatform/ktor_server/firebase_app_check/utils/extensions/ApplicationCallExtensions.kt b/library/src/commonMain/kotlin/net/freshplatform/ktor_server/firebase_app_check/utils/extensions/ApplicationCallExtensions.kt similarity index 100% rename from library/src/jvmMain/kotlin/net/freshplatform/ktor_server/firebase_app_check/utils/extensions/ApplicationCallExtensions.kt rename to library/src/commonMain/kotlin/net/freshplatform/ktor_server/firebase_app_check/utils/extensions/ApplicationCallExtensions.kt diff --git a/library/src/jvmMain/kotlin/net/freshplatform/ktor_server/firebase_app_check/service/FirebaseAppCheckTokenVerifierServiceImpl.kt b/library/src/jvmMain/kotlin/net/freshplatform/ktor_server/firebase_app_check/services/FirebaseAppCheckTokenVerifierServiceImpl.kt similarity index 97% rename from library/src/jvmMain/kotlin/net/freshplatform/ktor_server/firebase_app_check/service/FirebaseAppCheckTokenVerifierServiceImpl.kt rename to library/src/jvmMain/kotlin/net/freshplatform/ktor_server/firebase_app_check/services/FirebaseAppCheckTokenVerifierServiceImpl.kt index 43b4280..829d3d0 100644 --- a/library/src/jvmMain/kotlin/net/freshplatform/ktor_server/firebase_app_check/service/FirebaseAppCheckTokenVerifierServiceImpl.kt +++ b/library/src/jvmMain/kotlin/net/freshplatform/ktor_server/firebase_app_check/services/FirebaseAppCheckTokenVerifierServiceImpl.kt @@ -1,4 +1,4 @@ -package net.freshplatform.ktor_server.firebase_app_check.service +package net.freshplatform.ktor_server.firebase_app_check.services import com.auth0.jwk.* import com.auth0.jwt.JWT @@ -11,6 +11,8 @@ import net.freshplatform.ktor_server.firebase_app_check.exceptions.FirebaseAppCh import net.freshplatform.ktor_server.firebase_app_check.exceptions.FirebaseAppCheckFetchPublicKeyException 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.service.FetchFirebaseAppCheckPublicKeyConfig +import net.freshplatform.ktor_server.firebase_app_check.service.FirebaseAppCheckTokenVerifierService import java.net.URL import java.security.PublicKey import java.security.interfaces.RSAPublicKey diff --git a/library/src/jvmMain/kotlin/net/freshplatform/ktor_server/firebase_app_check/services/jwt/DecodedJwt.kt b/library/src/jvmMain/kotlin/net/freshplatform/ktor_server/firebase_app_check/services/jwt/DecodedJwt.kt new file mode 100644 index 0000000..4763e06 --- /dev/null +++ b/library/src/jvmMain/kotlin/net/freshplatform/ktor_server/firebase_app_check/services/jwt/DecodedJwt.kt @@ -0,0 +1,6 @@ +package net.freshplatform.ktor_server.firebase_app_check.services.jwt + +import com.auth0.jwt.interfaces.Claim +import com.auth0.jwt.interfaces.DecodedJWT +import java.util.* + diff --git a/settings.gradle.kts b/settings.gradle.kts index 0e31d1f..aee053f 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,17 +1,11 @@ -import org.gradle.kotlin.dsl.extra - rootProject.name = "FirebaseAppCheck" -include(":example", ":library") - -pluginManagement { - plugins { - val kotlinVersion = extra["kotlin.version"] as String -// val ktorVersion = extra["ktor.version"] as String +include(":library") +include(":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` +pluginManagement { + repositories { + mavenCentral() + gradlePluginPortal() } } \ No newline at end of file