10.3.7 • Published 2 months ago

@firebase-web-authn/server v10.3.7

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
2 months ago

@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

Demo: https://firebase-web-authn.dev

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

10.3.7

2 months ago

10.3.4

2 months ago

10.3.5

2 months ago

10.3.6

2 months ago

10.3.3

5 months ago

10.3.2

5 months ago

10.1.4

8 months ago

9.6.4

10 months ago

10.1.5

8 months ago

9.6.3

10 months ago

10.1.6

8 months ago

9.6.2

10 months ago

9.5.3

10 months ago

9.6.1

10 months ago

9.6.0

10 months ago

10.0.0

9 months ago

10.2.0

8 months ago

10.1.1

9 months ago

10.3.0

8 months ago

10.2.1

8 months ago

10.1.2

9 months ago

9.6.6

9 months ago

10.3.1

7 months ago

10.2.2

8 months ago

10.1.3

8 months ago

9.6.5

10 months ago

9.5.2

11 months ago

9.5.1

11 months ago

9.5.0

11 months ago