Closed fyziktom closed 2 years ago
I have the same issue I end up using reflection to force the authentication header into the HttpClient object:
public static IpfsClient CreateIpfsClient(string IpfsHostUrl, string IpfsHostUserName, string IpfsHostPassword ){
var c = new IpfsClient(IpfsHostUrl);
var httpClientInfo = typeof(IpfsClient).GetField("api", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static);
var apiObj = httpClientInfo.GetValue(null);
if (apiObj == null) {
MethodInfo createMethod = typeof(IpfsClient).GetMethod("Api", BindingFlags.NonPublic | BindingFlags.Instance);
var o = createMethod.Invoke(c, new Object[0]);
var httpClient = o as HttpClient;
var byteArray = Encoding.ASCII.GetBytes(IpfsHostUserName+ ":" + IpfsHostPassword);
httpClient.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Basic", Convert.ToBase64String(byteArray));
}
return c;
}
something like that
Hello. Thank you very much for this answer. It works :)
Hello,
Infura.io started beta paid version of IPFS service. I would like to use it together with this client, but I cannot find way how to add the credentials correctly. Could you please help me with some example?
I have tried to add it as part of url, but it does not work (like https://ProjetID:secret@ipfs.infura.io:5001/)
Thank you.