Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
30 changes: 13 additions & 17 deletions example/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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"))
}
23 changes: 13 additions & 10 deletions example/src/main/kotlin/Application.kt
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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() {
Expand Down
28 changes: 20 additions & 8 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,22 +1,34 @@
[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"

# 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" }
Expand Down
16 changes: 5 additions & 11 deletions library/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,42 +3,36 @@ 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 =
"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."

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)
}
}
}
Expand All @@ -65,4 +59,4 @@ kotlin {
// content { includeGroup(jitpackGroupId) }
// }
// }
//}
//}
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

}
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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) { _ ->
Expand All @@ -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
}

Expand Down