MDN self-hosted library · e01.org

Web Authentication extensions

Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.

js
const publicKey = {
  challenge: new Uint8Array([117, 61, 252, 231, 191, 241 /* … */]),
  rp: { id: "acme.com", name: "ACME Corporation" },
  user: {
    id: new Uint8Array([79, 252, 83, 72, 214, 7, 89, 26]),
    name: "jamiedoe",
    displayName: "Jamie Doe",
  },
  pubKeyCredParams: [{ type: "public-key", alg: -7 }],
  authenticatorSelection: {
    residentKey: "preferred",
  },
  extensions: {
    credProps: true,
    minPinLength: true,
  },
};
js
navigator.credentials.create({ publicKey });
js
navigator.credentials
  .create({ publicKey })
  .then((publicKeyCred) => {
    const myClientExtResults = publicKeyCred.getClientExtensionResults();
    // myClientExtResults will contain the output of processing
    // the "credProps" extension

    const authData = publicKeyCred.response.getAuthenticatorData();
    // authData will contain authenticator data, which will include
    // authenticator extension processing results, i.e., minPinLength
  })
  .catch((err) => {
    console.error(err);
  });
js
({
  extensions: {
    appid: "https://accounts.example.com",
  },
});
js
({
  allowCredentials: [
    {
      id: arrayBuffer, // needs to contain decoded binary form of id
      transports: ["nfc", "usb"],
      type: "public-key",
    },
  ],
});
js
({
  extensions: {
    appidExclude: "https://accounts.example.com",
  },
});
js
({
  excludeCredentials: [
    {
      id: arrayBuffer, // needs to contain decoded binary form of id
      transports: ["nfc", "usb"],
      type: "public-key",
    },
  ],
});
js
({
  extensions: {
    credProps: true,
  },
});
js
({
  authenticatorSelection: {
    requireResidentKey: true,
  },
});
js
({
  credProps: {
    rk: true,
  },
});
js
({
  extensions: {
    credentialProtectionPolicy: "userVerificationOptional",
    enforceCredentialProtectionPolicy: true,
  },
});
js
({ credProtect: 0x01 });
js
({
  extensions: {
    largeBlob: {
      support: "required",
    },
  },
});
js
({
  extensions: {
    largeBlob: {
      read: true,
    },
  },
});
js
({
  extensions: {
    largeBlob: {
      write: arrayBuffer,
    },
  },
});
js
({
  largeBlob: {
    supported: true, // false if it cannot store blobs
  },
});
js
({
  largeBlob: {
    blob: arrayBuffer,
  },
});
js
({
  largeBlob: {
    written: true,
  },
});
js
({
  extensions: {
    minPinLength: true,
  },
});
js
({ minPinLength: uint });
js
({
  extensions: {
    prf: {
      eval: { first: new TextEncoder().encode("Salt for new symmetric key") },
    },
  },
});
js
({
  extensions: {
    prf: {
      eval: {
        first: currentSessionKey, // salt for current session
        second: nextSessionKey, // salt for next session
      },
    },
  },
});
js
({
  extensions: {
    prf: {
      evalByCredential: {
        "<credentialId>": { first: bufferOne, second: bufferTwo },
        // …
        "<credentialId2>": {
          first: anotherBufferOne,
          second: anotherBufferTwo,
        },
      },
    },
  },
});
js
({
  prf: {
    enabled: true, // PRF can be used when creating credentials.
    results: { first: outputBuffer1, second: outputBuffer2 },
  },
});
js
({
  prf: {
    enabled: false, // PRF cannot be used when creating credentials.
  },
});
js
({
  prf: {
    results: { first: outputBuffer1, second: outputBuffer2 },
  },
});
js
({
  prf: {},
});