Skip to content

Commit 75f4e7d

Browse files
authored
Update MSAL libraries and use new MSALRuntime-based broker implementation (#1191)
Use the new Windows broker which is based on the MSALRuntime; an export wrapper around a native, cross-platform MSAL library. In this new set up, we drop the `.Desktop` package in favour of the `.Broker` package that also means we drop the WebView2Loader.dll, which we didn't make use of anyway. There are a few new binaries to be distributed in the new model, including a P/Invoke layer, IdentityModel abstractions library, and the native `msalruntime_x86.dll`. Note that GCM still only support x86 on Windows, and only supports broker use on Windows. For this reason we don't bother adding the broker package on non-.NET Framework builds to keep the sizes on Mac/Linux to a minimum. Also update the MSAL extensions library whilst we are here to pick up various bug fixes, and drop workarounds that are no longer required for this new broker implementation!
2 parents 79ef656 + 68acbc9 commit 75f4e7d

File tree

7 files changed

+271
-204
lines changed

7 files changed

+271
-204
lines changed

src/shared/Core/Authentication/MicrosoftAuthentication.cs

Lines changed: 223 additions & 160 deletions
Large diffs are not rendered by default.

src/shared/Core/Core.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@
1313
<ItemGroup Condition="'$(TargetFramework)' == 'net472'">
1414
<Reference Include="System.Net.Http" />
1515
<Reference Include="System.Web" />
16-
<PackageReference Include="Microsoft.Identity.Client.Desktop" Version="4.37.0" />
16+
<PackageReference Include="Microsoft.Identity.Client.Broker" Version="4.52.0" />
1717
</ItemGroup>
1818

1919
<ItemGroup>
2020
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
21-
<PackageReference Include="Microsoft.Identity.Client" Version="4.37.0" />
22-
<PackageReference Include="Microsoft.Identity.Client.Extensions.Msal" Version="2.19.2" />
21+
<PackageReference Include="Microsoft.Identity.Client" Version="4.52.0" />
22+
<PackageReference Include="Microsoft.Identity.Client.Extensions.Msal" Version="2.28.0" />
2323
<PackageReference Include="System.CommandLine" Version="2.0.0-beta1.21216.1" />
2424
</ItemGroup>
2525

src/shared/Core/Diagnostics/MicrosoftAuthenticationDiagnostic.cs

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,27 +15,8 @@ public MicrosoftAuthenticationDiagnostic(ICommandContext context)
1515

1616
protected override async Task<bool> RunInternalAsync(StringBuilder log, IList<string> additionalFiles)
1717
{
18-
if (MicrosoftAuthentication.CanUseBroker(CommandContext))
19-
{
20-
log.Append("Checking broker initialization state...");
21-
if (MicrosoftAuthentication.IsBrokerInitialized)
22-
{
23-
log.AppendLine(" Initialized");
24-
}
25-
else
26-
{
27-
log.AppendLine(" Not initialized");
28-
log.Append("Initializing broker...");
29-
MicrosoftAuthentication.InitializeBroker();
30-
log.AppendLine("OK");
31-
}
32-
}
33-
else
34-
{
35-
log.AppendLine("Broker not supported.");
36-
}
37-
3818
var msAuth = new MicrosoftAuthentication(CommandContext);
19+
log.AppendLine(msAuth.CanUseBroker() ? "Broker is enabled." : "Broker is not enabled.");
3920
log.AppendLine($"Flow type is: {msAuth.GetFlowType()}");
4021

4122
log.Append("Gathering MSAL token cache data...");

src/shared/Core/Interop/Windows/Native/Kernel32.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,16 @@ public static extern bool SetConsoleMode(
251251
/// </returns>
252252
[DllImport(LibraryName, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode, SetLastError = true)]
253253
public static extern IntPtr LocalFree(IntPtr ptr);
254+
255+
/// <summary>
256+
/// Retrieves the window handle used by the console associated with the calling process.
257+
/// </summary>
258+
/// <returns>
259+
/// The return value is a handle to the window used by the console associated with the calling process or
260+
/// NULL if there is no such associated console.
261+
/// </returns>
262+
[DllImport("kernel32.dll", SetLastError = true)]
263+
public static extern IntPtr GetConsoleWindow();
254264
}
255265

256266
[Flags]

src/shared/Core/Interop/Windows/Native/User32.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,36 @@ public static IntPtr SetWindowLongPtr(IntPtr hWnd, int nIndex, IntPtr value)
3535

3636
[DllImport(LibraryName, SetLastError = true)]
3737
public static extern bool GetClientRect(IntPtr hwnd, out RECT lpRect);
38+
39+
/// <summary>
40+
/// Retrieves the handle to the ancestor of the specified window.
41+
/// </summary>
42+
/// <param name="hwnd">
43+
/// A handle to the window whose ancestor is to be retrieved.
44+
/// If this parameter is the desktop window, the function returns NULL.
45+
/// </param>
46+
/// <param name="flags">The ancestor to be retrieved.</param>
47+
/// <returns>The return value is the handle to the ancestor window.</returns>
48+
[DllImport("user32.dll", SetLastError = true)]
49+
public static extern IntPtr GetAncestor(IntPtr hwnd, GetAncestorFlags flags);
50+
}
51+
52+
public enum GetAncestorFlags
53+
{
54+
/// <summary>
55+
/// Retrieves the parent window. This does not include the owner, as it does with the GetParent function.
56+
/// </summary>
57+
GetParent = 1,
58+
59+
/// <summary>
60+
/// Retrieves the root window by walking the chain of parent windows.
61+
/// </summary>
62+
GetRoot = 2,
63+
64+
/// <summary>
65+
/// Retrieves the owned root window by walking the chain of parent and owner windows returned by GetParent.
66+
/// </summary>
67+
GetRootOwner = 3
3868
}
3969

4070
[StructLayout(LayoutKind.Sequential)]

src/shared/Git-Credential-Manager/Program.cs

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,22 +25,6 @@ public static void Main(string[] args)
2525
// Write the start and version events
2626
context.Trace2.Start(context.ApplicationPath, args);
2727

28-
// Workaround for https://github.com/AzureAD/microsoft-authentication-library-for-dotnet/issues/2560
29-
if (MicrosoftAuthentication.CanUseBroker(context))
30-
{
31-
try
32-
{
33-
MicrosoftAuthentication.InitializeBroker();
34-
}
35-
catch (Exception ex)
36-
{
37-
context.Streams.Error.WriteLine(
38-
"warning: broker initialization failed{0}{1}",
39-
Environment.NewLine, ex.Message
40-
);
41-
}
42-
}
43-
4428
//
4529
// Git Credential Manager's executable used to be named "git-credential-manager-core" before
4630
// dropping the "-core" suffix. In order to prevent "helper not found" errors for users who

src/windows/Installer.Windows/Setup.iss

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -125,20 +125,19 @@ Source: "{#PayloadDir}\Microsoft.AzureRepos.dll"; DestDir:
125125
Source: "{#PayloadDir}\gcmcore.dll"; DestDir: "{app}"; Flags: ignoreversion
126126
Source: "{#PayloadDir}\gcmcoreui.dll"; DestDir: "{app}"; Flags: ignoreversion
127127
Source: "{#PayloadDir}\gcmcoreuiwpf.dll"; DestDir: "{app}"; Flags: ignoreversion
128-
Source: "{#PayloadDir}\Microsoft.Identity.Client.Desktop.dll"; DestDir: "{app}"; Flags: ignoreversion
128+
Source: "{#PayloadDir}\Microsoft.Identity.Client.Broker.dll"; DestDir: "{app}"; Flags: ignoreversion
129129
Source: "{#PayloadDir}\Microsoft.Identity.Client.dll"; DestDir: "{app}"; Flags: ignoreversion
130130
Source: "{#PayloadDir}\Microsoft.Identity.Client.Extensions.Msal.dll"; DestDir: "{app}"; Flags: ignoreversion
131-
Source: "{#PayloadDir}\Microsoft.Web.WebView2.Core.dll"; DestDir: "{app}"; Flags: ignoreversion
132-
Source: "{#PayloadDir}\Microsoft.Web.WebView2.WinForms.dll"; DestDir: "{app}"; Flags: ignoreversion
133-
Source: "{#PayloadDir}\Microsoft.Web.WebView2.Wpf.dll"; DestDir: "{app}"; Flags: ignoreversion
131+
Source: "{#PayloadDir}\Microsoft.Identity.Client.NativeInterop.dll"; DestDir: "{app}"; Flags: ignoreversion
132+
Source: "{#PayloadDir}\Microsoft.IdentityModel.Abstractions.dll"; DestDir: "{app}"; Flags: ignoreversion
133+
Source: "{#PayloadDir}\msalruntime_x86.dll"; DestDir: "{app}"; Flags: ignoreversion
134134
Source: "{#PayloadDir}\Newtonsoft.Json.dll"; DestDir: "{app}"; Flags: ignoreversion
135135
Source: "{#PayloadDir}\NOTICE"; DestDir: "{app}"; Flags: ignoreversion
136136
Source: "{#PayloadDir}\System.Buffers.dll"; DestDir: "{app}"; Flags: ignoreversion
137137
Source: "{#PayloadDir}\System.CommandLine.dll"; DestDir: "{app}"; Flags: ignoreversion
138138
Source: "{#PayloadDir}\System.Memory.dll"; DestDir: "{app}"; Flags: ignoreversion
139139
Source: "{#PayloadDir}\System.Numerics.Vectors.dll"; DestDir: "{app}"; Flags: ignoreversion
140140
Source: "{#PayloadDir}\System.Runtime.CompilerServices.Unsafe.dll"; DestDir: "{app}"; Flags: ignoreversion
141-
Source: "{#PayloadDir}\WebView2Loader.dll"; DestDir: "{app}"; Flags: ignoreversion
142141

143142
[Code]
144143
// Don't allow installing conflicting architectures

0 commit comments

Comments
 (0)