Skip to content

Commit

Permalink
Not ready yet
Browse files Browse the repository at this point in the history
  • Loading branch information
Ellet committed Dec 2, 2023
1 parent 1073b85 commit a87b92c
Show file tree
Hide file tree
Showing 23 changed files with 257 additions and 157 deletions.
64 changes: 20 additions & 44 deletions example/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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"))
}
26 changes: 0 additions & 26 deletions example/src/jvmMain/kotlin/plugins/AppCheck.kt

This file was deleted.

File renamed without changes.
28 changes: 28 additions & 0 deletions example/src/main/kotlin/plugins/AppCheck.kt
Original file line number Diff line number Diff line change
@@ -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"
),
)
}
}
}
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
Expand All @@ -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." }
Expand All @@ -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!" }
}
}
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
15 changes: 1 addition & 14 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -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
kotlin.code.style=official
25 changes: 24 additions & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -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]
[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" }
75 changes: 36 additions & 39 deletions library/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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")
}
}
Expand All @@ -61,25 +58,25 @@ repositories {
mavenCentral()
}

publishing {

val jitpackGroupId = "com.github.freshtechtips"

publications {
create<MavenPublication>("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) }
}
}
}
//publishing {
//
// val jitpackGroupId = "com.github.freshtechtips"
//
// publications {
// create<MavenPublication>("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) }
// }
// }
//}
Original file line number Diff line number Diff line change
Expand Up @@ -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

/**
Expand All @@ -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."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -176,7 +176,7 @@ class FirebaseAppCheckPluginConfiguration(
pluginConfiguration = it
)
},
var serviceImpl: FirebaseAppCheckTokenVerifierService = FirebaseAppCheckTokenVerifierServiceImpl(),
var serviceImpl: FirebaseAppCheckTokenVerifierService,
) {

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -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]
*/
Expand Down
Loading

0 comments on commit a87b92c

Please sign in to comment.