https://kotlinlang.org logo
#ktor
Title
j

jeremy

03/28/2018, 11:03 PM
What is the best format for installing auth across multiple routes but not all routes inside of routing {}?
n

neworldlt

03/29/2018, 6:35 AM
I created my own helper function:
Copy code
fun Route.userAuth(kodein: Kodein, path: String = "", build: Route.() -> Route) {
    route(path) {
        authentication {
            ....
        }
        build()
    }
}
And use it in cases I am needed:
Copy code
userAuth(kodein,"/user/current") {
                get {
                    call.respond(UserController(kodein).current(call.userId))
                }
            }
Hope it helps to you
o

orangy

03/29/2018, 2:33 PM
Next build will have a revamped auth DSL, you can try it with 0.9.2-alpha-4 when it’s out (soon).
n

neworldlt

03/29/2018, 2:38 PM
It looks promising:
<https://github.com/ktorio/ktor/blob/master/ktor-samples/ktor-samples-auth/src/io/ktor/samples/auth/JwtApplication.kt#L33>
👌
o

orangy

03/29/2018, 3:29 PM
0.9.2-alpha-5 (previous build failed)
j

jeremy

03/29/2018, 6:29 PM
@orangy Thanks, I noticed this this morning from an issue. 👍
2 Views