Skip to content
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

Allow updating the Connection's token and/or JWT upon disconnect #356

Open
scout719 opened this issue Jan 25, 2024 · 6 comments · May be fixed by #712
Open

Allow updating the Connection's token and/or JWT upon disconnect #356

scout719 opened this issue Jan 25, 2024 · 6 comments · May be fixed by #712
Labels
enhancement New feature or request

Comments

@scout719
Copy link

Proposed change

Support using the disconnected callback to refresh the token or JWT used to authenticate to allow reconnecting without the need to create a new connection and subscribe to all the topic again.
Something like this (working snippet using the V1 client):

opts.DisconnectedEventHandler += (sender, args) =>
{
    args.Conn.Opts.Token = RefreshToken();
};

opts.Token = GetToken();
using IConnection c = new ConnectionFactory().CreateConnection(opts);

Use case

We have a long running application that subscribes to several NATS topics.
The authentication in our scenario is made using tokens, with expiration.
In order to allow the reconnect of the same connection upon disconnect, we need to provide a valid token, so it might need to be refreshed due to expiry date.
This proposal would void the need to create a new connection and re-subscribe to all topics,

Contribution

Yes, I'm glad to help (might lack some context on the internals though)

@mtmk
Copy link
Collaborator

mtmk commented Jan 25, 2024

Similar to #285 design wise providing callbacks and/or reading tokens/jwt from files might be a better option since opts is read-only.

@mtmk mtmk added the enhancement New feature or request label Jan 25, 2024
@garrett-sutton
Copy link

Has there been any more interest in this? After the discussion in #525, I think this is what I am looking for.

When the user JWT that the NATS server associates with a given client connection expires, I'd want a way to be able to invoke a callback that can allow a client to get a new access token from my own authN server and trigger the auth callout flow again.

@garrett-sutton
Copy link

@mtmk do you know if there has been any other interest for a feature like this in the nats.net library?

Otherwise, are you aware of any workarounds?

@mtmk
Copy link
Collaborator

mtmk commented Jan 12, 2025

@garrett-sutton it's only folks in this issue afaik. I'm tiny bit snowed under at the minute. I think we basically need a callback in NatsOpts. If you or any other community members have some time please feel free to pop a PR in. Otherwise I will come back to it once I cleared my plate a little.

@garrett-sutton
Copy link

@mtmk Thanks for the insight. I am interested in helping out here. One question though (apologies I'm a noob at open source contributions). After a PR is submitted, do you have a sense for how long for review? And how long until a new version of the library with this enhancement in it?

@mtmk
Copy link
Collaborator

mtmk commented Jan 12, 2025

@mtmk Thanks for the insight. I am interested in helping out here. One question though (apologies I'm a noob at open source contributions). After a PR is submitted, do you have a sense for how long for review? And how long until a new version of the library with this enhancement in it?

@garrett-sutton that's great thank you! for our project it varies but it's usually pretty quick especially if there is interest. depending on how it goes all being well couple of days or so I'd guess in this case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants