Send feedback on this topic.
Teradata.Client.Provider
DeviceAuthenticationMessage Event
Example 



Teradata.Client.Provider Namespace > TdConnection Class : DeviceAuthenticationMessage Event
The .NET Data Provider for Teradata will raise this event when client authentication is performed using OIDC Device Code Flow.
Syntax
'Declaration
 
Public Event DeviceAuthenticationMessage As DeviceAuthenticationMessageEventHandler
'Usage
 
Dim instance As TdConnection
Dim handler As DeviceAuthenticationMessageEventHandler
 
AddHandler instance.DeviceAuthenticationMessage, handler
public event DeviceAuthenticationMessageEventHandler DeviceAuthenticationMessage
public:
event DeviceAuthenticationMessageEventHandler^ DeviceAuthenticationMessage
Event Data

The event handler receives an argument of type DeviceAuthenticationMessageEventArgs containing data related to this event. The following DeviceAuthenticationMessageEventArgs properties provide information specific to this event.

PropertyDescription
The lifetime in seconds of the UserCode.  
The end-user verification code.  
The end-user verification URI on the authorization server.  
The end-user verification URI that includes the UserCode (or other information with the same function as the UserCode) on the authorization server.  
Remarks
When TdConnectionStringBuilder.AuthenticationMechanism is set to "CODE", an application may register with this event if it wishes to display the end-user verification code and URI of the authorization server to the user. The application should prompt the user to visit the URI and confirm the verification code.
Example
The following example creates an instance of the TdConnection class with a DeviceAuthenticationMessage event handler. It displays the Device Code message to the user while establishing a session.

public void TestDeviceCodeFlow(TdConnectionStringBuilder builder)
{
    builder.AuthenticationMechanism = "CODE";
    builder.ConnectionTimeout = 60;
            
    using (TdConnection cn = new TdConnection(builder.ConnectionString))
    {
        // Create the DeviceAuthenticationMessage event handler
        cn.DeviceAuthenticationMessage += new DeviceAuthenticationMessageEventHandler(
            (sender, e) =>
            {
                // Provide the verification URI to the user. This requires user interaction.
                Console.WriteLine($"To proceed with Teradata authentication, use your web " +
                    $"browser to visit the following URL: {e.VerificationUriComplete}");
            });
            
        // Open the connection. The DeviceAuthenticationMessage event handler will be called.
        // The Open method will return after the user has authenticated or when the connection times
        // out per ConnectionTimeout.
        cn.Open();
            
        // do work
            
        cn.Close();
    }
}
Requirements
ProductVersionsPlatforms
.NET6, 7Windows, Linux, MacOS
.NET Framework4.6.2, 4.7, 4.7.1, 4.7.2, 4.8Windows
.NET Standard2.0Windows, Linux, MacOS
See Also