Is there any way to use ktor's authentication with...
# ktor
d
Is there any way to use ktor's authentication with a token provided in a query parameter instead of a header?
a
For the bearer provider, you can use the
authHeader
method to configure the token's source. Here is an example:
Copy code
install(Authentication) {
    bearer {
        authHeader { 
            val auth = it.request.queryParameters["auth"] ?: throw BadRequestException("No auth query parameter given")
            parseAuthorizationHeader(auth)
        }
    }
}
👍🏼 1
d
Thanks, that's perfect! Just funny that it's called
authHeader
...?
Since there we're really setting the auth source, shouldn't it be
authSource { }
?
a
Not exactly, since the source also has to be parsed.
d
It's not working @Aleksei Tirman [JB]...?
As a result to that parse function, I get the token in the authScheme of the HttpHeader... is that what's supposed to happen?
It seems to skip the
authenticate { }
block in
bearer {  }
too...
Copy code
install(Authentication) {
    bearer {
        authHeader { 
            val auth = it.request.queryParameters["auth"] ?: throw BadRequestException("No auth query parameter given")
            parseAuthorizationHeader("Bearer " + auth)
        }
    }
}
this works... I need to add
Bearer
to the auth token.
a
It depends on the format of the value in the header.