Does anyone know why the example "/works-fine" rou...
# ktor
e
Does anyone know why the example "/works-fine" route actually redirects to the google oauth flow, but the "/auth/login" route does not, and isn't considered as behind authentication?
Copy code
fun Application.privateRoutes() {
    routing {
        authenticate("auth-oauth-google") {
            applicationAuthRoutes()
            get("works-fine") {
                // Actually redirects to google oauth flow
            }
        }
    }
}
Copy code
fun Routing.applicationAuthRoutes() {
    route("/auth") {
        authLogin()
        authCallback()
    }
}
Copy code
fun Route.authLogin() {
    get("/login") {
        // Redirection to Google OAuth Flow should happen automatically, but for some reason this route is not behind authentication
    }
}
Copy code
fun Route.authCallback() {
    get("/callback") {
        // This route neither
    }
}
c
Setup seems fine. Only difference is see is the leading
/
that is not part of your
works-fine
e
Unfortunately that's not the issue
c
Is the route not reachable or is it just the „redirect“
e
The route is reachable, it's just not redirecting as it should. (Like it says in the google oauth module's docs)
m
authenticate
takes a
build: Route.() -> Unit
lambda as a configuration, not a
build: Routing.() -> Unit
(like
routing
does)
so the
Routing.applicationAuthRoutes()
extension method ends up being invoked on the root
routing
object, not in the authentication scope
🙌 1
a
@madisp seems to be right.
e
Thank you very much for this answer, I didn't see that at all. Everything works fine now, thanks again!
👍 1