Open sblomstrand opened 1 year ago
Another option would be changing the internal ApplyTo
function in FortnoxAuthorization
to public ApplyTo
so that we can implement our own version.
Hello! I have released a nuget where to ApplyTo is set to public. Hope this helps you to create your implementation of the authorization.
Super, thanks!
Would it be to much to suggest a breaking change?
Task ApplyToAsync
would let us handle the refresh in this method as well.
Since moving to the new Api we have started experiencing exceptions due to the rate-limiter. Doing a little digging we discovered that the reason for this is the combination of our implementation authorization along with the call to the rate-limiters Throttle-method in BaseClient.
Background: We use Fortnox in a distributed environment and need to keep the access token available to multiple clients. To be able to do this we use a DelegatingHandler to the HttpClient that we inject into the FortnoxClient. In the handler we retrieve and set the Authorization-header to the correct token.
In the
BaseClient
sSendAsync
-method the throttling is performed onAuthorization?.AccessToken
which in our case has not been set yet (it will be se on the next line when the call toHttpClient.SendAsync
is performed.The RateLimiters Throttle does not throttle anything if the AccessToken is null.
RateLimiter:
BaseClient:
A suggested solution: Expose a
RateLimiterToken
when creating a newFortnoxClient
and use that if there is no AccessToken in BaseClient:BaseClient: