ODataConnectedService icon indicating copy to clipboard operation
ODataConnectedService copied to clipboard

Help needed to add odata endpoint with basic authorization to C# project.

Open jerrywoo96 opened this issue 4 years ago • 10 comments

Hi, I'm asking for help on how to add an endpoint with Basic Authorization using OData Connected Service. There are no samples or step by step guide on how to add the endpoint with Basic Authorization. I've also searched the Issues tab for Authorization: Basic but no results show up. I've added Authorization: Basic in the custom headers section but it still does not show anything on the next page and returns 401 unauthorised at the last page. Postman using authoization: basic header is working. The endpoint is using OData V1. I'm able to retrieve the $metadata.xml in postman using the same Authorization: Basic header. I'm losing my mind on what should be a simple endpoint connection.

Reproduce steps

image

image

image

image

image

image

Expected result

Retrieved details

Actual result

Not retrieving details, 401

jerrywoo96 avatar Aug 05 '21 11:08 jerrywoo96

Hi @jerrywoo96

Perhaps, on the server side, additional request pledges are checked (for example, Host), which is why a 401 error is returned. See what other headers you are passing through Postman.

unchase avatar Aug 11 '21 09:08 unchase

In other words, all the headers are replaced with the custom headers entered? For open services with no authorization, the plugin should have sent some headers of its own right? In order to be able to retrieve details. Like the one on docs.microsoft.com using trippin service.

jerrywoo96 avatar Aug 11 '21 11:08 jerrywoo96

@jerrywoo96 the headers are appended to the request. But they are trimmed before being added to the request. Each header should be on a separate line.

Looking at your screenshots, it's not immediately clear why it's not working as expected.

Is it possible that you have a typo in the header? Or does may trimming be affecting the header? Does your token end in whitespace by any chance?

habbes avatar Aug 12 '21 11:08 habbes

@jerrywoo96 the headers are appended to the request. But they are trimmed before being added to the request. Each header should be on a separate line.

Looking at your screenshots, it's not immediately clear why it's not working as expected.

Is it possible that you have a typo in the header? Or does may trimming be affecting the header? Does your token end in whitespace by any chance?

I entered Authorization: Basic base64string as 1 line in the box and trimmed whitespace at both ends. The box width was small enough such that it wrapped around in the picture. Also hosting on a different port does not matter right?

jerrywoo96 avatar Aug 12 '21 13:08 jerrywoo96

@jerrywoo96 what do you mean by "hosting on a different port"? A different port from what?

habbes avatar Aug 12 '21 14:08 habbes

@jerrywoo96 what do you mean by "hosting on a different port"? A different port from what?

The service is hosted on other ports than 443. Like https://foobar.com:12345/TEST-SVR/$metadata

jerrywoo96 avatar Aug 12 '21 14:08 jerrywoo96

@jerrywoo96 could you use a tool that can intercept the network traffic, maybe something like fiddler and inspect whether the connected service is actually sending the request to the server with the expected headers? Are there other headers that are being sent by postman that are not being sent by the connected service?

habbes avatar Aug 13 '21 06:08 habbes

I am experiencing exactly the same problem. This applies to the Visual Studio extension and when using "odata-cli" tool. The result is the same in both cases - "The remote server returned an error: (401) Unauthorized." Executing Invoke-WebRequest against the same metadata endpoint and using the same header "Authorize: Basic ****' (used literally copy paste here) works just fine and returns the expected metadata xml.

psoszynski avatar Sep 15 '22 15:09 psoszynski

Same problem! I have been trying to connect to Microsoft Dynamics 2018 web services. I can do this from a web browser, but I have not been able to get connected in Visual Studio 2022 using OData Connected Service for V1-V4. Really would like to get this working!

fishmichael avatar Sep 26 '22 18:09 fishmichael

Hi fishmichael, it is a known issue and there is a PR that fixes it. Another thing is that this extension will work with only with OData versions V3-V4. Unchase extension seems to works for all versions though.

psoszynski avatar Sep 26 '22 19:09 psoszynski