Socket
Socket
Sign inDemoInstall

@github/webauthn-json

Package Overview
Dependencies
0
Maintainers
16
Versions
52
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @github/webauthn-json

A wrapper for the webauthn API that adapts input/output values to plain JSON with base64url.


Version published
Weekly downloads
83K
decreased by-4.65%
Maintainers
16
Created
Weekly downloads
 

Readme

Source

@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"

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

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 — and most sites only need to use — a small number of extensions. To save code size, @github/webauthn-json only includes the following extensions by default:

If you need to convert additional input or output extensions, use createExtended() and getExtended() from @github/webauthn-json/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!

Keywords

FAQs

Last updated on 13 Oct 2020

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc