Skip to content

Commit 4ed7e5b

Browse files
authored
Merge pull request #505 from microsoft/release/update/250404053222
Resync from mainline.
2 parents dab25f4 + c9fe292 commit 4ed7e5b

19 files changed

+48
-68
lines changed

src/Build.Common.StandardAndLegacy.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
</PropertyGroup>
55

66
<PropertyGroup Condition="'$(TargetFrameworks)' == ''">
7-
<TargetFrameworks Condition="'$(OutputType)' == 'Exe'">net6.0;net48;net462</TargetFrameworks>
7+
<TargetFrameworks Condition="'$(OutputType)' == 'Exe'">net8.0;net48;net462</TargetFrameworks>
88
<TargetFrameworks Condition="'$(OutputType)' != 'Exe'">netstandard2.0;net48;net462</TargetFrameworks>
99
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
1010
</PropertyGroup>

src/Build.Common.core.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
</PropertyGroup>
66

77
<PropertyGroup Condition="'$(ProjectSpecificFx)' == ''">
8-
<TargetFrameworks>net462;net472;net48;netstandard2.0;net6.0;net8.0</TargetFrameworks>
8+
<TargetFrameworks>net462;net472;net48;netstandard2.0;net8.0</TargetFrameworks>
99
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
1010
<NoWarn>NU5104</NoWarn>
1111
</PropertyGroup>

src/GeneralTools/DataverseClient/Client/Auth/AuthProcessor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ internal async static Task<ExecuteAuthenticationResults> ExecuteAuthenticateServ
152152
if (userCert != null)
153153
{
154154
logSink.Log("Initial ObtainAccessToken - CERT", TraceEventType.Verbose);
155-
cApp = cAppBuilder.WithCertificate(userCert).Build();
155+
cApp = cAppBuilder.WithCertificate(userCert, true).Build();
156156
memoryBackedTokenCache.Initialize(cApp.AppTokenCache);
157157
_authenticationResult = await ObtainAccessTokenAsync(cApp, Scopes, logSink).ConfigureAwait(false);
158158
}

src/GeneralTools/DataverseClient/Client/Auth/AuthorityResolver.cs

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Diagnostics;
4-
using System.Linq;
54
using System.Net;
65
using System.Net.Http;
76
using System.Threading.Tasks;
@@ -28,6 +27,11 @@ public sealed class AuthenticationDetails
2827
/// OAuth resource to request authentication for.
2928
/// </summary>
3029
public Uri Resource { get; internal set; }
30+
31+
/// <summary>
32+
/// Error message if probing failed.
33+
/// </summary>
34+
public string ErrorMessage { get; internal set; } = string.Empty;
3135
}
3236

3337
/// <summary>
@@ -57,7 +61,7 @@ public AuthorityResolver(HttpClient httpClient, Action<TraceEventType, string> l
5761
}
5862

5963
/// <summary>
60-
/// Attemtps to solicit a WWW-Authenticate reply using an unauthenticated GET call to the given endpoint.
64+
/// Attempts to solicit a WWW-Authenticate reply using an unauthenticated GET call to the given endpoint.
6165
/// Parses returned header for details
6266
/// </summary>
6367
/// <param name="endpoint">endpoint to challenge for authority and resource</param>
@@ -81,28 +85,31 @@ public async Task<AuthenticationDetails> ProbeForExpectedAuthentication(Uri endp
8185
{
8286
errDetails = $"; details: {wex.Message} ({wex.Status})";
8387
}
84-
LogError($"Failed to get response from: {endpoint}; error: {ex.Message}{errDetails}");
88+
89+
details.ErrorMessage = $"Failed to get response from: {endpoint}; error: {ex.Message}{errDetails}";
90+
LogError(details.ErrorMessage);
8591
return details;
8692
}
8793

8894

8995
if (response.StatusCode == HttpStatusCode.NotFound || response.StatusCode == HttpStatusCode.BadRequest)
9096
{
9197
// didn't find endpoint.
92-
LogError($"Failed to get Authority and Resource error. Attempt to Access Endpoint {endpoint} resulted in {response.StatusCode}.");
98+
details.ErrorMessage = $"Failed to get Authority and Resource error. Attempt to Access Endpoint {endpoint} resulted in {response.StatusCode}.";
99+
LogError(details.ErrorMessage);
93100
return details;
94101
}
95102

96103
if (response.Headers.Contains(AuthenticateHeader))
97104
{
98105
var authenticateHeaders = response.Headers.GetValues(AuthenticateHeader);
99106
// need to support OnPrem returning multiple Authentication headers.
100-
foreach (var authenticateHeaderraw in authenticateHeaders)
107+
foreach (var authenticateHeaderRaw in authenticateHeaders)
101108
{
102109
if (details.Success)
103110
break;
104111

105-
string authenticateHeader = authenticateHeaderraw.Trim();
112+
string authenticateHeader = authenticateHeaderRaw.Trim();
106113

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

115-
LogError($"Malformed 'Bearer' format: {authenticateHeader}");
122+
details.ErrorMessage = $"Malformed 'Bearer' format: {authenticateHeader}";
123+
LogError(details.ErrorMessage);
116124
return details;
117125
}
118126

@@ -126,15 +134,17 @@ public async Task<AuthenticationDetails> ProbeForExpectedAuthentication(Uri endp
126134
}
127135
catch (ArgumentException)
128136
{
129-
LogError($"Malformed arguments in '{AuthenticateHeader}: {authenticateHeader}");
137+
details.ErrorMessage = $"Malformed arguments in '{AuthenticateHeader}: {authenticateHeader}";
138+
LogError(details.ErrorMessage);
130139
return details;
131140
}
132141

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

144154
if (!authenticateHeaderItems.TryGetValue(ResourceKey, out var res))
145155
{
146-
LogError($"Response header from {endpoint} is missing expected key/value for {ResourceKey}");
156+
details.ErrorMessage = $"Response header from {endpoint} is missing expected key/value for {ResourceKey}";
157+
LogError(details.ErrorMessage);
147158
return details;
148159
}
149160
details.Resource = new Uri(res);

src/GeneralTools/DataverseClient/Client/ServiceClient.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1729,6 +1729,7 @@ public async Task<OrganizationResponse> ExecuteOrganizationRequestAsync(Organiza
17291729

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

17531754
private async Task<OrganizationResponse> ExecuteOrganizationRequestAsyncImpl(OrganizationRequest req, CancellationToken cancellationToken, string logMessageTag = "User Defined", bool useWebAPI = false, bool bypassPluginExecution = false)
17541755
{
1756+
_logEntry.ResetLastError(); // Reset Last Error
17551757
ValidateConnectionLive();
17561758
cancellationToken.ThrowIfCancellationRequested();
17571759
if (req != null)

src/GeneralTools/DataverseClient/Extensions/Microsoft.PowerPlatform.Dataverse.Client.AzAuth/AzAuth.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using Azure.Core;
22
using Azure.Identity;
33
using Microsoft.Extensions.Logging;
4+
using Microsoft.Extensions.Logging.Abstractions;
45
using Microsoft.PowerPlatform.Dataverse.Client.Model;
56
using System;
67
using System.Collections.Generic;
@@ -81,7 +82,7 @@ public AzAuth(bool autoResolveAuthorityAndTenant, DefaultAzureCredentialOptions
8182
{
8283
_credentialOptions = credentialOptions;
8384
_autoResolveAuthorityAndTenant = autoResolveAuthorityAndTenant;
84-
_logger = logger;
85+
_logger = logger ?? NullLogger.Instance;
8586
}
8687

8788
/// <summary>

src/GeneralTools/DataverseClient/Extensions/Microsoft.PowerPlatform.Dataverse.Client.AzAuth/AzPipelineFederatedIdentityAuth.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using Microsoft.PowerPlatform.Dataverse.Client.Model;
77
using System.Diagnostics;
88
using System.Threading.Tasks;
9+
using Microsoft.Extensions.Logging.Abstractions;
910

1011
namespace Microsoft.PowerPlatform.Dataverse.Client
1112
{
@@ -75,7 +76,7 @@ public AzPipelineFederatedIdentityAuth(string tenantId, string clientId, string
7576
_serviceConnectionId = serviceConnectionId;
7677
_systemAccessTokenEnvVarName = SystemAccessTokenEnvVarName;
7778
_autoResolveAuthorityAndTenant = autoResolveAuthorityAndTenant;
78-
_logger = logger;
79+
_logger = logger ?? NullLogger.Instance;
7980
}
8081

8182
/// <summary>

src/GeneralTools/DataverseClient/PowerShell/Microsoft.PowerPlatform.Dataverse.Client.PowerShell/BuildDrop.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ if($RunFromVSBuild -eq $false)
6060
}
6161
else
6262
{
63-
$BinsDirectory = [System.IO.Path]::Combine($BuildSourcesDirectory , "bin" , $BuildConfiguration, "DataverseClient" , "net6.0" )
63+
$BinsDirectory = [System.IO.Path]::Combine($BuildSourcesDirectory , "bin" , $BuildConfiguration, "DataverseClient" , "net8.0" )
6464
}
6565
## Copying PowerShell Module out only.
6666
Write-Host ">>> BINS path is $BinsDirectory"

src/GeneralTools/DataverseClient/PowerShell/Microsoft.PowerPlatform.Dataverse.Client.PowerShell/Microsoft.PowerPlatform.Dataverse.Client.PowerShell.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<PropertyGroup>
1111
<ProjectDir Condition="'$(ProjectDir)' == '' ">$(MSBuildProjectDirectory)\</ProjectDir>
1212
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
13-
<TargetFrameworks>net6.0</TargetFrameworks>
13+
<TargetFrameworks>net8.0</TargetFrameworks>
1414
<ImplicitUsings>enable</ImplicitUsings>
1515
<Nullable>enable</Nullable>
1616
</PropertyGroup>

src/GeneralTools/DataverseClient/UnitTests/AzDevOps_ServiceConnection_Test/AzDevOps_ServiceConnection_Test.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<PropertyGroup>
44
<ProjectSpecificFx>true</ProjectSpecificFx>
55
<OutputType>Exe</OutputType>
6-
<TargetFrameworks>net462;net6.0</TargetFrameworks>
6+
<TargetFrameworks>net462;net8.0</TargetFrameworks>
77
<SignAssembly>false</SignAssembly>
88
<ComponentAreaName>DataverseClient-Tests</ComponentAreaName>
99
<IsPackable>false</IsPackable>

0 commit comments

Comments
 (0)