-
Notifications
You must be signed in to change notification settings - Fork 651
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Guidance about websocket authentication & authentication update #2702
Comments
Hi 👋 ! Thanks for opening this! I'm pretty new to the Out of curiosity, how do you know you need to refresh the token? Do you receive an error message from the server or is this initiated client side with a timeout? |
Well the idea was to avoid recoding a whole I'm pretty new to the Android Apollo library so I'm not really sure but having implemented it on iOS I renew my auth token if I get an authentication error during a query/mutation or if a websocket get an authentication error. When done, I update the websocket headers (using the I guess it's a pretty standard way of handling token auth as token can have a short lifespan so you would expect them to be refreshed at runtime. |
Can you try using something like this: okHttpClient.addInterceptor(/* the same interceptor you used for queries/mutations */)
// Manually reconnect when a new token is required
apolloClient.subscriptionManager.stop()
apolloClient.subscriptionManager.start() |
I already saw that but the code looks like this:
which makes me think that subscriptions will be killed when doing that |
Mmm right, it does look like the |
@benoitletondor I'm still unclear whether authentication should be in the WebSocket request or the connection params? It looks like both solutions are possible? In all cases, |
Hey @martinbonnin , Many thanks for that, looks great!
I'm not sure I got what you mean here? |
We have: // goes into a "connection_init" websocket message
ApolloClient.builder().subscriptionConnectionParams {
SubscriptionConnectionParams(mapOf("token" to accessToken))
}
And // Will add the token as part of the initial WebSocket request
OkHttpClient.Builder().addNetworkInterceptor { chain ->
val request = chain.request().newBuilder().addHeader("token", accessToken).build()
chain.proceed(request)
} I guess you're using the second one? |
Indeed, the second one. But I don't see the difference in what we want to achieve which is reconnecting to the websocket when token changes at runtime, no matter the method used we would need that |
Yes. A better way to do this would certainly be to have a custom websocket message. That'd save having to tear down the web socket and renegociate it again. Something like |
Hi everyone 👋 , I know it's been a long time but if anyone comes here, we've adding some documentation about this at #4128 |
Question.
The documentation describes in a clear way how to handle authentication for http requests but it's not clear (at least for me) how to handle it for websockets and most importantly, how to update it at runtime (in case of a token refresh).
So I have 2 questions:
ApolloWebSocket
exposes a method calledupdateHeaderValues
that allow to update authentication headers, does this library have a similar mechanism?Many thanks in advance.
The text was updated successfully, but these errors were encountered: