OData / ODataConnectedService

A Visual Studio extension for generating client code for OData Services
Other
79 stars 41 forks source link

Do versions 7.6.4 and 7.7.0 support MSAL or ADAL as I get 401 UnAuthorized #163

Closed UM001 closed 4 years ago

UM001 commented 4 years ago

Resolved partially. See comments below.

I am using this library in .net core 3.1 as I want to develop a multi tenant application with microservices. I use ADAL for authentication and not MSAL for that reason. With .net framework and ADAL I got this to work (with older OData T4 files). With this new 7.7.0 version I got issues with I suspect that 7.7.0 is not ready for .net core. So moved back to 7.6.4.

Authentication and getting data from the D365FO ERP goes well if I use my own httpclient with custom delegatehandler to inject the bearer token with ConfidentialClientApplicationBuilder. Same works also for D365CE CRM.

Unfortunately with this T4 library version I get a 401 unauthenticated. I have no fiddler/ tools on this company pc to see if the requests are different. I would love to have better coding skills to extract that from the pipeline, but I do not. I am running in circles with this, so maybe you can help me out. I got a 401 on all three implementions that inject the bearer token: OnMessageCreating, SendingRequest2 and ConfigureODataClient.

I suspect this library does not accept a ADAL token and a raw implementation with httpclient does. Any ideas?

UM001 commented 4 years ago

I resolved this one myself. Have now both ADAL and MSAL working. In my unit test I put bearer instead of Authorization token. See this example. I have OnMessageCreating and SendingRequest2 working. var token = protectedApiBearerTokenHandler.GetTokenAsync().Result; request.SetHeader("Authorization", $"bearer {token}"); //request.SetHeader("bearer", token.Result);

Sreejithpin commented 4 years ago

Looks like you have resolved it. Thanks, Please let us know in case you come into any other issues Closing as its resolved