Skip to content

Provide an option for embedded or system browser with Azure interactive authentication #2611

Description

@thenextman

Azure interactive logins call the MSAL function AcquireTokenInteractive. The source code comments clearly explain the differences in default behaviour between browsers and .NET versions vis whether an embedded browser or the system browser is used for login. But in all cases, SqlClient does use the default behaviour of MSAL.

It would be better if the consumer application could choose whether an integrated or system browser is used, and this is supported by MSAL via WithUseEmbeddedWebView. What is missing is an option for the consumer to choose the behaviour here.

There is currently no alternative apart from to accept the default, or fork SqlClient and make the change ourselves.

At a higher level, this same feature was added to Azure.Identity based on our feature request so I believe that shows the worth in the idea. It's not an option here since SqlClient uses MSAL directly without an intermediate library (as far as I can tell).

Activity

  1. arellegue commented on Jun 27, 2024

    @arellegue
    Contributor

    We will discuss this and see it is feasible then back to you.

  2. thenextman commented on Jan 15, 2025

    @thenextman
    Author

    Hello, just wondering if there is any traction on this issue? It comes from a real business need.

    The customer environment has conditional access configured on access to Azure SQL resources, and only a specific set of device IDs are allowed to access it. If staff are using firefox or chrome, the device ID does not get sent on and in the Azure sign in logs it shows as device unknown, therefore the staff are prevented from accessing the resource and unable to login. If we set Edge as the default browser - Edge does pass on the device ID and staff can login.

    It leaves two options: turn off conditional access, or force users to set their default browser to Edge.

    Consider that this used to work with the application modal prompt - it's only since updating to .NET Core that we got the new behaviour of using the system browser that broke this use case.

    When I complained about the reverse problem with Azure.Identity (I wanted the browser popup option instead of the application popup on .NET Framework), they implemented the controls on top of MSAL to allow us to choose which method worked best for us. The same control here would be appreciated.

  3. thenextman commented on Apr 19, 2025

    @thenextman
    Author

    Any traction on this issue? From my side, I've resorted to patching MSAL using Harmony. It's basically a two-line change to get this functionality, plus whatever boilerplate you need on top to make it configurable. It would be appreciated if this was an option in SqlClient.

  4. moved this from To triage to Backlog in SqlClient Boardon Dec 3, 2025
  5. David-Engel commented on Dec 5, 2025

    @David-Engel
    Contributor

    You can always create a custom provider that overrides the MDS implementation for Authentication=ActiveDirectoryInteractive. There is an example that shows overriding the ActiveDirectoryDeviceCodeFlow option here:
    https://learn.microsoft.com/en-us/sql/connect/ado-net/sql/azure-active-directory-authentication?view=sql-server-ver16#support-for-a-custom-sql-authentication-provider
    Any of the options can be overridden. You can even override them without app code changes by modifying the app.config.

    Example:

    app.config

    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
        <configSections>
            <section name="SqlClientAuthenticationProviders" type="Microsoft.Data.SqlClient.SqlAuthenticationProviderConfigurationSection, Microsoft.Data.SqlClient" />
        </configSections>
        <SqlClientAuthenticationProviders>
            <providers>
                <add name="Active Directory Integrated" type="CustomAuthProvider.CustomInteractiveAuthProvider, CustomAuthProvider" />
            </providers>
        </SqlClientAuthenticationProviders>
    </configuration>
    

    Provider

    using Microsoft.Data.SqlClient;
    using Microsoft.Identity.Client;
    using System;
    using System.Threading.Tasks;
    
    namespace CustomAuthProvider
    {
        public class CustomInteractiveAuthProvider : SqlAuthenticationProvider
        {
            const string s_clientId = "your-client-id-here"; // Replace with your registered app/client ID
            public override async Task<SqlAuthenticationToken> AcquireTokenAsync(SqlAuthenticationParameters parameters)
            {
                // Implement custom MSAL Interactive authentication logic here
                // For example:
                var app = PublicClientApplicationBuilder.Create(s_clientId)
                    .WithAuthority(parameters.Authority)
                    .WithRedirectUri("http://localhost")
                    .Build();
                string scope = parameters.Resource.EndsWith("/.default", StringComparison.Ordinal) ? parameters.Resource : parameters.Resource + "/.default";
                string[] scopes = new string[] { scope };
                var result = await app.AcquireTokenInteractive(scopes).WithUseEmbeddedWebView(true).ExecuteAsync();
                if (string.IsNullOrEmpty(result.AccessToken))
                {
                    throw new Exception("Access token is not provided.");
                }
    
                return new SqlAuthenticationToken(result.AccessToken, result.ExpiresOn);
            }
    
            public override bool IsSupported(SqlAuthenticationMethod authenticationMethod)
            {
                return authenticationMethod.Equals(SqlAuthenticationMethod.ActiveDirectoryInteractive);
            }
        }
    }
    
  6. priyankatiwari08 commented on Sep 17, 2026

    @priyankatiwari08
    Contributor

    /triage

  7. github-actions commented on Sep 17, 2026

    @github-actions

    🔍 Triage Summary (on-demand re-triage)

    Check Result
    Issue type Feature
    Environment Not applicable (feature request, not a bug)
    Area Area\Netcore (Azure AD/Entra ID interactive authentication via ActiveDirectoryAuthenticationProvider, MSAL AcquireTokenInteractive browser selection)
    Duplicates None found
    Regression Not indicated as a regression per se, but a real behavior change was noted: the reporter states the previous "application modal prompt" (embedded browser) behavior on .NET Framework was replaced by system-browser behavior on .NET Core, which broke a conditional-access/device-ID scenario. This is a default-behavior change across frameworks rather than a version-boundary bug.

    Analysis

    The request asks that Microsoft.Data.SqlClient expose a connection-string or API-level option to select embedded vs. system browser for Authentication=ActiveDirectoryInteractive, mirroring MSAL's WithUseEmbeddedWebView and the equivalent feature already added to Azure.Identity. Currently ActiveDirectoryAuthenticationProvider.cs relies on MSAL's default browser-selection behavior with no consumer override, forcing users to fork the library or implement a custom SqlAuthenticationProvider (a workaround already documented by a maintainer in this thread). This has a real business impact (conditional access / device ID policies) reported by multiple commenters over ~18 months. Severity: P2 (valid, low-risk feature enhancement with existing workaround, moderate community interest).

    Next Steps

    • A maintainer has already provided a documented workaround (custom SqlAuthenticationProvider overriding AcquireTokenAsync with WithUseEmbeddedWebView), which unblocks affected consumers today. This should continue to be pointed to for anyone hitting this in the interim.
    • Recommend assigning to Copilot coding agent to implement a first-class option: add a new SqlConnectionStringBuilder/SqlAuthenticationParameters setting (e.g. Use Embedded Web View or similar) that flows through ActiveDirectoryAuthenticationProvider.cs to PublicClientApplication.AcquireTokenInteractive(...).WithUseEmbeddedWebView(bool). Investigation should cover: (1) adding the new connection string keyword and its parser/builder wiring, (2) updating SqlAuthenticationParameters to carry the flag, (3) default value selection to preserve current behavior for backward compatibility, (4) updates to ref/ reference assemblies since this is a public API surface change, and (5) unit/functional tests plus a doc/samples/ sample demonstrating the new option.
    • Since this is a public API addition, ensure the change is reviewed against .github/instructions/api-design.instructions.md guidance before implementation.

    Note: This triage summary is auto-generated by an AI agent. The analysis and suggestions above have not been verified by a human maintainer. Please treat as preliminary guidance only.

    Generated by SqlClient Issue Auto-Triage for #2611 · copilot · auto · 72.5 AIC · ⌖ 13.1 AIC · ⊞ 11.9K · ◷

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions