Skip to content

Commit 6cc12f0

Browse files
committed
chore: bump the server version to 0.0.5
1 parent 09e6097 commit 6cc12f0

3 files changed

Lines changed: 33 additions & 3 deletions

File tree

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ plugins {
88
}
99

1010
group = "com.sakethh"
11-
version = "0.0.4"
11+
version = "0.0.5"
1212

1313
application {
1414
mainClass.set("com.sakethh.linkora.ApplicationKt")
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
package com.sakethh.linkora
22

33
object Constants {
4-
const val SERVER_VERSION = "0.0.4"
4+
const val SERVER_VERSION = "0.0.5"
55
}

src/main/kotlin/com/sakethh/linkora/Security.kt

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,32 @@ package com.sakethh.linkora
22

33
import io.ktor.http.*
44
import io.ktor.server.application.*
5-
import io.ktor.server.request.path
5+
import io.ktor.server.request.*
66
import io.ktor.server.response.*
77
import io.ktor.server.routing.*
88

9+
10+
/*
11+
in RoutingNode's `buildPipeline()`, the following is implemented:
12+
13+
for (index in 0..handlers.lastIndex) {
14+
pipeline.intercept(Call) {
15+
val call = call as RoutingPipelineCall
16+
val routingCall = RoutingCall(call)
17+
val routingContext = RoutingContext(routingCall)
18+
if (call.isHandled) return@intercept
19+
handlers[index].invoke(routingContext)
20+
}
21+
}
22+
23+
so if a call is handled here in this `Security.kt` file,
24+
the handler of our routes (defined in routing files) is never reached;
25+
which is exactly what we want.
26+
27+
I've gone through the Ktor auth library (just the surface), and it defines an extension function
28+
`Route.authenticate` (same name) in `AuthenticationInterceptors.kt` that does almost the same thing.
29+
It doesn't directly send a 403 like I'm doing here, but for our scenario, this is fine.
30+
*/
931
val CustomBearerAuth = createRouteScopedPlugin(name = "CustomBearerAuth") {
1032
onCall { call ->
1133
val rawHeader = call.request.headers[HttpHeaders.Authorization]
@@ -57,6 +79,14 @@ fun Route.authenticate(initOnSuccess: Route.() -> Unit) {
5779
}
5880

5981
/*
82+
83+
i should have just used `authHeader` and it probably would've fixed the special characters in token = 401 issue
84+
85+
but this does pretty much the same thing, and I learnt a couple of new things, so hell yeahh
86+
87+
--------------------------------------------
88+
89+
6090
with the auth lib, something like this would have worked:
6191
6292
install(Authentication) {

0 commit comments

Comments
 (0)