Hi, Does anyone have a clue if it's possible to re...
# ktor
j
Hi, Does anyone have a clue if it's possible to retrieve client principal when using the StatusPage plugin? The AuthContext does not seem to exist in call.attributes
a
Could you please describe your problem in more detail?
j
Currently I would like to present different pages for different roles when serving a 404 page. Code for setting up StatusPages and securing routes are shown here
Copy code
install(StatusPages) {
    status(HttpStatusCode.NotFound) { call, status ->
        val principal = call.principal<JWTPrincipal>() // Always null here

        // Also tried to find the context like this: Key is never found
        val attributeKey = call.attributes.allKeys.find { attr -> attr.name == "AuthContext" }
    }
}

routing {
    authenticate("auth-jwt") {
        // Routes here
    }
}
Might be because the routes are given a principal but at the point of the 404 page the context will already be dropped?
However I could not find any documentation on how to set up an authentication block outside the routing block
a
So the scenario is that a user sends a credentials to a nonexistent route and you want to authenticate him and customize the 404 page?
j
Well the credentials are already sent using a jwt header
But I would like to show custom links depending on the user permissions
Using a common HTML header for the whole app which depends on the principal being present
I guess it doesn't matter which form of authentication you're using, cookies, basic auth etc, the principal wouldn't be there in the statuspage handler
a
You have to authenticate a user first to get a principal and I don’t see a way of doing in the StatusPages’s handler because the API that allows to trigger an authentication process is internal.
j
Ah okey, so the auth plugin is tied to the routing plugin pretty much then. It would be nice if it could be used with other plugins as well.