Closed IanKemp closed 1 week ago
What works is using the other overload of Create
:
var handlers = KiotaClientFactory.CreateDefaultHandlers();
handlers.Add(new MyDelegatingHandler());
var kiotaClient = KiotaClientFactory.Create(handlers);
// all other code same as first comment
MyAuthenticationProvider ...
The issue is that Create(HttpMessageHandler?, IRequestOption[]?)
is IMO a bit of a footgun: it doesn't automagically add GetDefaultHttpMessageHandler()
as the InnerHandler
of the passed-in handler. Yes, the method does explicitly say that the parameter is the final handler, but I made the assumption (which I don't think is unwarranted) that if I wanted to do nothing more than add a single handler into the chain, I should probably be calling the method that takes a single handler. Perhaps a CreateWith(params HttpMessageHandler[] handlers)
method that inserts the provided handlers between the default ones and the final GetDefaultHttpMessageHandler()
one?
I also think that the linked example should be updated to the code given in this comment, as it's both more concise and IMO self-explanatory.
This seems related to microsoft/kiota-http-dotnet#268 ?
And since you're trying to do authentication, why not make a factory that creates the right IAuthenticationProvider. The authentication provider interface has one method to implement which is: Task AuthenticateRequestAsync(...)
, has access to all the request info and can attach additional headers.
Transferring issue as part of https://github.com/microsoft/kiota-abstractions-dotnet/issues/238
This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment.
The following code throws the aforementioned exception with
Microsoft.Kiota.Http.HttpClientLibrary
version 1.4.3 (latest as of this writing) when issuing a request againstmyClient
. Am I doing something wrong, or is this a bug?Stack:
I do not receive the same exception if I follow the example directly.