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

@passageidentity/passage-flex-js

v0.1.4

Published

Passkey Flex SDK for JavaScript

Downloads

122

Readme

PassageFlex JS

Passkey Flex provides passkey authentication support to existing authentication systems. It handles the hard parts of incorporating the WebAuthn API and provides a simple, clean solution to take your authentication to the next level.

Use the passage-flex-js JS SDK to implement Passkey Flex in your web application to use passkeys to register, authenticate, or as added security on secure user actions.

For full documentation, including setting up a backend SDK, visit the Passkey Flex documentation here.

Getting started

Install this package using npm:

npm i --save @passageidentity/passage-flex-js

Import PassageFlex:

import { PassageFlex } from 'passage-flex-js';

Initialize a Passage Flex instance using your appId found in Passage Console:

const passageFlex = new PassageFlex(appID);

Core Functions

passkey.register(transactionId: string)

Returns

Promise<string>

Register the user using a transactionId retrieved from the Passage API using a Passage Flex backend SDK. Returns a nonce. You can use the nonce in a backend SDK to verify that Passage Flex has registered the user successfully.

Example

<input id="register-input" type="email" placeholder="[email protected]" />
<button id="register-button" type="button" onclick="onRegisterPasskeyClick()">Register</button>
async function onRegisterPasskeyClick() {
    const nonce = await passageFlex.passkey.register(transactionID);
}

passkey.authenticate(options?: {transactionId?: string, isConditionalMediation?: boolean})

Returns

Promise<string>

Authenticate the user. Returns a nonce. There are three ways to authenticate users with passkeys:

  1. With a unique identifier, eg. a username or email which requires an input and identifier

    Example

    <input id="authenticate-input" type="email" placeholder="[email protected]" />
    <button id="authenticate-button" type="button" onclick="onAuthenticatePasskeyClick()">
        Log in
    </button>
    async function onAuthenticatePasskeyClick() {
        const nonce = await passageFlex.passkey.authenticate({ transactionID });
    }
  1. Without a unique identifier, eg. a single "Log in" CTA which does not require an input or identifier

    Example

    <button id="authenticate-button" type="button" onclick="onAuthenticatePasskeyClick()">
        Log in
    </button>
    async function onAuthenticatePasskeyClick() {
        const nonce = await passageFlex.passkey.authenticate();
    }
  1. Using Passkey Autofill, eg. a dropdown with available passkeys is displayed to the user on clicking an identifier input

    Example

    <input autocomplete="username webauthn" id="authenticate-input" type="email" placeholder="[email protected]" />
    <button id="authenticate-button" type="button" onclick="onAuthenticatePasskeyClick()">Log in</button>
    // A request to authenticate with conditional mediation should be made on page load.
    async function onPageLoad() {
        const nonce = await passageFlex.passkey.authenticate({ isConditionalMediation: true });
    }

For more information on authenticating with Passkey Flex using passage-flex-js, see the Passkey Flex Authenticate documentation here.

Helper Functions

PassageFlexJS provides utility functions to check for Webauthn capabilities in the user's current browser. For example, these functions can be used to check for Webauthn capabilities before displaying the option to the user.

passkey.canAuthenticateWithPasskey()

Returns

Promise<boolean>

A promise that resolves true if the current browser supports passkey authentication, false otherwise.

Example

const isPasskeyAuthenticationAvailable = await passageFlex.passkey.canAuthenticateWithPasskey();

if (isPasskeyAuthenticationAvailable) {
    return <button onClick={onAuthenticateWithPasskeyClick}>Log in with passkey</button>;
}

passkey.canRegisterPasskey()

Returns

Promise<boolean>

A promise that resolves true if the current browser supports passkey creation, false otherwise.

const isPasskeyRegistrationAvailable = await passageFlex.passkey.canRegisterPasskey();

if (isPasskeyRegistrationAvailable) {
    return <button onClick={onRegisterWithPasskeyClick}>Log in with passkey</button>;
}

passkey.canUseConditionalMediation()

Returns

Promise<boolean>

A promise that resolves true if the current browser supports conditional mediation (passkey autofill), false otherwise.

Example

const isConditionalMediationAvailable = await passageFlex.passkey.canUseConditionalMediation();

if (isConditionalMediationAvailable) {
    return await passageFlex.passkey.authenticate({ isConditionalMediation: true });
}