@firebase-web-authn/api
A Firebase Extension for authentication with WebAuthn passkeys.
This package contains a Firebase Function that registers and authenticates WebAuthn passkeys, manages public key credentials in Firestore, and cleans up data if the user cancels the process or unlinks a passkey.
![Firebase SDK for Cloud Functions version](https://img.shields.io/npm/dependency-version/@firebase-web-authn/api/dev/firebase-functions?label=Firebase%20SDK%20for%20Cloud%20Functions&logo=firebase)
Firebase Extension deployment
See @firebase-web-authn/extension for simplified installation using firebase ext:install
.
Custom deployment
If you would rather deploy the API from your existing Firebase Functions package,
- Run:
% npm install @firebase-web-authn/api --save-dev
- Export the API from your Firebase Functions package's
main
file by calling getFirebaseWebAuthnApi
with a config object.
import { initializeApp } from "firebase-admin/app";
import { HttpsFunction } from "firebase-functions";
import { getFirebaseWebAuthnApi } from "@firebase-web-authn/api";
getApps().length === 0 && initializeApp();
export const firebaseWebAuthnAPI: HttpsFunction = getFirebaseWebAuthnApi({...});
interface FirebaseWebAuthnConfig {
authenticatorAttachment: AuthenticatorAttachment,
relyingPartyName: string,
userVerificationRequirement?: UserVerificationRequirement,
}
- Deploy your Firebase Functions:
% firebase deploy --only functions
Additional setup
- The browser must reach FirebaseWebAuthn from the same domain as your website. Modify your
firebase.json
to include a rewrite on each app where you'd like to use passkeys:
{
"hosting": [
{
"target": "...",
"rewrites": [
{
"source": "/firebase-web-authn-api",
"function": "firebaseWebAuthnAPI"
}
]
}
]
}
- Set up these services in your Firebase project:
- App Check
- Authentication with the anonymous provider
- Firestore Database
- Functions
- Grant the
Cloud Datastore User
and Service Account Token Creator
roles to the App Engine default service account
principal in Service accounts under App Engine default service account
> Permissions. - Grant the
Cloud Functions Invoker
role to the allUsers
principal in Cloud Functions under firebaseWebAuthnAPI
> Permissions.
More packages