Is it possible, using `HttpClient` to apply differ...
# ktor
j
Is it possible, using
HttpClient
to apply different types of auths to different requests?
a
What type of auths you use? For
x-api-key
header - you can use different headers. And so on.
j
a combination of digest and jwt....right now I have digest declared e.g.
Copy code
install(Auth) {
                digest {
                    ....
                }
            }
but want to define/use jwt then as well.....digest for example for initial login request to get token and then jwt after that
a
I think you have to view into
digest
and (may by) write your own class for auth. It has to call one of auths for each call.
j
but there's no way of specifying which one it should use.....in the same way you can, on server, wrap different routes with different
authenticate
s (that have different auths)?
a
but there’s no way of specifying which one it should use...
You don’t know what way should be using? I think it’s the root cause of the problem.
j
so the assumption right now is that the one auth type you specific in that
install(Auth)
block will be automatically used for all requests? I guess that makes sense
It seems, at least for jwt case, that this would be pretty common pattern i.e. an initial login attempt to get token and then subsequent requests using that token for auth
a
You want to have a mutable list of auths and use the first successful?
j
Was more thinking that there'd be some way for me to specify multiple auth types (as is done on server) and then specify which one to use when making request
a
then specify which one to use when making request
You know which one you have to use. Isn’t it?
j
yeah, for example digest for that initial login request to get token.....and then jwt for all requests after that
a
You can use your own provider (based on standard) and use value if this exists.
j
ok, thanks, I'll dig a bit deeper
I could be overthinking this as well.....it should be straightforward to just manually added auth header with token for request where that's needed for example