keycloak-authorization-services-dotnet icon indicating copy to clipboard operation
keycloak-authorization-services-dotnet copied to clipboard

Refit Dependency

Open bdovaz opened this issue 9 months ago • 3 comments

Currently it is very difficult, if not impossible, to make certain configurations of the HttpClient instance.

For starters you have no control over the construction of the HttpClient object so you cannot pass it an instance of HttpClientHandler to be able to configure for example a proxy or other things.

https://github.com/NikiforovAll/keycloak-authorization-services-dotnet/blob/6d20ce592c224ffb32c7a3e198e9d26cef8dc5ba/src/Keycloak.AuthServices.Sdk/Admin/ServiceCollectionExtensions.cs#L46

I think that at the very least there should be an overload that allows you to pass an instance of HttpClient directly: Func<IServiceProvider, HttpClient> clientProvider. It is very common nowadays this pattern: https://learn.microsoft.com/en-us/dotnet/architecture/microservices/implement-resilient-applications/use-httpclientfactory-to-implement-resilient-http-requests

Another issue is why there is a hard dependency to Refit when it should not be necessary, the implementation should be cleaner without dependencies to Refit.

Whoever uses the library if they want to use Refit should be their choice but not an imposition.

If you agree I am willing to help with a PR.

bdovaz avatar Sep 19 '23 20:09 bdovaz

Ok, I see that the AddKeycloakAdminHttpClient method returns an IHttpClientBuilder and I see that the Refit.HttpClientFactory dependency uses the Microsoft library I said.

Even so, I still think that the Refit dependency should not be necessary.

Examining the code I see that it provides several functionalities through C# attributes for client generation and I understand the "convenience" of using it but I still think that it should be a library for the exclusive use of the consumer of a library, not intended for whoever develops a library because you are imposing that use.

bdovaz avatar Sep 19 '23 21:09 bdovaz

Good point, next version will focus on removing unnecessary dependencies

NikiforovAll avatar Apr 19 '24 19:04 NikiforovAll

Will be fixed as part of: #64

NikiforovAll avatar Apr 24 '24 09:04 NikiforovAll

Done as part of https://github.com/NikiforovAll/keycloak-authorization-services-dotnet/releases/tag/2.0.0

NikiforovAll avatar May 05 '24 12:05 NikiforovAll