No authorization options?
Closed this issue · 3 comments
maxwidergy commented
Hey, im trying to use your package but there is no way to use any authorization option i am right? I have a SOAP Service that requires Basic Authorization for example. Thanks!
pmorelli92 commented
Hey @maxwidergy you can customise the underlying HttpClientFactory
to add any headers you want: https://github.com/pmorelli92/SoapHttpClient/blob/master/Source/SoapHttpClient/SoapClient.cs#L27
maxwidergy commented
thanks for the answer! so i should fork the repo and make the changes my self right?
pmorelli92 commented
No need, you can create your own HttpClientFactory like:
public class AuthorizationHttpClientFactory : IHttpClientFactory
{
public HttpClient CreateClient(string name)
{
var client = new HttpClient();
client.DefaultRequestHeaders.Add("Authorization", "Bearer x.x.x");
return client;
}
}
And then do:
var factory = new AuthorizationHttpClientFactory();
var client = new SoapClient(factory);
There is an example here https://github.com/pmorelli92/SoapHttpClient/blob/master/Tests/SoapHttpClient.Tests/SoapClientTests.cs#L109-L110