-
Notifications
You must be signed in to change notification settings - Fork 103
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
Do not try to refresh token when no getToken function is given #216
Comments
Hello @nfode Did you consider configuring refresh proxy to periodically validate connection fully on server-side? This way you can fully avoid disconnects and re-init I think. |
We still use JWT Tokens. So we want the server to disconnect the client when the token expires, to then force a reconnect with a new token. This as of now works already very good: the token expires and the client errors. The only problem is that the error comes from the missing Another way to improve this behavior could be to upgrade the Changing the behavior of the refresh handling in the client would improve our and other uses of the connection proxy with custom auth by a lot. |
I am trying to think on a better way to handle this. To avoid disconnects at all if the connection is still valid. Like it happens with native Centrifugo JWTs. Let's consider this scenario:
Can this fit your case? This will be very similar to our native JWT handling – but with delegating token handling to the backend. BTW, one more question. Since you are using JWT – why not you just generated Centrifugo native JWT for the connection? What is the reason you want to use custom token instead? The answer may help me to understand the use case better. |
Firstly, thank you for taking time thinking about possible solutions! I love the idea. That would fit our use case perfectly.
We use Keycloak with multiple realms and therefore have multiple JWKs endpoints. This was already discussed for the v4 roadmap here: centrifugal/centrifugo#500 (comment) But from my understanding there was nothing done in that direction. |
I did some prototyping with what I described above in centrifugal/centrifugo#612. While it works – the feeling is that all the benefits of JWTs are lost in that case. You will get more requests to the backend than required - on connection (from Centrifugo to app), on time to refresh (from SDK to app), and on refreshing (from Centrifugo to app). And it feels a bit odd actually since Centrifuge SDK first asks your backend for the token, then Centrifugo almost immediately sends it over refresh proxy for validation. In this perspective current Centrifugo refresh proxy behaviour which does not involve client-side request to the app for token at all have much more sense since user is already known. Let's talk more about that JWKs and multiple realms. I suppose selecting JWKs endpoint based on |
Your proposal feels exactly what I would have expected in the first place when checking out Centrifugo for us. When using Centrifugo with "custom authn" you automatically accept that you have more requests. That is a risk we are willing to take. Before using Centrifugo we had a custom NATS patch based on an outdated NATS fork, the Centrifugo proxy therefore is a major improvement for us. But I also understand that it feels odd. Regarding the idea with the Selecting the JWKs endpoint only by the To avoid this, Centrifugo could check if the What can work is configuring a template url to the jwks endpoint, and then also configuring where to get the tenant/realm from the token. The config then would look like this for Keycloak:
Centrifugo then would parse the token, get the realm, and then get the JWKs with the configured url template. If the token was forged by an attacker, the check would fail even if the realm exists, since we verify with our own JWKs. This would work for Keycloak besides that the
Instead of adding another configuration, we also could ditch the user channel boundaries and use the |
Could you reach me out in our Telegram or Discord community groups to discuss this? There are some things I can suggest regarding this and some things for which I still need more clarification. Think in a chat this may be more effective. Hopefully we can come to the effective solution here – but it's hard to implement without understanding all the details. |
Eventually fixed over centrifugal/centrifugo#638, docs |
Hello, firstly I would like to thank you for the work on centrifuge.
Is your feature request related to a problem? Please describe.
We are using a centrifuge with the connect proxy. This means instead of giving the token on constructing the Centrifuge-Client we pass the token in the data field like this:
In our backend, we then validate the token and set the
expire_at
like described in the documentation here. This is necessary since the build in token mechanism does not work with our internal systems.Connecting then works like a charm, but it gets problematic when the tokens are expired and the client wants to trigger a refresh. We then get the following error in the browser console:
The error is thrown here on token refresh because the lib tries to call the
getToken
function we did not define, since we have our own token handling.Describe the solution you'd like
On refresh, when no
getToken
function is defined, the client triggers an error event and does not try to reconnect. When the error event is triggered, the implementor then can reinitialize the client using its own logic.Describe alternatives you've considered
The code wrapping the client remembers when the token expires and reinitialize the client when it is time for a refresh. It then also ignores that an error is thrown because of the missing
getToken
function.If there are any questions or further clarification needed I am happy to help.
The text was updated successfully, but these errors were encountered: