SimpleWebAuthn

repository·master·Indexed 25 days ago

https://github.com/masterkale/simplewebauthn

A suite of libraries designed to reduce the complexity of implementing WebAuthn and Passkeys in web applications. It includes @simplewebauthn/server for server-side verification and @simplewebauthn/browser for client-side interaction. Compatible with Node.js (LTS 20.x+), Deno (v1.43+), Cloudflare Workers, and Bun. The server package supports various W3C attestation formats including Android Key, Apple, FIDO U2F, and TPM.

Tokens
10.1K
Snippets
35
Records
58
Agent score
81%

What's inside SimpleWebAuthn

  1. Overview of SimpleWebAuthn packages

    master

    SimpleWebAuthn provides two complementary libraries designed to simplify the integration of WebAuthn into web applications:

    • @simplewebauthn/server: Handles the server-side logic for WebAuthn authentication flows.
    • @simplewebauthn/browser: Provides client-side utilities to interact with the WebAuthn API in the browser.
  2. Install SimpleWebAuthn

    master

    SimpleWebAuthn can be installed via NPM or JSR. It is compatible with the following runtimes:

    • Node.js: LTS 20.x and higher
    • Deno: v1.43 and higher
    • Other compatible runtimes: Cloudflare Workers, Bun, etc.

    For specific installation commands for each package, refer to their individual READMEs.

  3. How to include @simplewebauthn/types in other packages

    master

    The types defined in @simplewebauthn/types are not consumed directly as a dependency in production. Instead, they are codegen'd into @simplewebauthn/browser and @simplewebauthn/server to ensure the typings are bundled within those specific packages.

    If you are contributing to the repository and make changes to the typings in this package, you must run the codegen task to propagate those changes to the browser and server packages, and then commit the resulting changes.

    deno task codegen
  4. Explore the SimpleWebAuthn Example Project

    master

    The example package serves as a fully-functional reference implementation of both @simplewebauthn/server and @simplewebauthn/browser. It demonstrates how to integrate these two packages to create a complete WebAuthn flow. For a detailed, in-depth guide on how the example project is structured and how the components interact, refer to the official documentation.

    https://simplewebauthn.dev/docs/advanced/example-project
  5. Install SimpleWebAuthn via JSR in Deno

    master

    Support for importing SimpleWebAuthn packages via deno.land/x URLs is deprecated. For Deno v1.43 and higher, use Deno's native support for JSR imports. You can install the server package using the deno add command, which allows you to use standard npm-style import specifiers in your code.

    # Deno v1.43 and higher
    deno add jsr:@simplewebauthn/server
  6. Install @simplewebauthn/browser via UMD

    master

    You can include the library via unpkg in your HTML <head>. The library's methods will be available on the global SimpleWebAuthnBrowser object.

    ES2021 (Modern Browsers)

    Use this version if you only need to support modern browsers.

    ES5 (Legacy Browser Support)

    Use this version if you need to support WebAuthn feature detection in deprecated browsers like IE11 and Edge Legacy. This version includes polyfills that enable the use of browserSupportsWebAuthn() in older browsers, though it adds bundle size overhead.

  7. Migrate from deno.land/x to JSR imports

    master

    If you are currently using deno.land/x URLs to import SimpleWebAuthn, you should migrate to JSR imports.

    Old way (Deprecated):

    import { generateAuthenticationOptions } from 'https://deno.land/x/simplewebauthn/deno/server.ts';

    New way (JSR):

    import { generateAuthenticationOptions } from 'jsr:@simplewebauthn/server';
  8. Use JSON-compatible types for WebAuthn transmission

    master

    When sending WebAuthn options from a server to a browser, or receiving responses from a browser to a server, you cannot use the standard DOM types because they contain ArrayBuffer objects which are not JSON-serializable.

    Use the *JSON interfaces provided by this package to define the shape of the data being transmitted over the wire. These interfaces use Base64URLString for all binary data fields.

    Key JSON Interfaces:

    • PublicKeyCredentialCreationOptionsJSON: Use this to send registration options to the browser.
    • PublicKeyCredentialRequestOptionsJSON: Use this to send authentication options to the browser.
    • RegistrationResponseJSON: Use this to receive registration results from the browser.
    • AuthenticationResponseJSON: Use this to receive authentication results from the browser.