Git Product home page Git Product logo

webauthn-json's Introduction

@github/webauthn-json

@github/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 = await 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. @github/webauthn-json focuses on one simple approach: converting the known structure using a simple (custom) schema format. @github/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 small numbe rof extensions. To save code size, this library only includes the following extensions in the main build:

  • appid
  • appidExclude

If you need to convert additional input or output extensions, use createExtended() and getExtended() from @github/webauthn-json/dist/extended.

Contributions

The scope of @github/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!

webauthn-json's People

Contributors

lgarron avatar koddsson avatar santiagorodriguez96 avatar abhineet97 avatar cybai avatar dependabot[bot] avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.