使用 Microsoft Entra 驗證和 SqlClient 連線至 Azure SQL

適用於:.NET Framework .NET .NET Standard

下載 ADO.NET

此文章說明如何從 .NET 應用程式,搭配 SqlClient 使用 Microsoft Entra 驗證來連線到 Azure SQL 資料來源。

注意

雖然 Microsoft Entra ID 是 Azure Active Directory (Azure AD) 的新名稱,但為了防止干擾現有的環境,Azure AD 仍會保留在某些硬式編碼元素中,如 UI 欄位、連線供應商、錯誤碼與 Cmdlet。 在本文中,這兩個名稱是可交換的。

概觀

Microsoft Entra 驗證會使用 Microsoft Entra ID 中的身分識別來存取資料來源,例如,Azure SQL Database、Azure SQL 受控執行個體與 Azure Synapse Analytics。 Microsoft.Data.SqlClient 命名空間可讓用戶端應用程式在連線到 Azure SQL Database 和 Azure SQL 受控執行個體時,以不同的驗證模式指定 Microsoft Entra 認證。 若要搭配 Azure SQL 使用 Microsoft Entra 驗證,您必須使用 Azure SQL 設定和管理 Microsoft Entra 驗證

當您在連接字串中設定 Authentication 連線屬性時,用戶端可以根據提供的值選擇慣用的 Microsoft Entra 驗證模式:

  • 最早的 Microsoft.Data.SqlClient 版本支援適用於 .NET Framework、.NET Core 與 .NET Standard 的 Active Directory Password。 該版本也支援適用於 .NET Framework 的 Active Directory Integrated 驗證與 Active Directory Interactive 驗證。

  • Microsoft.Data.SqlClient 2.0.0 開始,將對 Active Directory Integrated 驗證與 Active Directory Interactive 驗證的支援延伸到 .NET Framework、.NET Core 與 .NET Standard。

    同時也在 SqlClient 2.0.0 中新增了新的 Active Directory Service Principal 驗證模式。 此模式會使用服務主體身分識別的用戶端識別碼與祕密來完成驗證。

  • Microsoft.Data.SqlClient 2.1.0 中新增了更多驗證模式,包括 Active Directory Device Code FlowActive Directory Managed Identity (也稱為 Active Directory MSI)。 這些新模式可讓應用程式取得存取權杖以連線到伺服器。

如需下列各節所描述之外的 Microsoft Entra 驗證相關資訊,請參閱<使用 Microsoft Entra 驗證>。

設定 Microsoft Entra 驗證

使用 Microsoft Entra 驗證來將應用程式連線到 Azure SQL 資料來源時,其必須提供有效的驗證模式。 下表列出支援的驗證模式。 應用程式會使用連接字串中的 Authentication 連線屬性來指定模式。

描述 Microsoft.Data.SqlClient 版本
Active Directory 密碼 使用 Microsoft Entra 身分識別的使用者名稱和密碼來進行驗證 1.0+
Active Directory 整合式 使用整合式 Windows 驗證 (IWA) 向 Microsoft Entra 身分識別進行驗證 2.0.0+1
Active Directory 互動式 使用互動式驗證,以 Microsoft Entra 身分識別進行驗證 2.0.0+1
Active Directory 服務主體 使用 Microsoft Entra 服務主體的用戶端識別碼和祕密進行驗證 2.0.0+
Active Directory 裝置程式碼流程 使用裝置程式碼流程模式,以 Microsoft Entra 身分識別進行驗證 2.1.0+
Active Directory 受控識別、
Active Directory MSI
使用 Microsoft Entra 系統指派或使用者指派的受控識別來進行驗證 2.1.0+
Active Directory Default 使用無密碼和非互動式機制驗證 Microsoft Entra 身分識別,包括受控識別、Visual Studio Code、Visual Studio、Azure CLI 等。 3.0.0+
Active Directory 工作負載身分識別 使用同盟使用者指派的受控識別,以 Microsoft Entra 身分識別進行驗證,以從已啟用工作負載識別支援的 Azure 用戶端環境連線到 SQL 資料庫。 5.2.0+

1Microsoft.Data.SqlClient 2.0.0 的之前版本,.NET Framework 僅支援 Active Directory IntegratedActive Directory Interactive 驗證模式。

使用密碼驗證

Active Directory Password 驗證模式支援使用適用於原生或同盟 Microsoft Entra 使用者的 Microsoft Entra ID,來向 Azure 資料來源進行驗證。 當您使用此模式時,必須在連接字串中提供使用者認證。 下列範例示範如何使用 Active Directory Password 驗證。

// Use your own server, database, user ID, and password.
string ConnectionString = @"Server=demo.database.windows.net; Authentication=Active Directory Password; Encrypt=True; Database=testdb; User Id=user@domain.com; Password=***";

using (SqlConnection conn = new SqlConnection(ConnectionString)) {
    conn.Open();
}

使用整合式驗證

若要使用 Active Directory Integrated 驗證模式,您必須有已加入雲端中 Microsoft Entra ID 的內部部署 Active Directory 執行個體。 例如,您可以使用 Active Directory 同盟服務 (AD FS) 進行同盟

當您登入到已加入網域的機器時,便能存取 Azure SQL 資料來源,而不會使用此模式提示您提供認證。 您無法針對 .NET Framework 應用程式,在連接字串中指定使用者名稱與密碼。 使用者名稱在 .NET Core 與 .NET Standard 應用程式的連接字串中是選擇性的。 您無法在此模式中設定 SqlConnection 的 Credential 屬性。

下列程式碼片段是使用 Active Directory Integrated 驗證時的範例。

// Use your own server and database.
string ConnectionString1 = @"Server=demo.database.windows.net; Authentication=Active Directory Integrated; Encrypt=True; Database=testdb";

using (SqlConnection conn = new SqlConnection(ConnectionString1)) {
    conn.Open();
}

// User ID is optional for .NET Core and .NET Standard.
string ConnectionString2 = @"Server=demo.database.windows.net; Authentication=Active Directory Integrated; Encrypt=True; Database=testdb; User Id=user@domain.com";

using (SqlConnection conn = new SqlConnection(ConnectionString2)) {
    conn.Open();
}

使用互動式驗證

Active Directory Interactive 驗證支援多重要素驗證技術,以連線至 Azure SQL 資料來源。 如果您在連接字串中提供此驗證模式,則會出現 Azure 驗證畫面,並要求使用者輸入有效的認證。 您無法在連接字串中指定密碼。

您無法在此模式中設定 SqlConnection 的 Credential 屬性。 使用 Microsoft.Data.SqlClient* 2.0.0 與更新版本,當您處於互動模式時,連接字串中允許使用者名稱。

下列範例示範如何使用 Active Directory Interactive 驗證。

// Use your own server, database, and user ID.
// User ID is optional.
string ConnectionString1 = @"Server=demo.database.windows.net; Authentication=Active Directory Interactive; Encrypt=True; Database=testdb; User Id=user@domain.com";

using (SqlConnection conn = new SqlConnection(ConnectionString1)) {
    conn.Open();
}

// User ID is not provided.
string ConnectionString2 = @"Server=demo.database.windows.net; Authentication=Active Directory Interactive; Encrypt=True; Database=testdb";

using (SqlConnection conn = new SqlConnection(ConnectionString2)) {
    conn.Open();
}

使用服務主體驗證

Active Directory Service Principal 驗證模式中,用戶端應用程式可透過提供服務主體身分識別的用戶端識別碼與祕密來連線到 Azure SQL 資料來源。 服務主體驗證包括:

  1. 使用祕密設定應用程式註冊。
  2. 將權限授與 Azure SQL Database 執行個體中的應用程式。
  3. 使用正確的認證進行連線。

下列範例示範如何使用 Active Directory Service Principal 驗證。

// Use your own server, database, app ID, and secret.
string ConnectionString = @"Server=demo.database.windows.net; Authentication=Active Directory Service Principal; Encrypt=True; Database=testdb; User Id=AppId; Password=secret";

using (SqlConnection conn = new SqlConnection(ConnectionString)) {
    conn.Open();
}

使用裝置程式碼流程驗證

使用適用於 .NET (MSAL.NET) 的 Microsoft 驗證程式庫時,Active Directory Device Code Flow 驗證可讓用戶端應用程式從不具互動式網頁瀏覽器的裝置與作業系統連線到 Azure SQL 資料來源。 互動式驗證會在另一部裝置上執行。 如需裝置程式碼流程驗證的詳細資訊,請參閱 OAuth 2.0 裝置程式碼流程

使用此模式時,您無法設定 SqlConnectionCredential 屬性。 此外,也不能在連接字串中指定使用者名稱與密碼。

下列程式碼片段是使用 Active Directory Device Code Flow 驗證的範例。

注意

Active Directory Device Code Flow 的逾時預設為連線的 Connect Timeout 設定。 請務必指定 Connect Timeout 以提供足夠的時間來通過裝置程式碼流程驗證流程。

// Use your own server and database and increase Connect Timeout as needed for device code flow.
string ConnectionString = @"Server=demo.database.windows.net; Authentication=Active Directory Device Code Flow; Encrypt=True; Database=testdb; Connect Timeout=180;";

using (SqlConnection conn = new SqlConnection(ConnectionString)) {
    conn.Open();
}

使用受控識別驗證

使用 Azure 資源的受控識別進行驗證,是對 SQL 進行程式設計存取的建議驗證方法。 用戶端應用程式可以使用資源的系統指派或使用者指派的受控識別,藉由提供身分識別並將其用來取得存取權杖,以使用 Microsoft Entra ID 向 SQL 進行驗證。 此方法不需要管理認證和祕密,且可以簡化存取管理。

受控身分識別有兩種:

  • 系統指派的受控識別會建立為 Azure 資源的一部分 (例如 SQL 受控執行個體或邏輯伺服器),並共用該資源的生命週期。 系統指派的身分識別只能與單一 Azure 資源建立關聯。
  • 「使用者指派的受控識別」會以獨立 Azure 資源的形式來建立。 其可指派給 Azure 服務的一或多個執行個體。

如需受控識別的詳細資訊,請參閱關於 Azure 資源受控識別

Microsoft.Data.SqlClient 2.1.0 開始,驅動程式可透過受控識別取得存取權杖,以支援向 Azure SQL Database、Azure Synapse Analytics 與 Azure SQL 受控執行個體進行驗證。 若要使用此驗證,請在連接字串中指定 Active Directory Managed IdentityActive Directory MSI,而且不需任何密碼。 您也無法在此模式中設定 SqlConnectionCredential 屬性。

針對使用者指派的受控識別,在使用 Microsoft.Data.SqlClient v3.0 或更新版本時,必須提供受控識別的用戶端識別碼。 如果使用 Microsoft.Data.SqlClient v2.1,則必須提供受控識別的物件識別碼

下列範例示範如何搭配系統指派的受控識別使用 Active Directory Managed Identity 驗證。

// For system-assigned managed identity
// Use your own values for Server and Database.
string ConnectionString1 = @"Server=demo.database.windows.net; Authentication=Active Directory Managed Identity; Encrypt=True; Database=testdb";

using (SqlConnection conn = new SqlConnection(ConnectionString1)) {
    conn.Open();
}

string ConnectionString2 = @"Server=demo.database.windows.net; Authentication=Active Directory MSI; Encrypt=True; Database=testdb";

using (SqlConnection conn = new SqlConnection(ConnectionString2)) {
    conn.Open();
}

下列範例示範使用 Microsoft.Data.SqlClient v3.0 及更新版本的使用者指派受控識別進行 Active Directory Managed Identity 驗證。

// For user-assigned managed identity
// Use your own values for Server, Database, and User Id.

// With Microsoft.Data.SqlClient v3.0+
string ConnectionString1 = @"Server=demo.database.windows.net; Authentication=Active Directory Managed Identity; Encrypt=True; User Id=ClientIdOfManagedIdentity; Database=testdb";

using (SqlConnection conn = new SqlConnection(ConnectionString1)) {
    conn.Open();
}

// With Microsoft.Data.SqlClient v3.0+
string ConnectionString2 = @"Server=demo.database.windows.net; Authentication=Active Directory MSI; Encrypt=True; User Id=ClientIdOfManagedIdentity; Database=testdb";

using (SqlConnection conn = new SqlConnection(ConnectionString2)) {
    conn.Open();
}

下列範例示範使用 Microsoft.Data.SqlClient v2.1 的使用者指派受控識別進行 Active Directory Managed Identity 驗證。

// For user-assigned managed identity
// Use your own values for Server, Database, and User Id.

// With Microsoft.Data.SqlClient v2.1
string ConnectionString1 = @"Server=demo.database.windows.net; Authentication=Active Directory Managed Identity; Encrypt=True; User Id=ObjectIdOfManagedIdentity; Database=testdb";

using (SqlConnection conn = new SqlConnection(ConnectionString1)) {
    conn.Open();
}

// With Microsoft.Data.SqlClient v2.1
string ConnectionString2 = @"Server=demo.database.windows.net; Authentication=Active Directory MSI; Encrypt=True; User Id=ObjectIdOfManagedIdentity; Database=testdb";

using (SqlConnection conn = new SqlConnection(ConnectionString2)) {
    conn.Open();
}

使用預設驗證

從 3.0 版開始,此驗證模式可擴大使用者驗證的可能性。 此模式可將登入解決方案延伸至用戶端環境、Visual Studio Code、Visual Studio、Azure CLI 等。

若使用此驗證模式,驅動程式可取得權杖,其方式為從 Azure 身分識別程式庫傳遞「DefaultAzureCredential」來取得存取權杖。 這個模式會嘗試使用一組認證類型,按順序取得存取權杖: 依據所使用的 Azure 身分識別媒體櫃版本,認證集合會有所不同。 清單中會指出版本特定的差異。 如需 Azure 身分識別版本特定行為,請參閱<Azure.Identity API 文件>。

  • EnvironmentCredential
    • 使用用戶端搭配祕密或使用者名稱搭配密碼來啟用對 Microsoft Entra ID 的驗證,詳細資料須透過下列環境變數設定:AZURE_TENANT_ID、AZURE_CLIENT_ID、AZURE_CLIENT_SECRET、AZURE_CLIENT_CERTIFICATE_PATH、AZURE_USERNAME、AZURE_PASSWORD (其他詳細資訊)
  • WorkloadIdentityCredential
    • 在 Kubernetes 及其他支援工作負載身分識別的主機上啟用 Microsoft Entra 工作負載 ID 驗證。 如需詳細資訊,請參閱 Microsoft Entra 工作負載 ID。 從 Azure Identity 1.10 版和 Microsoft.Data.SqlClient 5.1.4 版開始提供。
  • ManagedIdentityCredential
    • 嘗試使用指派給部署環境的受控識別,向 Microsoft Entra ID 進行驗證。 「使用者指派的受控識別」的「用戶端識別碼」是從「使用者識別碼」連線屬性讀取。
  • SharedTokenCacheCredential
    • 使用 Microsoft 應用程式之間共用本機快取中的權杖進行驗證。
  • VisualStudioCredential
    • 使用 Visual Studio 中的資料,啟用對 Microsoft Entra ID 的驗證
  • VisualStudioCodeCredential
    • 使用來自 Visual Studio Code 的資料,啟用對 Microsoft Entra ID 的驗證。
  • AzurePowerShellCredential
    • 使用 Azure PowerShell 啟用對 Microsoft Entra ID 的驗證。 從 Azure Identity 1.6 版和 Microsoft.Data.SqlClient 5.0 版開始提供。
  • AzureCliCredential
    • 使用 Azure CLI 來啟用對 Microsoft Entra ID 的驗證,以取得存取權杖。
  • AzureDeveloperCliCredential
    • 使用 Azure 開發人員 CLI 來啟用對 Microsoft Entra ID 的驗證,以取得存取權杖。 從 Azure Identity 1.10 版和 Microsoft.Data.SqlClient 5.1.4 版開始提供。

注意

「Active Directory Default」其驅動程式實作中的 InteractiveBrowserCredential 處於停用狀態,而「Active Directory Interactive」是使用 MFA/互動式驗證取得權杖的唯一可用選項。

目前無法使用其他自訂選項。

下列範例示範如何使用 Active Directory Default 驗證。

// Use your own server, database
string ConnectionString = @"Server=demo.database.windows.net; Authentication=Active Directory Default; Encrypt=True; Database=testdb;";

using (SqlConnection conn = new SqlConnection(ConnectionString)) {
    conn.Open();
}

使用工作負載身分識別驗證

從 5.2 版開始可用,例如使用受控識別,工作負載身分識別驗證模式會在指定時,在其用戶端標識碼的 連接字串 中使用使用者標識元參數的值。 但與受控識別不同,WorkloadIdentityCredentialOptions 會從環境變數預設其值:AZURE_TENANT_ID、AZURE_CLIENT_ID和AZURE_FEDERATED_TOKEN_FILE。 不過,連接字串 只能覆寫用戶端標識符。

下列範例示範 Active Directory Workload Identity 使用 Microsoft.Data.SqlClient v5.2 及更新版本的使用者指派受控識別進行驗證。

// Use your own values for Server, Database, and User Id.
// With Microsoft.Data.SqlClient v5.2+
string ConnectionString = @"Server=demo.database.windows.net; Authentication=Active Directory Workload Identity; Encrypt=True; User Id=ClientIdOfManagedIdentity; Database=testdb";

using (SqlConnection conn = new SqlConnection(ConnectionString)) {
    conn.Open();
}

自訂 Microsoft Entra 驗證

除了使用內建於驅動程式的 Microsoft Entra 驗證之外,Microsoft.Data.SqlClient 2.1.0 與更新版本會為應用程式提供自訂 Microsoft Entra 驗證的選項。 自訂會以 ActiveDirectoryAuthenticationProvider 類別為基礎,此類別衍生自 SqlAuthenticationProvider 抽象類別。

在 Microsoft Entra 驗證期間,用戶端應用程式可以透過下列方式定義自己的 ActiveDirectoryAuthenticationProvider 類別:

  • 使用自訂的回呼方法。
  • 透過 SqlClient 驅動程式來將應用程式用戶端識別碼傳遞至 MSAL 程式庫,以擷取存取權杖。

下列範例示範如何在使用 Active Directory Device Code Flow 驗證時使用自訂回呼。

using System;
using System.Threading.Tasks;
using Microsoft.Identity.Client;
using Microsoft.Data.SqlClient;

namespace CustomAuthenticationProviderExamples
{
    public class Program
    {
        public static void Main()
        {
            SqlAuthenticationProvider authProvider = new ActiveDirectoryAuthenticationProvider(CustomDeviceFlowCallback);
            SqlAuthenticationProvider.SetProvider(SqlAuthenticationMethod.ActiveDirectoryDeviceCodeFlow, authProvider);
            using (SqlConnection sqlConnection = new SqlConnection("Server=<myserver>.database.windows.net;Authentication=Active Directory Device Code Flow;Database=<db>;"))
            {
                sqlConnection.Open();
                Console.WriteLine("Connected successfully!");
            }
        }

        private static Task CustomDeviceFlowCallback(DeviceCodeResult result)
        {
            // Provide custom logic to process result information and read device code.
            Console.WriteLine(result.Message);
            return Task.FromResult(0);
        }
    }
}

使用自訂的 ActiveDirectoryAuthenticationProvider 類別,在使用支援的 Microsoft Entra 驗證模式時,可將使用者定義的應用程式用戶端識別碼傳遞至 SqlClient。 支援的 Microsoft Entra 驗證模式包括 Active Directory PasswordActive Directory IntegratedActive Directory InteractiveActive Directory Service PrincipalActive Directory Device Code Flow

應用程式用戶端識別碼也可以透過 SqlAuthenticationProviderConfigurationSectionSqlClientAuthenticationProviderConfigurationSection 來設定。 設定屬性 applicationClientId 適用於 .NET Framework 4.6+ 與 .NET Core 2.1+。

下列程式碼片段是在使用 Active Directory Interactive 驗證時,搭配使用者定義的應用程式用戶端識別碼使用自訂 ActiveDirectoryAuthenticationProvider 類別的範例。

using System;
using Microsoft.Data.SqlClient;

namespace CustomAuthenticationProviderExamples
{
    public class Program
    {
        public static void Main()
        {
            // Supported for all authentication modes supported by ActiveDirectoryAuthenticationProvider
            ActiveDirectoryAuthenticationProvider provider = new ActiveDirectoryAuthenticationProvider("<application_client_id>");
            if (provider.IsSupported(SqlAuthenticationMethod.ActiveDirectoryInteractive))
            {
                SqlAuthenticationProvider.SetProvider(SqlAuthenticationMethod.ActiveDirectoryInteractive, provider);
            }
            
            using (SqlConnection sqlConnection = new SqlConnection("Server=<myserver>.database.windows.net;Authentication=Active Directory Interactive;Database=<db>;"))
            {
                sqlConnection.Open();
                Console.WriteLine("Connected successfully!");
            }
        }
    }
}

下列範例示範如何透過設定區段來設定應用程式用戶端識別碼。

<configuration>
  <configSections>
    <section name="SqlClientAuthenticationProviders"
             type="Microsoft.Data.SqlClient.SqlClientAuthenticationProviderConfigurationSection, Microsoft.Data.SqlClient" />
  </configSections>
  <SqlClientAuthenticationProviders applicationClientId ="<GUID>" />
</configuration>

<!--or-->

<configuration>
  <configSections>
    <section name="SqlAuthenticationProviders"
             type="Microsoft.Data.SqlClient.SqlAuthenticationProviderConfigurationSection, Microsoft.Data.SqlClient" />
  </configSections>
  <SqlAuthenticationProviders applicationClientId ="<GUID>" />
</configuration>

支援自訂的 SQL 驗證提供者

透過更大的彈性,用戶端應用程式也可以使用自己的提供者來進行 Microsoft Entra 驗證,而不需使用 ActiveDirectoryAuthenticationProvider 類別。 自訂驗證提供者必須是具有覆寫方法之 SqlAuthenticationProvider 的子類別。 然後,其必須註冊自訂提供者,並覆寫一或多個現有的 Active Directory* 驗證方法。

下列範例示範如何使用新的驗證提供者來進行 Active Directory Device Code Flow 驗證。

using System;
using System.Threading.Tasks;
using Microsoft.Identity.Client;
using Microsoft.Data.SqlClient;

namespace CustomAuthenticationProviderExamples
{
    /// <summary>
    /// Example demonstrating creating a custom device code flow authentication provider and attaching it to the driver.
    /// This is helpful for applications that wish to override the Callback for the Device Code Result implemented by the SqlClient driver.
    /// </summary>
    public class CustomDeviceCodeFlowAzureAuthenticationProvider : SqlAuthenticationProvider
    {
        public override async Task<SqlAuthenticationToken> AcquireTokenAsync(SqlAuthenticationParameters parameters)
        {
            string clientId = "my-client-id";
            string clientName = "My Application Name";
            string s_defaultScopeSuffix = "/.default";

            string[] scopes = new string[] { parameters.Resource.EndsWith(s_defaultScopeSuffix) ? parameters.Resource : parameters.Resource + s_defaultScopeSuffix };

            IPublicClientApplication app = PublicClientApplicationBuilder.Create(clientId)
                .WithAuthority(parameters.Authority)
                .WithClientName(clientName)
                .WithRedirectUri("https://login.microsoftonline.com/common/oauth2/nativeclient")
                .Build();

            AuthenticationResult result = await app.AcquireTokenWithDeviceCode(scopes,
                    deviceCodeResult => CustomDeviceFlowCallback(deviceCodeResult)).ExecuteAsync();
            return new SqlAuthenticationToken(result.AccessToken, result.ExpiresOn);
        }

        public override bool IsSupported(SqlAuthenticationMethod authenticationMethod) => authenticationMethod.Equals(SqlAuthenticationMethod.ActiveDirectoryDeviceCodeFlow);

        private Task CustomDeviceFlowCallback(DeviceCodeResult result)
        {
            Console.WriteLine(result.Message);
            return Task.FromResult(0);
        }
    }

    public class Program
    {
        public static void Main()
        {
            // Register our custom authentication provider class to override Active Directory Device Code Flow
            SqlAuthenticationProvider.SetProvider(SqlAuthenticationMethod.ActiveDirectoryDeviceCodeFlow, new CustomDeviceCodeFlowAzureAuthenticationProvider());
            using (SqlConnection sqlConnection = new SqlConnection("Server=<myserver>.database.windows.net;Authentication=Active Directory Device Code Flow;Database=<db>;"))
            {
                sqlConnection.Open();
                Console.WriteLine("Connected successfully!");
            }
        }
    }
}

除了改進 Active Directory Interactive 驗證體驗之外,Microsoft.Data.SqlClient 2.1.0 與更新版本提供下列 API,讓用戶端應用程式自訂互動式驗證與裝置程式碼流程驗證。

public class ActiveDirectoryAuthenticationProvider
{
    // For .NET Framework targeted applications only
    // Sets a reference to the current System.Windows.Forms.IWin32Window that triggers the browser to be shown. 
    // Used to center the browser pop-up onto this window.
    public void SetIWin32WindowFunc(Func<IWin32Window> iWin32WindowFunc);

    // For .NET Standard targeted applications only
    // Sets a reference to the ViewController (if using Xamarin.iOS), Activity (if using Xamarin.Android) IWin32Window, or IntPtr (if using .NET Framework). 
    // Used for invoking the browser for Active Directory Interactive authentication.
    public void SetParentActivityOrWindowFunc(Func<object> parentActivityOrWindowFunc);

    // For .NET Framework, .NET Core, and .NET Standard targeted applications
    // Sets a callback method that's invoked with a custom web UI instance that will let the user sign in with Azure AD, present consent if needed, and get back the authorization code. 
    // Applicable when working with Active Directory Interactive authentication.
    public void SetAcquireAuthorizationCodeAsyncCallback(Func<Uri, Uri, CancellationToken, Task<Uri>> acquireAuthorizationCodeAsyncCallback);

    // For .NET Framework, .NET Core, and .NET Standard targeted applications
    // Clears cached user tokens from the token provider.
    public static void ClearUserTokenCache();
}

另請參閱