Apollo documentation mentions <support of OkHttp i...
# apollo-kotlin
i
Apollo documentation mentions support of OkHttp interceptors as a way to easily add an "Authorization" header to HTTP requests. I wonder if Apollo also supports okhttp Authenticator as a way to refresh auth token and retry the request? (after my initial trials I don't think this is the case but I want to double check)
If no then what is the intended way of re running the previously unauthenticated request with new credentials?
b
Hi! Yes this should work - you need to create your OkHttpClient and pass it to the Apollo client, and it will use it. If the OkHttpClient is configured with an Authenticator, that is transparent to Apollo
what happened in your tests?
i
Thx for the confirmation. I have solved this puzzle. The API is graphQL and it returns unauthenticated responses with a
200
HTTP status code.
b
Arg 🙂 I see.
In that case you can probably implement an ApolloInterceptor which has access to the GraphQL response.
❤️ 1
i
thx for quick response
b
Sure thing!
i
Will ApolloInterceptor be used for WS as well? Will it handle case when token is incorrect for WS or should I implement custom logic here as well
.wsProtocol(getSubscriptionWsProtocolFactory())
b
`ApolloInterceptor`s do work with subscriptions
we also have this section of the doc touching the subject of auth with WS