@firebase-web-authn/api v10.4.2
@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 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, 1. Set up these services in your project. This must be done both in the Firebase Console and initialized in the application:
- App Check with reCAPTCHA Enterprise or v3
- Authentication with the anonymous provider
- Firestore
- Functions
Run:
% npm install @firebase-web-authn/api --save-devExport the API from your Firebase Functions package's
mainfile by callinggetFirebaseWebAuthnApiwith a config object.import { initializeApp } from "firebase-admin/app"; import { HttpsFunction } from "firebase-functions"; import { getFirebaseWebAuthnApi } from "@firebase-web-authn/api"; import { FunctionRequest, FunctionResponse } from "firebase-web-authn/types";
getApps().length === 0 && initializeApp();
export const firebaseWebAuthnAPI: CallableFunction<FunctionRequest, FunctionResponse> = getFirebaseWebAuthnApi({...});
// Other api...
```ts
interface FirebaseWebAuthnConfig {
authenticatorAttachment?: AuthenticatorAttachment, // Optional authenticator attachment. "cross-platform" allows security keys. "platform" allows passkey managers. Default behavior allows either attachment.
authenticatorAttachment2FA?: AuthenticatorAttachment, // Optional authenticator attachment for second (2FA) factor passkeys. Default behavior follows the main authenticator attachment configuration.
relyingPartyName: string, // Your app's display name in the passkey popup on some browsers.
userVerificationRequirement?: UserVerificationRequirement, // Your app's user verification requirement. "preferred" is default.
}Deploy your Firebase Functions:
% firebase deploy --only functions
Additional setup
Create a Firestore Database to store public key credentials with the ID
ext-firebase-web-authnand location matching the function deployment. It is recommended to choose eithernam5in North America oreur3in Europe and to enable delete protection:% firebase firestore:databases:create ext-firebase-web-authn --location ${MULTI_REGION_NAME} --delete-protection ENABLEDThe browser must reach FirebaseWebAuthn from the same domain as your website. Modify your
firebase.jsonto include a rewrite on each app where you'd like to use passkeys:{ "hosting": [ { "target": "...", "rewrites": [ { "source": "/firebase-web-authn-api", "function": "firebaseWebAuthnAPI" } ] } ] }Grant the
Cloud Datastore UserandService Account Token Creatorroles to theApp Engine default service accountprincipal in Service accounts underApp Engine default service account> Permissions.- Grant the
Cloud Functions Invokerrole to theallUsersprincipal in Cloud Functions underfirebaseWebAuthnAPI> Permissions.
More packages
1 year ago
1 year ago
1 year ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago