ActiveDirectoryAuthenticationProvider.SetDeviceCodeFlowCallback 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
設定回呼方法,覆寫處理 'Active Directory 裝置程式碼流程' 驗證結果的預設實作。
public:
void SetDeviceCodeFlowCallback(Func<Microsoft::Identity::Client::DeviceCodeResult ^, System::Threading::Tasks::Task ^> ^ deviceCodeFlowCallbackMethod);
public void SetDeviceCodeFlowCallback (Func<Microsoft.Identity.Client.DeviceCodeResult,System.Threading.Tasks.Task> deviceCodeFlowCallbackMethod);
member this.SetDeviceCodeFlowCallback : Func<Microsoft.Identity.Client.DeviceCodeResult, System.Threading.Tasks.Task> -> unit
Public Sub SetDeviceCodeFlowCallback (deviceCodeFlowCallbackMethod As Func(Of DeviceCodeResult, Task))
參數
- deviceCodeFlowCallbackMethod
- Func<DeviceCodeResult,Task>
要與「Active Directory 裝置程式碼流程」驗證搭配使用的回呼方法。
範例
下列範例示範如何為裝置程式碼流程驗證方法提供 SqlClient 的自訂裝置流程回呼:
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);
}
}
}