https://kotlinlang.org logo
Title
p

Peter

04/27/2022, 5:27 PM
attempting to migrate to Ktor 2: any idea what happened to
Authentication.ChallengePhase
?
i see:
internal object ChallengeHook : Hook<suspend (ApplicationCall) -> Unit> {
    internal val ChallengePhase: PipelinePhase = PipelinePhase("Challenge")
but it's
internal
😞
r

Ron S

04/27/2022, 5:32 PM
yeah I also had the same issue when implementing role system, haven't solved it so far 😞
😞 1
p

Peter

04/27/2022, 5:33 PM
PipelinePhase
isn't a data class either... so assuming just redeclaring an instance won't compare equally the internal one?
r

Ron S

04/27/2022, 5:53 PM
PipelinePhase("Challenge")
creating my own instance of it might actually work, but I have no idea how to test it. the interceptor triggers and there is no excption being thrown
it would also be sufficient when the interceptor fires after the authentication in general, doesnt have to be the Challenge phase, does it?
a

Aleksei Tirman [JB]

04/28/2022, 1:31 AM
@Rustam Siniukov
r

Rustam Siniukov

04/28/2022, 8:02 AM
@Peter Can you share your use case, please?
@Ron S for role based auth you can use
AuthenticationChecked
hook
r

Ron S

04/28/2022, 8:47 AM
Thanks @Rustam Siniukov I think I got it to work. Here's my snippet @Peter
fun Route.authorization(build: Route.() -> Unit): Route {
    val route = createChild(CustomSelector())
    val plugin = createRouteScopedPlugin("CustomAuthorization") {
        on(AuthenticationChecked) { call ->
            val principal = call.authentication.principal
            // custom logic
        }
    }
    route.install(plugin)
    route.build()
    return route
}
👍 1
p

Peter

04/28/2022, 2:21 PM
my use case is also a RBAC feature/plugin... thanks for the example @Ron S - i'll take a look soon, traveling today