Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

We use a client-side JavaScript library called "webauth-json" that serves as a convenience wrapper for the the WebAuthn API by encoding binary data using base64url. 

https://github.com/github/webauthn-json

This article demonstrates how to use the webauth-json JavaScript library and DualShield API to register a FIDO2 key in a web browser. 

Table of Contents

Import WebAuth-Jason

To use the webauth-jason, you need to install it first

Code Block
npm install --save @github/webauthn-json

Install WebAuth-Jason

Then, you need to import it

Code Block
import { create, CredentialCreationOptionsJSON, CredentialRequestOptionsJSON, get, PublicKeyCredentialWithAssertionJSON } from '@github/webauthn-json';

Create Objects

We need to create 3 objects, fidoObj, CredentialCreationOptionsJSON, and CredentialRequestOptionsJSON

Code Block
languagejs
fidoObj = {
    manufacturerCode: "DN",
    productCode: "FIDO2",
    method: "FIDO2"
  };

  credentialCreateOptions: CredentialCreationOptionsJSON = {
    publicKey: {
      rp: {
        name: ""
      },
      user: {
        name: "",
        displayName: "",
        id: ""
      },
      challenge: "",
      pubKeyCredParams: [],
      timeout: 0,
      excludeCredentials: [],
      authenticatorSelection: {userVerification: "discouraged"},
      attestation: "none",
    }
  };

  credentialRequestOptions: CredentialRequestOptionsJSON = {
    publicKey: {
      challenge: "",
      extensions:{
        appid:""
      },

    allowCredentials: [],
    userVerification: "discouraged"
    }
  };