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 · 1 comment
Open

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

scout719 opened this issue Jan 25, 2024 · 1 comment
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
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

No branches or pull requests

2 participants