OtpSession Class
Namespace: Yubico.YubiKey.Otp Assembly: Yubico.YubiKey.dllEntry point for all high-level OTP operations.
public sealed class OtpSession : Object, IOtpSession, IDisposable
Remarks
Most methods will return a reference to the operation class that performs
the operation being executed. Then, methods on that class that configure
the operation also return the same reference. This is known as a fluent
builder pattern. This allows operations to be built by stringing together
configuration methods. The operation is usually concluded with a call to a
method named Execute()
.
Methods in this class that instantiate classes that support the fluent builder pattern are any that return a class reference. Methods that return void do not require additional configuration to perform their operations. See the example section below for more details.
Examples
This is an example of using the fluent builder pattern to configure a YubiKey OTP slot to emit a static password.
ReadOnlyMemory<char> password = "Shhhh!Don'tTell!".ToCharArray();
using (OtpSession otp = new OtpSession(yubiKey))
{
otp.ConfigureStaticPassword(Slot.ShortPress)
.SetPassword(password)
.WithKeyboard(KeyboardLayout.en_US)
.AppendCarriageReturn()
.Execute();
};
The method, ConfigureStaticPassword(Slot), instantiates an
instance of the class ConfigureStaticPassword.
The next line configures the operation with the password to set. The next
line configures the keyboard layout. The next line configures the operation
to tell the YubiKey to send a carriage-return after sending the password,
and finally, Execute()
tells the operation class to perform the
configuration on the YubiKey.
Constructors
Name | Description |
---|---|
OtpSession(IYubiKeyDevice) | Constructs a OtpSession instance for high-level OTP operations. |
Properties
Name | Description |
---|---|
IsLongPressConfigured | Indicates that the long-press configuration (slot 2) is present and valid. |
IsShortPressConfigured | Indicates that the short-press configuration (slot 1) is present and valid. |
LongPressRequiresTouch | Indicates that the long-press configuration (slot 2) requires touch for operation. |
ShortPressRequiresTouch | Indicates that the short-press configuration (slot 1) requires touch for operation. |
Methods
Name | Description |
---|---|
CalculateChallengeResponse(Slot) | Submits a challenge to the YubiKey OTP application to be calculated. |
ConfigureChallengeResponse(Slot) | Configures one of the OTP application slots to respond to challenges. |
ConfigureHotp(Slot) | Configures a YubiKey OTP slot to emit sequence-based OTP codes. |
ConfigureNdef(Slot) | Configures a YubiKey's NDEF slot for text or URI. |
ConfigureStaticPassword(Slot) | Sets a static password for an OTP application slot on a YubiKey. |
ConfigureYubicoOtp(Slot) | Configures one of the OTP application slots to act as a Yubico OTP device. |
DeleteSlot(Slot) | Removes an OTP slot configuration and sets it to empty. |
DeleteSlotConfiguration(Slot) | Removes a slot configuration in the YubiKey's OTP application. |
Dispose() | |
ReadNdefTag() | Reads the OTP programmed in the short-press slot using the NFC Data-Exchange Format (NDEF) tag from NFC enabled YubiKeys. (Requires the YubiKey be connected via NFC). |
SwapSlots() | Swaps the configurations in the short and long press slots. |
UpdateSlot(Slot) | Updates the settings of an OTP application slot on a YubiKey without removing the existing configuration. |