ActiveDirectoryAuthenticationProvider.SetDeviceCodeFlowCallback Method

Definition

Sets the callback method, overriding the default implementation that processes the result for 'Active Directory Device Code Flow' authentication.

C#
public void SetDeviceCodeFlowCallback (Func<Microsoft.Identity.Client.DeviceCodeResult,System.Threading.Tasks.Task> deviceCodeFlowCallbackMethod);

Parameters

deviceCodeFlowCallbackMethod
Func<DeviceCodeResult,Task>

The callback method to be used with 'Active Directory Device Code Flow' authentication.

Examples

The following example demonstrates providing a custom device flow callback to SqlClient for the Device Code Flow authentication method:

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

Applies to

Product Versions
SqlClient .NET Core 2.1, 3.0, 3.1, 4.0, 4.1, 5.0, 5.1, 5.2
SqlClient .NET Framework 2.1, 3.0, 3.1, 4.0, 4.1, 5.0, 5.1, 5.2
SqlClient .NET Standard 2.1, 3.0, 3.1, 4.0, 4.1, 5.0, 5.1, 5.2