exposing client builder to allow httpClient.#71
exposing client builder to allow httpClient.#71mark-robustelli wants to merge 4 commits intomainfrom
Conversation
syncing with changes to fusionauth-client-builder FusionAuthSyncClient.
Making cleaner. Since the baseRequest function expected a clean httpClient every call, I just added a clear to the headers instead of all the validation logic.
|
Having built my own client to support injecting a HttpClient using IHttpClientFactory as this change supports, you should note that having a single HttpClient can mean that cookies and access tokens are shared across requests. I have an API that sites between our client application and FusionAuth, if User A renews their token using the This happens as the response from FusionAuth includes a Set-Cookie header (documented here) and the refresh endpoint and I asusme others, use the cookies over the json payload being sent To get around this and still use IHttpClientFactory (as is best practice) I've had to disable cookies services.AddHttpClient("my-fusion-client")
.ConfigurePrimaryHttpMessageHandler(() => new HttpClientHandler { UseCookies = false })Hope this helps someone and saves them the trouble I've had 👍 |
| @@ -57,6 +58,10 @@ public DefaultRESTClient(string host) { | |||
| httpClient = new HttpClient {BaseAddress = new Uri(host)}; | |||
There was a problem hiding this comment.
| httpClient = new HttpClient {BaseAddress = new Uri(host)}; | |
| var handler = new HttpClientHandler | |
| { | |
| UseCookies = false, | |
| }; | |
| httpClient = new HttpClient(handler) {BaseAddress = new Uri(host)}; |
In the same vein as @matt-lethargic's comment regarding preventing the accidental reuse of cookies. While there's not an easy way to override the HttpClientHandler for the custom HTTP client provided by the end-user, we can at least ensure that the default client will not re-use cookies by disabling the functionality during initial construction.
|
|
||
| public IRESTClient build(string host) | ||
| { | ||
| if (HTTP_CLIENT.BaseAddress == null) |
There was a problem hiding this comment.
Echoing comment from FusionAuth/fusionauth-client-builder#75 (comment)
If a host string is passed in, but the BaseAddress of the HTTP_CLIENT is already set, the parameter is effectively ignored. This might be an anti-pattern.
DefaultRestClient.cs is the change that will stick. The changes to FusionAuthClient.cs and FusionAuthSyncClient.cs will have to be added to fusionauth-client-bulder. I will add that now.