-
Notifications
You must be signed in to change notification settings - Fork 321
WAM POC [updated] #3874
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
WAM POC [updated] #3874
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,15 @@ | ||||||
| // Licensed to the .NET Foundation under one or more agreements. | ||||||
| // The .NET Foundation licenses this file to you under the MIT license. | ||||||
| // See the LICENSE file in the project root for more information. | ||||||
|
|
||||||
| using System; | ||||||
| using System.Runtime.InteropServices; | ||||||
|
|
||||||
| internal partial class Interop | ||||||
| { | ||||||
| internal partial class Kernel32 | ||||||
| { | ||||||
| [DllImport("kernel32.dll")] | ||||||
|
||||||
| [DllImport("kernel32.dll")] | |
| [DllImport("kernel32.dll", ExactSpelling = true)] |
Copilot
AI
Jan 9, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minimise the use of unmanaged code.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
| // See the LICENSE file in the project root for more information. | ||
|
|
||
| using System; | ||
| using System.Runtime.InteropServices; | ||
|
|
||
|
|
||
| internal partial class Interop | ||
| { | ||
| internal partial class User32 | ||
| { | ||
| internal enum GetAncestorFlags | ||
| { | ||
| GetParent = 1, | ||
| GetRoot = 2, | ||
| /// <summary> | ||
| /// Retrieves the owned root window by walking the chain of parent and owner windows returned by GetParent. | ||
| /// </summary> | ||
| GetRootOwner = 3 | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Retrieves the handle to the ancestor of the specified window. | ||
| /// </summary> | ||
| /// <param name="hwnd">A handle to the window whose ancestor is to be retrieved. | ||
| /// If this parameter is the desktop window, the function returns NULL. </param> | ||
| /// <param name="flags">The ancestor to be retrieved.</param> | ||
| /// <returns>The return value is the handle to the ancestor window.</returns> | ||
| [DllImport("user32.dll", ExactSpelling = true)] | ||
| internal static extern IntPtr GetAncestor(IntPtr hwnd, GetAncestorFlags flags); | ||
|
||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,16 @@ | ||||||||||||||||||||||
| // Licensed to the .NET Foundation under one or more agreements. | ||||||||||||||||||||||
| // The .NET Foundation licenses this file to you under the MIT license. | ||||||||||||||||||||||
| // See the LICENSE file in the project root for more information. | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| using System; | ||||||||||||||||||||||
| using System.Threading; | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| namespace Microsoft.Data.SqlClient | ||||||||||||||||||||||
| { | ||||||||||||||||||||||
| public sealed partial class ActiveDirectoryAuthenticationProvider : SqlAuthenticationProvider | ||||||||||||||||||||||
| { | ||||||||||||||||||||||
| private Func<object> _parentActivityOrWindowFunc = null; | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
|
||||||||||||||||||||||
| /// <summary> | |
| /// Gets the delegate that provides the parent activity or window object for interactive authentication. | |
| /// <para> | |
| /// On Unix platforms, when <see cref="_parentActivityOrWindowFunc"/> is <c>null</c>, this property | |
| /// also evaluates to <c>null</c>. Unlike the Windows implementation, there is no fallback to a | |
| /// console or terminal window handle on Unix. | |
| /// </para> | |
| /// </summary> |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,45 @@ | ||||||||||||||||||||||||||||||||
| // Licensed to the .NET Foundation under one or more agreements. | ||||||||||||||||||||||||||||||||
| // The .NET Foundation licenses this file to you under the MIT license. | ||||||||||||||||||||||||||||||||
| // See the LICENSE file in the project root for more information. | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| using System; | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| namespace Microsoft.Data.SqlClient | ||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||
| public sealed partial class ActiveDirectoryAuthenticationProvider : SqlAuthenticationProvider | ||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||
| private Func<object> _parentActivityOrWindowFunc = null; | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| private Func<object> ParentActivityOrWindow | ||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||
| get | ||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||
| return _parentActivityOrWindowFunc != null ? _parentActivityOrWindowFunc : GetConsoleOrTerminalWindow; | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| set | ||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||
| _parentActivityOrWindowFunc = value; | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| #if NETFRAMEWORK | ||||||||||||||||||||||||||||||||
| /// <include file='../../../../../../doc/snippets/Microsoft.Data.SqlClient/ActiveDirectoryAuthenticationProvider.xml' path='docs/members[@name="ActiveDirectoryAuthenticationProvider"]/SetIWin32WindowFunc/*'/> | ||||||||||||||||||||||||||||||||
| public void SetIWin32WindowFunc(Func<System.Windows.Forms.IWin32Window> iWin32WindowFunc) => SetParentActivityOrWindow(iWin32WindowFunc); | ||||||||||||||||||||||||||||||||
| #endif | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| /// <summary> | ||||||||||||||||||||||||||||||||
| /// | ||||||||||||||||||||||||||||||||
| /// </summary> | ||||||||||||||||||||||||||||||||
| /// <param name="parentActivityOrWindowFunc"></param> | ||||||||||||||||||||||||||||||||
|
Comment on lines
+32
to
+34
|
||||||||||||||||||||||||||||||||
| /// | |
| /// </summary> | |
| /// <param name="parentActivityOrWindowFunc"></param> | |
| /// Sets a callback that returns the parent activity or window to use for interactive authentication dialogs. | |
| /// </summary> | |
| /// <param name="parentActivityOrWindowFunc"> | |
| /// A delegate that returns an object representing the parent activity or window (for example, | |
| /// a <see cref="System.Windows.Forms.IWin32Window"/> or a platform-specific window handle). | |
| /// If this delegate is not provided, the provider falls back to using the console or terminal window handle. | |
| /// </param> | |
| /// <remarks> | |
| /// Call this method before initiating an Azure Active Directory authentication flow that may display UI, | |
| /// so that any interactive dialogs are correctly parented to the specified application window or activity. | |
| /// This is typically used in desktop or GUI applications that host interactive authentication experiences. | |
| /// </remarks> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The INTERACTIVE_AUTH compilation constant is defined for Debug builds in the netfx project but is not defined in the netcore project at all. This means that interactive authentication with broker support will only work in .NET Framework Debug builds or when InteractiveAuthEnabled is explicitly set to true. The netcore project needs a similar conditional compilation setup to enable broker authentication support, otherwise the new broker authentication code will never be compiled for .NET Core/NET builds.