How to use u2f-api - 10 common examples

To help you get started, we’ve selected a few u2f-api examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github authelia / authelia / web / src / views / LoginPortal / SecondFactor / SecurityKeyMethod.tsx View on Github external
try {
            triggerTimer();
            setState(State.WaitTouch);
            const signRequest = await initiateU2FSignin();
            const signRequests: u2fApi.SignRequest[] = [];
            for (var i in signRequest.registeredKeys) {
                const r = signRequest.registeredKeys[i];
                signRequests.push({
                    appId: signRequest.appId,
                    challenge: signRequest.challenge,
                    keyHandle: r.keyHandle,
                    version: r.version,
                })
            }
            const signResponse = await u2fApi.sign(signRequests, signInTimeout);
            // If the request was initiated and the user changed 2FA method in the meantime,
            // the process is interrupted to avoid updating state of unmounted component.
            if (!mounted.current) return;

            setState(State.SigninInProgress);
            const res = await completeU2FSignin(signResponse, redirectionURL);
            onSignInSuccessCallback(res ? res.redirect : undefined);
        } catch (err) {
            // If the request was initiated and the user changed 2FA method in the meantime,
            // the process is interrupted to avoid updating state of unmounted component.
            if (!mounted.current) return;
            console.error(err);
            onSignInErrorCallback(new Error("Failed to initiate security key sign in process"));
            setState(State.Failure);
        }
    }, [onSignInSuccessCallback, onSignInErrorCallback, redirectionURL, mounted, triggerTimer, props.authenticationLevel, props.registered]);
github MyEtherWallet / MyEtherWallet / src / wallets / hardware / bitbox / digitalBitboxUsb.js View on Github external
]);
    const key = {
      appId: location.origin,
      challenge: DigitalBitboxUsb.webSafe64(challenge.toString('base64')),
      version: 'U2F_V2',
      keyHandle: DigitalBitboxUsb.webSafe64(kh.toString('base64'))
    };
    // Set timeout to 35 seconds for Windows 10 to wait for user confirmation
    // Keep 3 seconds for other plaforms so that polling is fast enough
    let timeout;
    navigator.platform.indexOf('Win') >= 0 &&
    (navigator.userAgent.indexOf('Windows NT 10.0') != -1 ||
      navigator.userAgent.indexOf('Windows 10.0') != -1)
      ? (timeout = 35)
      : (timeout = 3);
    u2f
      .sign(key, timeout)
      .then(localCallback)
      .catch(err => {
        callback(undefined, err);
      });
  }
};
github getsentry / sentry / src / sentry / static / sentry / app / components / u2f / u2finterface.jsx View on Github external
invokeU2fFlow = () => {
    let promise;
    if (this.props.flowMode === 'sign') {
      promise = u2f.sign(this.props.challengeData.authenticateRequests);
    } else if (this.props.flowMode === 'enroll') {
      const {registerRequests, authenticateRequests} = this.props.challengeData;
      promise = u2f.register(registerRequests, authenticateRequests);
    } else {
      throw new Error(`Unsupported flow mode '${this.props.flowMode}'`);
    }
    promise
      .then(data => {
        this.setState(
          {
            hasBeenTapped: true,
          },
          () => {
            const u2fResponse = JSON.stringify(data);
            const challenge = JSON.stringify(this.props.challengeData);

            // eslint-disable-next-line react/no-direct-mutation-state
            this.state.responseElement.value = u2fResponse;
github authelia / authelia / client / src / containers / views / SecurityKeyRegistrationView / SecurityKeyRegistrationView.ts View on Github external
onInit: async (token: string) => {
      try {
        dispatch(registerSecurityKey());
        const registerRequest = await AutheliaService.completeSecurityKeyRegistrationIdentityValidation(token);
        const registerRequests: U2fApi.RegisterRequest[] = [];
        for(var i in registerRequest.registerRequests) {
          const r = registerRequest.registerRequests[i];
          registerRequests.push({
            appId: registerRequest.appId,
            challenge: r.challenge,
            version: r.version,
          })
        }
        const registerResponse = await U2fApi.register(registerRequests, [], 60);
        await AutheliaService.completeSecurityKeyRegistration(registerResponse);
        dispatch(registerSecurityKeySuccess());
        setTimeout(() => {
          ownProps.history.push('/');
        }, 2000);
      } catch(err) {
        console.error(err);
        dispatch(registerSecurityKeyFailure(err.message));
      }
    },
    onBackClicked: () => {
github authelia / authelia / client-react / src / containers / views / SecondFactorView / SecondFactorView.ts View on Github external
async function triggerSecurityKeySigning(dispatch: Dispatch, props: Props) {
  let err, result;
  dispatch(securityKeySign());
  [err, result] = await to(requestSigning());
  if (err) {
    dispatch(securityKeySignFailure(err.message));
    return;
  }

  [err, result] = await to(u2fApi.sign(result, 60));
  if (err) {
    dispatch(securityKeySignFailure(err.message));
    return;
  }

  [err, result] = await to(completeSecurityKeySigning(result as SignResponse));
  if (err) {
    dispatch(securityKeySignFailure(err.message));
    return;
  }
  dispatch(securityKeySignSuccess());
  await redirectUponAuthentication(props);
}
github authelia / authelia / client / src / lib / secondfactor / U2FValidator.ts View on Github external
.then(function (signRequest: U2f.Request) {
      notifier.info(UserMessages.PLEASE_TOUCH_TOKEN);
      return U2fApi.sign(signRequest, 60);
    })
    .then(function (signResponse: U2fApi.SignResponse) {
github LedgerHQ / ledgerjs / packages / hw-transport-u2f / src / TransportU2F.js View on Github external
): Promise {
  const keyHandle = wrapApdu(apdu, scrambleKey);
  const challenge = Buffer.from(
    "0000000000000000000000000000000000000000000000000000000000000000",
    "hex"
  );
  const signRequest = {
    version: "U2F_V2",
    keyHandle: webSafe64(keyHandle.toString("base64")),
    challenge: webSafe64(challenge.toString("base64")),
    appId: location.origin
  };
  if (debug) {
    debug("=> " + apdu.toString("hex"));
  }
  return sign(signRequest, timeoutMillis / 1000).then(response => {
    const { signatureData } = response;
    if (typeof signatureData === "string") {
      const data = Buffer.from(normal64(signatureData), "base64");
      let result;
      if (!unwrap) {
        result = data;
      } else {
        result = data.slice(5);
      }
      if (debug) {
        debug("<= " + result.toString("hex"));
      }
      return result;
    } else {
      throw response;
    }
github authelia / authelia / client / src / containers / components / SecondFactorU2F / SecondFactorU2F.ts View on Github external
async function triggerSecurityKeySigning(dispatch: Dispatch, redirectionUrl: string | null) {
  dispatch(securityKeySign());
  const signRequest = await AutheliaService.requestSigning();
  const signRequests: u2fApi.SignRequest[] = [];
  for (var i in signRequest.registeredKeys) {
    const r = signRequest.registeredKeys[i];
    signRequests.push({
      appId: signRequest.appId,
      challenge: signRequest.challenge,
      keyHandle: r.keyHandle,
      version: r.version,
    })
  }
  const signResponse = await u2fApi.sign(signRequests, 60);
  const response = await AutheliaService.completeSecurityKeySigning(signResponse, redirectionUrl);
  dispatch(securityKeySignSuccess());

  if (response) {
    window.location.href = response.redirect;
    return;
  }
  await handleSuccess(dispatch, 1000);
}
github getsentry / sentry / src / sentry / static / sentry / app / components / u2f / u2finterface.jsx View on Github external
invokeU2fFlow = () => {
    let promise;
    if (this.props.flowMode === 'sign') {
      promise = u2f.sign(this.props.challengeData.authenticateRequests);
    } else if (this.props.flowMode === 'enroll') {
      const {registerRequests, authenticateRequests} = this.props.challengeData;
      promise = u2f.register(registerRequests, authenticateRequests);
    } else {
      throw new Error(`Unsupported flow mode '${this.props.flowMode}'`);
    }
    promise
      .then(data => {
        this.setState(
          {
            hasBeenTapped: true,
          },
          () => {
            const u2fResponse = JSON.stringify(data);
            const challenge = JSON.stringify(this.props.challengeData);
github LedgerHQ / ledgerjs / packages / hw-transport-u2f / src / TransportU2F.js View on Github external
static listen = (observer: *) => {
    let unsubscribed = false;
    isSupported().then(supported => {
      if (unsubscribed) return;
      if (supported) {
        observer.next({ type: "add", descriptor: null });
        observer.complete();
      } else {
        observer.error(
          new TransportError(
            "U2F browser support is needed for Ledger. " +
              "Please use Chrome, Opera or Firefox with a U2F extension. " +
              "Also make sure you're on an HTTPS connection",
            "U2FNotSupported"
          )
        );
      }
    });
    return {

u2f-api

Promisified U2F API for browsers

MIT
Latest version published 3 years ago

Package Health Score

50 / 100
Full package analysis