Skip to content

Commit

Permalink
Prepare for KMP
Browse files Browse the repository at this point in the history
  • Loading branch information
Ellet committed Nov 26, 2023
1 parent 32de9e8 commit e6569bc
Show file tree
Hide file tree
Showing 30 changed files with 201 additions and 126 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 18 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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

Expand All @@ -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

Expand Down
55 changes: 35 additions & 20 deletions example/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,24 @@ 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")
}

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")
}

repositories {
mavenCentral()
// mavenLocal()
val jitpackGroupId = "com.github.freshtechtips"
maven {
name = "jitpack"
Expand All @@ -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")
}
}
}
}
Original file line number Diff line number Diff line change
@@ -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(
Expand Down
26 changes: 26 additions & 0 deletions example/src/jvmMain/kotlin/plugins/AppCheck.kt
Original file line number Diff line number Diff line change
@@ -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"
// ),
// )
// }
// }
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package net.freshplatform.plugins
package plugins

import io.ktor.http.*
import io.ktor.http.content.*
Expand Down
Original file line number Diff line number Diff line change
@@ -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.")
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!" }
// }
// }
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package net.freshplatform.plugins
package plugins

import io.ktor.server.application.*

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package net.freshplatform.plugins
package plugins

import io.ktor.serialization.kotlinx.json.*
import io.ktor.server.application.*
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -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
Expand Down
26 changes: 0 additions & 26 deletions example/src/main/kotlin/net/freshplatform/plugins/AppCheck.kt

This file was deleted.

7 changes: 4 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[versions]

[libraries]

[plugins]
Loading

0 comments on commit e6569bc

Please sign in to comment.