nozzlegear / ShopifySharp

ShopifySharp is a .NET library that helps developers easily authenticate with and manage Shopify stores.
https://nozzlegear.com/shopify-development-handbook
MIT License
742 stars 308 forks source link

ShopifyOauthUtility.RefreshAccessTokenAsync incorrectly disposes the static HttpClient used by InternalHttpClientFactory #1005

Closed nozzlegear closed 7 months ago

nozzlegear commented 7 months ago

ShopifyOauthUtility.RefreshAccessTokenAsync is erroneously disposing the HttpClient it instantiates. In most cases this is just bad practice, but because the ShopifyOauthUtility does not currently accept an IHttpClientFactory in its constructor and only uses ShopifySharp's default InternalHttpClientFactory, this means the static HttpClient in the internal client factory is then permanently disposed for the lifetime of the application. The next call to RefreshAccessTokenAsync will fail with an ObjectDisposedException.

Worse, if the developer has not supplied their own IHttpClientFactory to ShopifySharp using the ShopifyService.SetHttpClientFactory, then all services will by default use the internal client factory, meaning any further call to any service will result in that same ObjectDisposedException.

Note: because the deprecated AuthorizationService.RefreshAccessTokenAsync calls the ShopifyOauthUtility behind the scenes, it was also affected by this bug.