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

Test long-running connections and handling of 4xx auth errors #31

Open
anthonyreilly opened this issue Jan 28, 2021 · 4 comments
Open

Comments

@anthonyreilly
Copy link
Owner

Minimal testing has been done on long-running login sessions, where a client goes idle and the with token may have been revoked or expired. Need to test and/or simulate these events to verify how the library handles these situations.

https://developer.salesforce.com/docs/atlas.en-us.api_streaming.meta/api_streaming/streaming_handling_errors.htm

@sergey-bulavskiy
Copy link

Hey, wanted to clarify as it is not clear. Some kind of authentication-info caching is supported? Havent found anything about it. I mean currently i register client as a scoped entity, so i'm thinking about switching to singleton, but wandering if i'm should be the one that handle 4xx or it is handled somehow on NetCoreForce side.

@anthonyreilly
Copy link
Owner Author

Currently, you would need to monitor for 4xx when the token or login session expires and then refresh the token. Adding an automatic token refresh is a priority for the next release, since I'm also looking at a similar situation where I may need to switch to a long-running singleton, and having the library automatically intercept the 4xx and refresh the token would be much easier to use. This would also perform better than an app that is constantly needing to create new tokens.

https://help.salesforce.com/s/articleView?id=sf.remoteaccess_oauth_refresh_token_flow.htm&type=5

@senj
Copy link

senj commented Oct 28, 2022

This is what we use with Polly

_unauthorizedPolicy = Policy
                .Handle<ForceApiException>(faex => faex.Errors?.Any(p => p.ErrorCode == "INVALID_SESSION_ID") == true)
                .RetryAsync(1, onRetry: async (exception, retryCount) =>
                {
                    _logger.LogWarning(exception, "Session expired, refreshing token");
                    await CreateNewClientAsync(salesforceConfiguration.Value);
                });

@sergey-bulavskiy
Copy link

I made the Singleton auth info storage, with underlying AuthClient, and each time Rest client is instance (scoped) it asks for auth data from singleton auth storage, if it is about to expire (more than 1.5h) - re-loggin. Not as accurate as @senj solution, will think about using Polly.

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

No branches or pull requests

3 participants