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

Matvei Vdovitsyn

05/01/2021, 7:11 PM
Why may Ktor Authentication feature's authenticated route handlers be executed with empty principal, despite of not being optional? Code further in thread
Copy code
routing {
    authenticate("vk") {
        location<login>(){
              //... endpoint i use for communication with oAuth2 service
        }
        get("locked"){
            val principal = call.authentication.principal<OAuthAccessTokenResponse.OAuth2>() //principal is null, why?
            call.respondText {
                "Oh hi mark!"
            }
        }
    }
}
There is an issue in multiple samples in github of Ktor, that is being fixed, by, as I think, a hack with session == null -> redirect in every endpoint, because OAuthProvider with providerLookup returning null is just being ignored.
s

Stylianos Gakis

06/24/2021, 8:56 AM
I'm also experiencing this behaviour, what approach did you take to solve it afterall? Does it happen to be as part of an open sourced project I can take a look at?
11 Views