Skip to content

Commit

Permalink
Retarget framework from net6-windows10.0.17763.0 to net6-windows (#…
Browse files Browse the repository at this point in the history
…819)

This update addresses a breaking change in the `Microsoft.Identity.Client` library, which has removed support for the `net6.0-windows7.0` binary. To maintain compatibility for desktop applications targeting `net6.0-windows`, the `Microsoft.Identity.Client.Desktop` dependency has been added. This change ensures that authentication using a browser, with the method `WithWindowsEmbeddedBrowserSupport()`, continues to work seamlessly. See AzureAD/microsoft-authentication-library-for-dotnet#4468

Additionally, this update allows us to remove the dependency on the `Microsoft.Windows.SDK` framework, which has resulted in a reduction of installed binary sizes.
  • Loading branch information
albertospelta authored Sep 19, 2024
1 parent b03faf4 commit b888de6
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/Bravo.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net6-windows10.0.17763.0</TargetFramework>
<SupportedOSPlatformVersion>7.0</SupportedOSPlatformVersion>
<TargetFramework>net6-windows</TargetFramework>
<UseWindowsForms>True</UseWindowsForms>
<ApplicationIcon>Assets\bravo.ico</ApplicationIcon>
<Company>SQLBI</Company>
Expand Down Expand Up @@ -67,6 +66,7 @@
<PackageReference Include="Macross.Json.Extensions" Version="3.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.ApplicationInsights" Version="2.22.0" />
<PackageReference Include="Microsoft.Web.WebView2" Version="1.0.2739.15" />
<PackageReference Include="Microsoft.Identity.Client.Desktop" Version="4.64.1" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.7.3" PrivateAssets="all" />
<PackageReference Include="System.CommandLine" Version="2.0.0-beta4.22272.1" />
<PackageReference Include="System.Management" Version="7.0.0" />
Expand Down
14 changes: 8 additions & 6 deletions src/Infrastructure/Helpers/MsalHelper.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
namespace Sqlbi.Bravo.Infrastructure.Helpers
{
using Microsoft.Identity.Client;
using Microsoft.Identity.Client.Desktop;
using Sqlbi.Bravo.Infrastructure.Configuration;
using Sqlbi.Bravo.Infrastructure.Models;
using Sqlbi.Bravo.Infrastructure.Models.PBICloud;
Expand All @@ -20,7 +21,13 @@ public static IPublicClientApplication CreatePublicClientApplication(IPBICloudEn
var authorityUri = pbicloudEnvironment.AzureADAuthority;

// TODO: should we add logging .WithLogging() ??
var publicClient = PublicClientApplicationBuilder.Create(pbicloudEnvironment.AzureADClientId).WithAuthority(authorityUri).WithRedirectUri(redirectUri).Build();
var builder = PublicClientApplicationBuilder.Create(pbicloudEnvironment.AzureADClientId).WithAuthority(authorityUri).WithRedirectUri(redirectUri);
{
if (useEmbeddedBrowser)
builder.WithWindowsEmbeddedBrowserSupport();
}
var publicClient = builder.Build();

TokenCacheHelper.RegisterCache(publicClient.UserTokenCache);

return publicClient;
Expand All @@ -41,11 +48,6 @@ public static async Task<IAuthenticationResult> AcquireTokenSilentAsync(string u

public static async Task<IAuthenticationResult> AcquireTokenInteractiveAsync(string userPrincipalName, IPBICloudEnvironment environment, string claims, CancellationToken cancellationToken)
{
// *** EmbeddedWebView requirements ***
// Requires VS project OutputType=WinExe and the 'windows10.0.17763.0' OS version in TargetFramework
// The TargetFramework OS 'windows10.0.17763.0' requires 'Microsoft.Windows.SDK.NET' as project dependency.
// The 'Microsoft.Windows.SDK.NET' includes all the WPF(PresentationFramework.dll) and WinForm(System.Windows.Forms.dll) assemblies to the project.

var useEmbeddedBrowser = !UserPreferences.Current.UseSystemBrowserForAuthentication;
var extraQueryParameters = MicrosoftAccountOnlyQueryParameter;
var prompt = Prompt.SelectAccount; // Force a sign-in as the MSAL web browser might contain cookies for the current user and we don't necessarily want to re-sign-in the same user
Expand Down
2 changes: 1 addition & 1 deletion test/Bravo.Tests/Bravo.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6-windows10.0.17763.0</TargetFramework>
<TargetFramework>net6-windows</TargetFramework>
<SupportedOSPlatformVersion>7.0</SupportedOSPlatformVersion>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
Expand Down

0 comments on commit b888de6

Please sign in to comment.