@firebase-web-authn/server
TypeScript icon, indicating that this package has built-in type declarations

10.3.7 • Public • Published

@firebase-web-authn/server

A Firebase Extension for authentication with WebAuthn passkeys.

This package contains six tree-shakeable async methods for using FirebaseWebAuthn in a secure context.

GitHub workflow status FirebaseWebAuthn version Firebase Admin SDK version

Methods

         credentials: (uid: string, app?: App) => Promise<{ [key in WebAuthnUserCredentialFactor]: WebAuthnUserCredential | null }>;
  lastCredentialUsed: (uid: string, app?: App) => Promise<WebAuthnUserCredentialFactor | null>;
         lastPresent: (uid: string, app?: App) => Promise<Timestamp | null>;
        lastVerified: (uid: string, app?: App) => Promise<Timestamp | null>;
 lastWebAuthnProcess: (uid: string, app?: App) => Promise<WebAuthnProcess | null>;
webAuthnUserDocument: (uid: string, app?: App) => Promise<WebAuthnUserDocument | null>;

Designed to be used within Firebase Functions or another secure context with access to Firestore to check users' status with FirebaseWebAuthn:

import { getApps, initializeApp } from "firebase-admin/app";
import { lastVerified }           from "@firebase-web-authn/server";
getApps().length === 0 && initializeApp();

// If the user was verified within the past 30 seconds, proceed. Otherwise, ask for reverification:
(await lastVerified(user.uid))?.seconds > (Date.now() / 1000) - 30 ?
  proceed() :
  askForReverification();

If your check involves multiple pieces of data from WebAuthnUserDocument, use the webAuthnUserDocument method to reduce Firestore calls:

// If the user was verified with their first-factor credential within the past 30 seconds, proceed. Otherwise, ask for reverification:
(await webAuthnUserDocument(user.uid).then<boolean>(
  (webAuthnUserDocument: WebAuthnUserDocument): boolean => webAuthnUserDocument.lastVerified > (Date.now() / 1000) - 30 && webAuthnUserDocument.lastCredentialUsed === "first",
)) ?
  proceed() :
  askForReverification();

More packages

Readme

Keywords

none

Package Sidebar

Install

npm i @firebase-web-authn/server

Weekly Downloads

2

Version

10.3.7

License

Apache-2.0

Unpacked Size

14.7 kB

Total Files

23

Last publish

Collaborators

  • gavinsawyer