-
Notifications
You must be signed in to change notification settings - Fork 743
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
Update auth header on Websocket connection, automatic reconnect of subscription? #1178
Comments
Yeah - as I understand it, this is a problem with short-lived auth tokens and web sockets in general, since there's not really a way to constantly re-authenticate. We do have a I'm going to tag in @fassko here, who's contributed to both |
Thanks @designatednerd for that, I have had a dig through the framework, and adding this to, and calling when the token needs to be refreshed seems to work in initial testing. It seems a bit hacky, but by doing it this way calling connect re-starts the subscriptions that where active when disconnect is called it seems. in WebSocketTransport.swift
Now, I could be missing something very bad I'm doing here, so please let me know if I am? Cheers Gareth |
I don't believe there's anything bad, but there might be a race condition since the I'm not sure if Starscream handles multiple attempts to reconnect under the hood or if we'd need to temporarily disable the auto-reconnect. |
Ah yes, valid point. So maybe something more like this, where we explicitly disable reconnect for the restart of the socket, and set it back to its previous value if it was true?
Is this something you'd be interested in implementing in the framework, or should I make my own fork for this (which I'd really like to not have to do) as I cannot extend or sub-class due to private restrictions e.t.c Thanks Gareth |
Yeah, please open a PR! |
+1! I would very much like this to be a feature. 🙏 |
@yootsubo I'm swamped so any help I can get would be lovely |
This shipped with |
I have this working in a project to a Hasura backend using subscriptions. I am authenticating by adding an ID Token from google auth to the connectingPayload.
The validity of the ID token from google is 1 hour, and I am trying to honour that in Hasura with only allowing the connection to remain valid for the remaining validity of the token when received.
Unfortunately that means I need to change the token in the payload when it has expired, and reconnect the web socket.
I am currently thinking the only way to do this is to create a new WebSocketTransport in
func webSocketTransport(_ webSocketTransport: WebSocketTransport, didDisconnectWithError error:Error?)
But the problem is I have some active subscriptions going on when this happens, and they don't reconnect unless manually made to do so.
Am I missing something here, or is their no easy/clean way way to handle the currently in the framework?
Thanks
Gareth
The text was updated successfully, but these errors were encountered: