close
The Wayback Machine - https://web.archive.org/web/20200203184819/https://github.com/github/webauthn-json/
Skip to content
πŸ” A WebAuthn API wrapper that translates to/from pure JSON using base64url.
TypeScript JavaScript Makefile
Branch: master
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
Image .github/workflows Add workflow file for CI. Aug 8, 2019
Image extended Move most extensions into a separate build (saves 20% of bytes). Nov 13, 2019
Image src Move most extensions into a separate build (saves 20% of bytes). Nov 13, 2019
Image test Update dependencies. Nov 14, 2019
Image .gitignore Initial implementation. Aug 2, 2019
Image .npmignore Initial implementation. Aug 2, 2019
Image .travis.yml Initial implementation. Aug 2, 2019
Image CODE_OF_CONDUCT.md Initial implementation. Aug 2, 2019
Image LICENSE.md Initial implementation. Aug 2, 2019
Image Makefile Update `Makefile`. Aug 18, 2019
Image README.md Fix typo in `README.md`. Nov 15, 2019
Image jest.config.js
Image package-lock.json Update deps using `npm audit fix`. Dec 18, 2019
Image package.json Update deps using `npm audit fix`. Dec 18, 2019
Image rollup.config.js Move most extensions into a separate build (saves 20% of bytes). Nov 13, 2019
Image tsconfig.json Change exports. (main: UMD/ES2017, module: ESM/ES2017) Aug 2, 2019
Image tslint.json Initial implementation. Aug 2, 2019

README.md

@github/webauthn-json

webauthn-json is a client-side Javascript library that serves as convenience wrapper for the the WebAuthn API by encoding binary data using base64url (also known as "websafe" or "urlsafe" base64).

The WebAuthn API itself takes input and output values that look almost like JSON, except that binary data is represented as ArrayBuffers. Using webauthn-json allows the data to be sent from/to the server as normal JSON without client-side processing.

Usage

  1. Replace calls to navigator.credentials.create() with create(), and navigator.credentials.get() with get().
  2. Encode/decode binary values on the server as base64url.

Example

Install using:

npm install --save @github/webauthn-json

Then:

import {create} from "@github/webauthn-json"

async auth() {
  const request = await fetch("...");
  const response = create(request.json());
  await fetch("...", {
    method: "POST",
    body: JSON.stringify(response)
  });
}

See here for fully working client-side demo code.

API

function create(requestJSON: JSON): Promise<JSON>;
function get(requestJSON: JSON): Promise<JSON>;
function supported(): boolean;

Schema

There are are several ways to encode JSON with binary fields. webauthn-json focuses on one simple approach: converting the known structure using a simple (custom) schema format. webauthn-json uses a few tricks for a compact schema encoding: the production build is about β‰ˆ2KB uncompressed (<1KB gzipped).

Right now, we only convert fields explicitly known to be used by the WebAuthn API. This means that you'll have to update to a newer version of this library if you want to use new fields in the future.

To print the current schema, run:

npx @github/webauthn-json schema

Extensions

Modern browsers generally only support a single extension: the appid string. If you need to convert additional input or output extensions, use createExtended() and getExtended() from @github/webauthn-json/extended.

Contributions

The scope of webauthn-json is fairly small β€” it's essentially feature-complete. However, we're happy to accept issues or pull requests that address the core goal of the project!

You can’t perform that action at this time.