Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update ODataProvider.cs #50

Merged
merged 3 commits into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Version>10.6.7</Version>
<Version>10.6.8</Version>
<AssemblyVersion>1.0.0.0</AssemblyVersion>
<Title>OData Provider</Title>
<Description>The Odata Provider lets you fetch and map data from or to any OData endpoint.</Description>
Expand Down
16 changes: 15 additions & 1 deletion src/ODataProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Text.Json;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Xml;
Expand Down Expand Up @@ -129,6 +130,19 @@ public string DestinationEndpointId
#endregion

private string GetMetadataURL()
{
if (GetEndpointResponse(ODataSourceReader.GetEndpointUrlWithTop(_endpoint.Url), out string endpointResponse, out Exception exception) == HttpStatusCode.OK && exception is null)
return GetMetadataURLFallBack();

using var responseJson = JsonDocument.Parse(endpointResponse);

if (responseJson.RootElement.ValueKind != JsonValueKind.Object)
return GetMetadataURLFallBack();

return responseJson.RootElement.EnumerateObject().FirstOrDefault(obj => obj.Name.Equals("@odata.context", StringComparison.OrdinalIgnoreCase)).Value.GetString() ?? GetMetadataURLFallBack();
}

private string GetMetadataURLFallBack()
{
if (_endpoint.Url.Contains("companies(", StringComparison.OrdinalIgnoreCase))
{
Expand Down Expand Up @@ -164,7 +178,7 @@ internal void SetCredentials()
var endpointAuthentication = _endpoint.Authentication;
if (endpointAuthentication != null)
{
var metadataUri = new Uri(GetMetadataURL());
var metadataUri = new Uri(_endpoint.Url);
var credentialCache = new CredentialCache
{
{ new Uri(metadataUri.GetLeftPart(UriPartial.Authority)), endpointAuthentication.Type.ToString(), endpointAuthentication.GetNetworkCredential() }
Expand Down
Loading