public static async Task AuthenticateAsync(IHidDevice hidDevice, DeviceRegistration deviceRegistration, string appId, string facet, bool checkOnly = false, CancellationToken?cancellationToken = null) { cancellationToken = cancellationToken ?? CancellationToken.None; if (hidDevice == null || !hidDevice.IsConnected) { throw new ArgumentException("Hid device not connected", nameof(hidDevice)); } using (var u2fHidDevice = await U2FHidDevice.OpenAsync(hidDevice)) { var startAuthentication = U2F.StartAuthentication(appId, deviceRegistration); Log.Debug("Touch token to authenticate"); var authenticateResponse = await WaitForTokenInputAsync(() => U2Fv2.AuthenticateAsync(u2fHidDevice, startAuthentication, facet, checkOnly), cancellationToken.Value).ConfigureAwait(false); U2F.FinishAuthentication(startAuthentication, authenticateResponse, deviceRegistration); Log.Debug("Authenticated"); } }
public static async Task <DeviceRegistration> RegisterAsync(IHidDevice hidDevice, string appId, string facet, CancellationToken?cancellationToken = null) { cancellationToken = cancellationToken ?? CancellationToken.None; if (hidDevice == null || !hidDevice.IsConnected) { throw new ArgumentException("Hid device not connected", nameof(hidDevice)); } using (var u2fHidDevice = await U2FHidDevice.OpenAsync(hidDevice)) { var startRegistration = U2F.StartRegistration(appId); Log.Debug("Touch token to register"); var registerResponse = await WaitForTokenInputAsync(() => U2Fv2.RegisterAsync(u2fHidDevice, startRegistration, facet), cancellationToken.Value); var deviceRegistration = U2F.FinishRegistration(startRegistration, registerResponse); Log.Debug("Registered"); return(deviceRegistration); } }