Skip to content

Resync from mainline. #505

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

Merged
merged 1 commit into from
Apr 5, 2025
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
2 changes: 1 addition & 1 deletion src/Build.Common.StandardAndLegacy.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
</PropertyGroup>

<PropertyGroup Condition="'$(TargetFrameworks)' == ''">
<TargetFrameworks Condition="'$(OutputType)' == 'Exe'">net6.0;net48;net462</TargetFrameworks>
<TargetFrameworks Condition="'$(OutputType)' == 'Exe'">net8.0;net48;net462</TargetFrameworks>
<TargetFrameworks Condition="'$(OutputType)' != 'Exe'">netstandard2.0;net48;net462</TargetFrameworks>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
</PropertyGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/Build.Common.core.props
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
</PropertyGroup>

<PropertyGroup Condition="'$(ProjectSpecificFx)' == ''">
<TargetFrameworks>net462;net472;net48;netstandard2.0;net6.0;net8.0</TargetFrameworks>
<TargetFrameworks>net462;net472;net48;netstandard2.0;net8.0</TargetFrameworks>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<NoWarn>NU5104</NoWarn>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ internal async static Task<ExecuteAuthenticationResults> ExecuteAuthenticateServ
if (userCert != null)
{
logSink.Log("Initial ObtainAccessToken - CERT", TraceEventType.Verbose);
cApp = cAppBuilder.WithCertificate(userCert).Build();
cApp = cAppBuilder.WithCertificate(userCert, true).Build();
memoryBackedTokenCache.Initialize(cApp.AppTokenCache);
_authenticationResult = await ObtainAccessTokenAsync(cApp, Scopes, logSink).ConfigureAwait(false);
}
Expand Down
31 changes: 21 additions & 10 deletions src/GeneralTools/DataverseClient/Client/Auth/AuthorityResolver.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
Expand All @@ -28,6 +27,11 @@ public sealed class AuthenticationDetails
/// OAuth resource to request authentication for.
/// </summary>
public Uri Resource { get; internal set; }

/// <summary>
/// Error message if probing failed.
/// </summary>
public string ErrorMessage { get; internal set; } = string.Empty;
}

/// <summary>
Expand Down Expand Up @@ -57,7 +61,7 @@ public AuthorityResolver(HttpClient httpClient, Action<TraceEventType, string> l
}

/// <summary>
/// Attemtps to solicit a WWW-Authenticate reply using an unauthenticated GET call to the given endpoint.
/// Attempts to solicit a WWW-Authenticate reply using an unauthenticated GET call to the given endpoint.
/// Parses returned header for details
/// </summary>
/// <param name="endpoint">endpoint to challenge for authority and resource</param>
Expand All @@ -81,28 +85,31 @@ public async Task<AuthenticationDetails> ProbeForExpectedAuthentication(Uri endp
{
errDetails = $"; details: {wex.Message} ({wex.Status})";
}
LogError($"Failed to get response from: {endpoint}; error: {ex.Message}{errDetails}");

details.ErrorMessage = $"Failed to get response from: {endpoint}; error: {ex.Message}{errDetails}";
LogError(details.ErrorMessage);
return details;
}


if (response.StatusCode == HttpStatusCode.NotFound || response.StatusCode == HttpStatusCode.BadRequest)
{
// didn't find endpoint.
LogError($"Failed to get Authority and Resource error. Attempt to Access Endpoint {endpoint} resulted in {response.StatusCode}.");
details.ErrorMessage = $"Failed to get Authority and Resource error. Attempt to Access Endpoint {endpoint} resulted in {response.StatusCode}.";
LogError(details.ErrorMessage);
return details;
}

if (response.Headers.Contains(AuthenticateHeader))
{
var authenticateHeaders = response.Headers.GetValues(AuthenticateHeader);
// need to support OnPrem returning multiple Authentication headers.
foreach (var authenticateHeaderraw in authenticateHeaders)
foreach (var authenticateHeaderRaw in authenticateHeaders)
{
if (details.Success)
break;

string authenticateHeader = authenticateHeaderraw.Trim();
string authenticateHeader = authenticateHeaderRaw.Trim();

// This also checks for cases like "BearerXXXX authorization_uri=...." and "Bearer" and "Bearer "
if (!authenticateHeader.StartsWith(Bearer, StringComparison.OrdinalIgnoreCase)
Expand All @@ -112,7 +119,8 @@ public async Task<AuthenticationDetails> ProbeForExpectedAuthentication(Uri endp
if (isOnPrem)
continue;

LogError($"Malformed 'Bearer' format: {authenticateHeader}");
details.ErrorMessage = $"Malformed 'Bearer' format: {authenticateHeader}";
LogError(details.ErrorMessage);
return details;
}

Expand All @@ -126,15 +134,17 @@ public async Task<AuthenticationDetails> ProbeForExpectedAuthentication(Uri endp
}
catch (ArgumentException)
{
LogError($"Malformed arguments in '{AuthenticateHeader}: {authenticateHeader}");
details.ErrorMessage = $"Malformed arguments in '{AuthenticateHeader}: {authenticateHeader}";
LogError(details.ErrorMessage);
return details;
}

if (authenticateHeaderItems != null)
{
if (!authenticateHeaderItems.TryGetValue(AuthorityKey, out var auth))
{
LogError($"Response header from {endpoint} is missing expected key/value for {AuthorityKey}");
details.ErrorMessage = $"Response header from {endpoint} is missing expected key/value for {AuthorityKey}";
LogError(details.ErrorMessage);
return details;
}
details.Authority = new Uri(
Expand All @@ -143,7 +153,8 @@ public async Task<AuthenticationDetails> ProbeForExpectedAuthentication(Uri endp

if (!authenticateHeaderItems.TryGetValue(ResourceKey, out var res))
{
LogError($"Response header from {endpoint} is missing expected key/value for {ResourceKey}");
details.ErrorMessage = $"Response header from {endpoint} is missing expected key/value for {ResourceKey}";
LogError(details.ErrorMessage);
return details;
}
details.Resource = new Uri(res);
Expand Down
2 changes: 2 additions & 0 deletions src/GeneralTools/DataverseClient/Client/ServiceClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1729,6 +1729,7 @@ public async Task<OrganizationResponse> ExecuteOrganizationRequestAsync(Organiza

internal OrganizationResponse ExecuteOrganizationRequestImpl(OrganizationRequest req, string logMessageTag = "User Defined", bool useWebAPI = false, bool bypassPluginExecution = false)
{
_logEntry.ResetLastError(); // Reset Last Error
ValidateConnectionLive();
if (req != null)
{
Expand All @@ -1752,6 +1753,7 @@ internal OrganizationResponse ExecuteOrganizationRequestImpl(OrganizationRequest

private async Task<OrganizationResponse> ExecuteOrganizationRequestAsyncImpl(OrganizationRequest req, CancellationToken cancellationToken, string logMessageTag = "User Defined", bool useWebAPI = false, bool bypassPluginExecution = false)
{
_logEntry.ResetLastError(); // Reset Last Error
ValidateConnectionLive();
cancellationToken.ThrowIfCancellationRequested();
if (req != null)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Azure.Core;
using Azure.Identity;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using Microsoft.PowerPlatform.Dataverse.Client.Model;
using System;
using System.Collections.Generic;
Expand Down Expand Up @@ -81,7 +82,7 @@ public AzAuth(bool autoResolveAuthorityAndTenant, DefaultAzureCredentialOptions
{
_credentialOptions = credentialOptions;
_autoResolveAuthorityAndTenant = autoResolveAuthorityAndTenant;
_logger = logger;
_logger = logger ?? NullLogger.Instance;
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Microsoft.PowerPlatform.Dataverse.Client.Model;
using System.Diagnostics;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging.Abstractions;

namespace Microsoft.PowerPlatform.Dataverse.Client
{
Expand Down Expand Up @@ -75,7 +76,7 @@ public AzPipelineFederatedIdentityAuth(string tenantId, string clientId, string
_serviceConnectionId = serviceConnectionId;
_systemAccessTokenEnvVarName = SystemAccessTokenEnvVarName;
_autoResolveAuthorityAndTenant = autoResolveAuthorityAndTenant;
_logger = logger;
_logger = logger ?? NullLogger.Instance;
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ if($RunFromVSBuild -eq $false)
}
else
{
$BinsDirectory = [System.IO.Path]::Combine($BuildSourcesDirectory , "bin" , $BuildConfiguration, "DataverseClient" , "net6.0" )
$BinsDirectory = [System.IO.Path]::Combine($BuildSourcesDirectory , "bin" , $BuildConfiguration, "DataverseClient" , "net8.0" )
}
## Copying PowerShell Module out only.
Write-Host ">>> BINS path is $BinsDirectory"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<PropertyGroup>
<ProjectDir Condition="'$(ProjectDir)' == '' ">$(MSBuildProjectDirectory)\</ProjectDir>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
<TargetFrameworks>net6.0</TargetFrameworks>
<TargetFrameworks>net8.0</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<ProjectSpecificFx>true</ProjectSpecificFx>
<OutputType>Exe</OutputType>
<TargetFrameworks>net462;net6.0</TargetFrameworks>
<TargetFrameworks>net462;net8.0</TargetFrameworks>
<SignAssembly>false</SignAssembly>
<ComponentAreaName>DataverseClient-Tests</ComponentAreaName>
<IsPackable>false</IsPackable>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<ProjectSpecificFx>true</ProjectSpecificFx>
<!-- only test with one of the Classic and Core frameworks each -->
<TargetFrameworks>net462;net6.0</TargetFrameworks>
<TargetFrameworks>net462;net8.0</TargetFrameworks>
<SignAssembly>true</SignAssembly>
<ComponentAreaName>DataverseClient-Tests</ComponentAreaName>
<IsPackable>false</IsPackable>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<ProjectSpecificFx>true</ProjectSpecificFx>
<!-- only test with one of the Classic and Core frameworks each -->
<CheckEolTargetFramework>false</CheckEolTargetFramework>
<TargetFrameworks>net462;net472;net48;net6.0</TargetFrameworks>
<TargetFrameworks>net462;net472;net48;net8.0</TargetFrameworks>
<SignAssembly>true</SignAssembly>
<ComponentAreaName>DataverseClient-Tests-Package</ComponentAreaName>
<IsPackable>false</IsPackable>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>net462;net6.0</TargetFrameworks>
<TargetFrameworks>net462;net8.0</TargetFrameworks>
<SignAssembly>true</SignAssembly>
<ComponentAreaName>DataverseClient-Tests-Package</ComponentAreaName>
<IsPackable>false</IsPackable>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<ProjectSpecificFx>true</ProjectSpecificFx>
<OutputType>Exe</OutputType>
<TargetFrameworks>net462;net6.0</TargetFrameworks>
<TargetFrameworks>net462;net8.0</TargetFrameworks>
<SignAssembly>true</SignAssembly>
<ComponentAreaName>DataverseClient-Tests</ComponentAreaName>
<IsPackable>false</IsPackable>
Expand Down
2 changes: 1 addition & 1 deletion src/Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<PackageVersion_SystemSecurityPermissions>6.0.0</PackageVersion_SystemSecurityPermissions>
<PackageVersion_Azure_Identity>1.13.1</PackageVersion_Azure_Identity>
<PackageVersion_System_ServiceModel_PreNet6>4.10.3</PackageVersion_System_ServiceModel_PreNet6>
<PackageVersion_System_ServiceModel_PostNet6>6.2.0</PackageVersion_System_ServiceModel_PostNet6>
<PackageVersion_System_ServiceModel_PostNet6>8.1.2</PackageVersion_System_ServiceModel_PostNet6>
<PackageVersion_System_Formats_Asn1>8.0.1</PackageVersion_System_Formats_Asn1>

<!-- Test: -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@
<dependency id="Microsoft.PowerPlatform.Dataverse.Client" version="1.2.0" exclude="Build,Analyzers" />
<dependency id="Azure.Identity" version="1.12.0" exclude="Build,Analyzers" />
</group>
<group targetFramework="NET6.0">
<dependency id="Microsoft.PowerPlatform.Dataverse.Client" version="1.2.0" exclude="Build,Analyzers" />
<dependency id="Azure.Identity" version="1.12.0" exclude="Build,Analyzers" />
</group>
<group targetFramework="NET8.0">
<dependency id="Microsoft.PowerPlatform.Dataverse.Client" version="1.2.0" exclude="Build,Analyzers" />
<dependency id="Azure.Identity" version="1.12.0" exclude="Build,Analyzers" />
Expand All @@ -39,8 +35,6 @@
<files>
<file src="{signedBinDir}\{configuration}\DataverseClient\net8.0\Microsoft.PowerPlatform.Dataverse.Client.AzAuth.dll" target="lib\net8.0\Microsoft.PowerPlatform.Dataverse.Client.AzAuth.dll" />
<file src="{signedBinDir}\{configuration}\DataverseClient\net8.0\Microsoft.PowerPlatform.Dataverse.Client.AzAuth.xml" target="lib\net8.0\Microsoft.PowerPlatform.Dataverse.Client.AzAuth.xml" />
<file src="{signedBinDir}\{configuration}\DataverseClient\net6.0\Microsoft.PowerPlatform.Dataverse.Client.AzAuth.dll" target="lib\net6.0\Microsoft.PowerPlatform.Dataverse.Client.AzAuth.dll" />
<file src="{signedBinDir}\{configuration}\DataverseClient\net6.0\Microsoft.PowerPlatform.Dataverse.Client.AzAuth.xml" target="lib\net6.0\Microsoft.PowerPlatform.Dataverse.Client.AzAuth.xml" />
<file src="{signedBinDir}\{configuration}\DataverseClient\net472\Microsoft.PowerPlatform.Dataverse.Client.AzAuth.dll" target="lib\net472\Microsoft.PowerPlatform.Dataverse.Client.AzAuth.dll" />
<file src="{signedBinDir}\{configuration}\DataverseClient\net472\Microsoft.PowerPlatform.Dataverse.Client.AzAuth.xml" target="lib\net472\Microsoft.PowerPlatform.Dataverse.Client.AzAuth.xml" />
<file src="{signedBinDir}\{configuration}\DataverseClient\net462\Microsoft.PowerPlatform.Dataverse.Client.AzAuth.dll" target="lib\net462\Microsoft.PowerPlatform.Dataverse.Client.AzAuth.dll" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,8 @@
<group targetFramework=".NETFramework4.8">
<dependency id="Microsoft.PowerPlatform.Dataverse.Client" version="1.2.2" exclude="Build,Analyzers" />
</group>
<group targetFramework="NET6.0">
<dependency id="Microsoft.PowerPlatform.Dataverse.Client" version="1.2.2" exclude="Build,Analyzers" />
</group>
<group targetFramework="NET8.0">
<dependency id="Microsoft.PowerPlatform.Dataverse.Client" version="1.2.0" exclude="Build,Analyzers" />
<dependency id="Microsoft.PowerPlatform.Dataverse.Client" version="1.2.3" exclude="Build,Analyzers" />
</group>

</dependencies>
Expand All @@ -45,8 +42,6 @@
<files>
<file src="{signedBinDir}\{configuration}\DataverseClient\net8.0\Microsoft.PowerPlatform.Dataverse.Client.Dynamics.dll" target="lib\net8.0\Microsoft.PowerPlatform.Dataverse.Client.Dynamics.dll" />
<file src="{signedBinDir}\{configuration}\DataverseClient\net8.0\Microsoft.PowerPlatform.Dataverse.Client.Dynamics.xml" target="lib\net8.0\Microsoft.PowerPlatform.Dataverse.Client.Dynamics.xml" />
<file src="{signedBinDir}\{configuration}\DataverseClient\net6.0\Microsoft.PowerPlatform.Dataverse.Client.Dynamics.dll" target="lib\net6.0\Microsoft.PowerPlatform.Dataverse.Client.Dynamics.dll" />
<file src="{signedBinDir}\{configuration}\DataverseClient\net6.0\Microsoft.PowerPlatform.Dataverse.Client.Dynamics.xml" target="lib\net6.0\Microsoft.PowerPlatform.Dataverse.Client.Dynamics.xml" />
<file src="{signedBinDir}\{configuration}\DataverseClient\net472\Microsoft.PowerPlatform.Dataverse.Client.Dynamics.dll" target="lib\net472\Microsoft.PowerPlatform.Dataverse.Client.Dynamics.dll" />
<file src="{signedBinDir}\{configuration}\DataverseClient\net472\Microsoft.PowerPlatform.Dataverse.Client.Dynamics.xml" target="lib\net472\Microsoft.PowerPlatform.Dataverse.Client.Dynamics.xml" />
<file src="{signedBinDir}\{configuration}\DataverseClient\net462\Microsoft.PowerPlatform.Dataverse.Client.Dynamics.dll" target="lib\net462\Microsoft.PowerPlatform.Dataverse.Client.Dynamics.dll" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ Notice:
Note: Only AD on FullFramework, OAuth, Certificate, ClientSecret Authentication types are supported at this time.

++CURRENTRELEASEID++
Fix for Null ILogger passed to the AzAuth Client Creators causing a fault. Git: https://github.com/microsoft/PowerPlatform-DataverseServiceClient/issues/481
Fix for Memory Leak in Retrieve Multiple. Git: https://github.com/microsoft/PowerPlatform-DataverseServiceClient/issues/463
Fix for Memory bloat issue caused by not releasing lastErrorMessage property.
Updated Error messages verbosity when checking for authority from Dataverse during onboard auth phase.
Dependency changes:
System.ServiceModel.Http updated to 8.1.2
REMOVED .net 6.0 Targets. .net 6.0 is no longer in support.

1.2.3:
RequestId on OrganizationRequest is not overridden by random Guid if present. RequestId from ClientRequestBuilder still takes precedence over OrganizationRequest.RequestId
Dependency changes:
Microsoft.Identity.Client updated to 4.66.1
Expand Down
Loading