Show / Hide Table of Contents

UseTouchNotifier Method

UseTouchNotifier(Action)

Set an System.Action delegate to notify users to touch the YubiKey button.

C#
public CalculateChallengeResponse UseTouchNotifier(Action notifier)

Parameters

Type Name Description
Action notifier

System.Action delegate.

Returns

CalculateChallengeResponse

The CalculateChallengeResponse instance

Examples

Here is a very simple example of performing a challenge-response operation on a YubiKey.

using (var otpSess = new OtpSession(_yubiKey))
{
    string otp = otp.CalculateChallengeResponse(_slot)
        .UseTouchNotifier(() => Console.WriteLine("Press the YubiKey button."))
        .UseTotp()
        .GetCode();
}

As mentioned in the remarks section, showing a prompt in a GUI application requires a little bit more work. Here is an example of calling a notifier method.

using (var otpSess = new OtpSession(_yubiKey))
{
    string otp = otpSess.CalculateChallengeResponse(_slot)
        .UseTouchNotifier(() => _appWindow.AlertUser())
        .UseTotp()
        .GetCode();
    _appWindow.SetOtpCode(otp);
}

Here is how the notifier would handle making sure the notification is handled on the correct thread.

public void AlertUser()
{
    if (!Dispatcher.CheckAccess())
    {
        Dispatcher.Invoke(() => AlertUser());
    }
    MessageBox.Show(this, "Press the YubiKey button.");
}

Remarks

This delegate will be launched as a System.Threading.Tasks.Task. The SDK will not wait or otherwise track the completion of the delegate. It is meant as a simple notifier.

It is important to take into consideration that it will execute on an unknown thread, so if you are using it to do a notification on a graphical user interface, then you should be sure that you marshall the call to the appropriate thread.

In this article
Back to top Generated by DocFX