Hello community,
I ran into following problem (D365 solution with .net Framework 4.6.2):
I want to consume from D365 F&X an external API Endpoint which needs a bearer token auth.
On several websites (MSDN, StackOverflow) the recomended way to provide the auth details is via DefaultRequestHeader or on the HttpRequestMessage (depending wether it changes per request or not). Neither ways are working, because (and this is my assumption) the DefaultRequestHeader is a property with only a getter.
I also tried to work with the add method without succes.
The error I get from our beloved compiler is: Error Invalid token '('.
using System.Net.Http; class DefinitelyNotAClass { public static void main(Args _args) { HttpClient httpClient = new HttpClient(); httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", "DefinitelyNotABearerToken"); } }
My question is: How should I provide the bearer token authentication from a D365 solution with the HttpClient?
Thanks in advance and best regards,
Oliver