-
Notifications
You must be signed in to change notification settings - Fork 14
exposing client builder to allow httpClient. #71
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
base: main
Are you sure you want to change the base?
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 @@ class DefaultRESTClient : IRESTClient { | |||
httpClient = new HttpClient {BaseAddress = new Uri(host)}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.