Aracılığıyla paylaş


ActiveDirectoryAuthenticationProvider.SetDeviceCodeFlowCallback Yöntem

Tanım

'Active Directory Cihaz Kodu Akışı' kimlik doğrulaması sonucunu işleyen varsayılan uygulamayı geçersiz kılarak geri çağırma yöntemini ayarlar.

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))

Parametreler

deviceCodeFlowCallbackMethod
Func<DeviceCodeResult,Task>

'Active Directory Cihaz Kodu Akışı' kimlik doğrulaması ile kullanılacak geri çağırma yöntemi.

Örnekler

Aşağıdaki örnek, Cihaz Kodu Akışı kimlik doğrulama yöntemi için SqlClient'a özel bir cihaz akışı geri çağırması sağlamayı gösterir:

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);
        }
    }
}

Şunlara uygulanır