https://kotlinlang.org logo
Title
j

John O'Reilly

09/21/2020, 7:05 AM
Is it possible, using
HttpClient
to apply different types of auths to different requests?
a

aleksey.tomin

09/21/2020, 7:09 AM
What type of auths you use? For
x-api-key
header - you can use different headers. And so on.
j

John O'Reilly

09/21/2020, 7:22 AM
a combination of digest and jwt....right now I have digest declared e.g.
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

aleksey.tomin

09/21/2020, 7:27 AM
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

John O'Reilly

09/21/2020, 7:41 AM
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

aleksey.tomin

09/21/2020, 7:46 AM
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

John O'Reilly

09/21/2020, 7:51 AM
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

aleksey.tomin

09/21/2020, 7:57 AM
You want to have a mutable list of auths and use the first successful?
j

John O'Reilly

09/21/2020, 7:59 AM
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

aleksey.tomin

09/21/2020, 8:04 AM
then specify which one to use when making request
You know which one you have to use. Isn’t it?
j

John O'Reilly

09/21/2020, 8:05 AM
yeah, for example digest for that initial login request to get token.....and then jwt for all requests after that
a

aleksey.tomin

09/21/2020, 8:07 AM
You can use your own provider (based on standard) and use value if this exists.
j

John O'Reilly

09/21/2020, 8:09 AM
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