Created
January 26, 2020 23:58
-
-
Save prom3theu5/bf2025d0e4d41a60e088163b3c068bc4 to your computer and use it in GitHub Desktop.
Polly AuthRefresh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var authorisationEnsuringPolicy = Policy | |
.HandleResult<HttpResponseMessage>(r => r.StatusCode == HttpStatusCode.Unauthorized) | |
.RetryAsync( | |
retryCount: 1, // Consider how many retries. If auth lapses and you have valid credentials, one should be enough; too many tries can cause some auth systems to blacklist. | |
onRetryAsync: async (outcome, retryNumber, context) => FooRefreshAuthorizationAsync(context), | |
/* more configuration */); | |
var response = authorisationEnsuringPolicy.ExecuteAsync(context => DoSomethingThatRequiresAuthorization(context), cancellationToken); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment