npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@twilio/twilio-verify-passkeys-web

v0.0.2

Published

Twilio Passkeys Web SDK enables developers to easily add Passkeys into their existing authentication flows within their own web applications. The Verify Passkeys SDK supports passkeys creation and authentication using the FIDO/WebAuthn industry standard.

Downloads

5

Readme

Twilio Verify Passkeys Web

Table of content

About

Twilio Passkeys Web SDK enables developers to easily add Passkeys into their existing authentication flows within their own web applications. The Verify Passkeys SDK supports passkeys creation and authentication using the FIDO/WebAuthn industry standard.

Documentation

Verify Passkeys Overview

Requirements

  • Node.js v20.x or higher

Installation

  • Add the library to your project

Using NPM

npm install @twilio/twilio-verify-passkeys-web

Directly from Github

npm install https://github.com/twilio/twilio-verify-passkeys-web.git

Using it from CDN

<script src="https://unpkg.com/@twilio/[email protected]/dist/twilio-verify-passkeys.iife.js"></script>

Quickstart

Create registration

Use the TwilioPasskeys instance to create a registration by calling the create(String) function.

The create method receive a param that represent a challenge payload, check how to create challenge payload.

You can also call create(CreatePasskeysRequest), where the CreatePasskeysRequest is wrapper object of a creation challenge payload schema.

const createPasskeysResult = twilioPasskeys.create(challengePayload)

if(createPasskeysResult.Error !== null) {
    // verify the createPasskeyResult.createPasskeyResponse against your backend and finish sign up
} else {
    // handle error
}

Authenticate a user

Use the TwilioPasskeys instance to authenticate a user by calling the authenticate(String) function.

The authenticate method receive a param that represent an authentication request, it follows the schema of an authentication challenge payload.

You can also call authenticate(AuthenticatePasskeysRequest), where the AuthenticatePasskeysRequest is a wrapper object of an authentication challenge payload.

const authenticatePasskeyResult = twilioPasskeys.authenticate(authenticationRequest)

if(authenticatePasskeyResult.Error !== null) {
    // verify the authenticatePasskeyResult.authenticatePasskeyResponse against your backend
} else {
    // handle error
}

Create Challenge Payload

The challenge payload for creating a registration is a String obtained by requesting your backend a challenge for registering a user, it uses the JSON schema:

{"rp":{"id":"your_backend","name":"PasskeySample"},"user":{"id":"WUV...5Ng","name":"1234567890","displayName":"1234567890"},"challenge":"WUY...jZQ","pubKeyCredParams":[{"type":"public-key","alg":-7}],"timeout":600000,"excludeCredentials":[],"authenticatorSelection":{"authenticatorAttachment":"platform","requireResidentKey":false,"residentKey":"preferred","userVerification":"preferred"},"attestation":"none"}

Authenticate Challenge Payload

The challenge payload for authenticating a user is a JSON with the schema:

{"publicKey":{"challenge":"WUM...2Mw","timeout":300000,"rpId":"your_backend","allowCredentials":[],"userVerification":"preferred"}}

Building and Running Sample App

Requirements

  • ngrok

Steps

  1. Clone this repository.
  2. Install the dependencies using
npm install
  1. Make sure you have setup your backend
  2. Go to the config.js file inside the sample-app folder and replace the backend url with your backend url
  3. Run the following command to build and run a local server with the sample app
npm run demo
  1. The previous step will open a browser tap with the localhost server running at port 8080, run ngrok for that port:
ngrok http http://localhost:8080
  1. Open the sample app in your browser using the url that ngrok provides: https://example.ngrok.app/sample-app/

Backend side configurations for sample app

  1. Setup a backend throught the function template of passkeys-backend

  2. Make sure you already added support for digital asset links, this should be inside a file called assetlinks.json in your backend, check whether an entry with the following structure:

{
    "relation":[
        "delegate_permission/common.get_login_creds",
        "delegate_permission/common.handle_all_urls"
    ],
    "target":{
        "namespace": "web",
        "site": "https://example.ngrok.app"
    }
},
  1. Add the ngrok url to the enviroment variables in the field RP_DOMAIN if you are using just this sample app.
RP_DOMAIN=example.ngrok.app
  1. Add the ngrok url to the enviroment variable called ORIGINS, using a full url format.
ORIGINS=https://example.ngrok.app

Project Structure

  • src: Contains all the main code, including business logic, data models, and utility functions.
  • sample-app: This folder contains a simple demo application code that use html and vanilla javascript.

Code Structure

Main code

The src folder constains all the core code. This includes:

  • Data models (src/models)
  • Buisness logic (src/TwilioPasskeys.js)
  • Utility functions (src/utils)

Sample App

The sample-app folder contains a simple demo app code. This includes:

  • Vanilla javascript code that works as code snippets for integrating with the Twilio Verify Passkeys SDK

  • HTML code that works as UI implementation

Running Tests

Running all tests

npm run test

Running test coverage

npm run coverage