selfhost.directory

The index of self-hostable projects — ranked, categorized and served with live updates.
Own your data and stop giving it to big tech.

2fa logo

Self-host 2fa

v1.13.1

2FA code vault on Cloudflare Workers with WebDAV backups

ReleaseOpen SourceMIT
Updated9 hours ago
LanguageJavaScript
Setup difficultyEasy
MobilePWA
ThemeDark mode
Stars
458
Install with Cloudflare Workers
Main key list with TOTP codes on desktopSame dashboard in a tablet-sized layoutMobile layout of the code list

What is 2fa?

This project is a two-factor authentication key manager you publish as your own Cloudflare Worker, so the whole app runs serverlessly on the free Workers tier instead of a VPS. It generates TOTP and HOTP codes locally in the browser, and keys can be added by scanning a QR code with the camera, uploading, pasting or dragging a screenshot, or typing a Base32 secret with custom digits, period and algorithm. Bulk import works with exports from Google Authenticator migration QR codes, Aegis, 2FAS, Bitwarden, LastPass, andOTP and Ente Auth, and bulk export writes TXT, JSON, CSV, HTML or a scannable Google Authenticator migration QR code. Secrets are stored in a Workers KV namespace and, once the ENCRYPTION_KEY secret is set, encrypted with AES-GCM 256; automatic backups are kept (100 by default) and can be pushed to WebDAV, S3-compatible storage, OneDrive or Google Drive. A companion browser extension for Chrome, Edge and Firefox reads and autofills codes, and the web app installs as a PWA with offline add/edit/import that syncs later. Deployment is either the Cloudflare deploy button (upgrades run through the Sync Upstream workflow) or a wrangler command line path; there is no Docker image. Only a single management password protects the instance, and OTP can also be exposed through unauthenticated public /otp/ URLs, which is a deliberate but security-relevant design.

Should you self-host 2fa?

2fa scores 48/100 on selfhost.directory (how scoring works) and ranks #25 of 40 in Authentication. It has 458 GitHub stars.

It shipped 14 stable releases in the past year. The latest, v1.13.1, came out on 19 October 2026. New versions land roughly every 3 days.

Setup is easy: most people get it running in one sitting. It is MIT-licensed and written mostly in JavaScript.

Its closest alternative on selfhost.directory is keycloak (86/100, 37 571 stars). It scores higher overall, so compare the two before you pick. See 2fa vs keycloak side by side.

Features

  • Automatic backup and restore
  • Browser extension autofill
  • Bulk export
  • Bulk Import
  • Customisable session lifetime
  • Encrypted secret storageOptional: without the key data is stored in plain text in KV.
  • HOTP support
  • Multi-language UI
  • Public OTP API
  • QR code scanning and image recognition
  • Remote backup sync
  • Search and grouped key list
  • TOTP code generation
  • Utilities toolbox

2fa README

How to install 2fa

Install 2fa with Cloudflare Workers

Cloudflare account; KV namespace and Durable Object created automatically by Wrangler
Environment variables
ENCRYPTION_KEY, ONEDRIVE_CLIENT_ID, ONEDRIVE_CLIENT_SECRET, GOOGLE_DRIVE_CLIENT_ID, GOOGLE_DRIVE_CLIENT_SECRET, OAUTH_REDIRECT_BASE_URL
  1. 点击上方部署按钮,使用 GitHub 登录并授权
  2. 登录 Cloudflare 账户,点击 Deploy 等待部署完成
  3. 记下您的 Worker URL(如 https://2fa-xxxx.workers.dev)

Upgrades run in place through the Sync Upstream GitHub Actions workflow.

How to configure 2fa

  • crons0 16 * * *Scheduled backup trigger; runs daily and only creates a backup when data changed

    Scheduled backup trigger; runs daily and only creates a backup when data changed

  • ENCRYPTION_KEYAES-GCM 256-bit encryption key (recommended secret; encrypted data is unrecoverable if lost)

    AES-GCM 256-bit encryption key (recommended secret; encrypted data is unrecoverable if lost)

    values: base64 of 32 random bytes

  • ENVIRONMENTproductionDeployment environment name used for cache behaviour

    Deployment environment name used for cache behaviour

    values: production / development

  • GOOGLE_DRIVE_CLIENT_IDGoogle Drive OAuth 客户端 ID

    Google Drive OAuth 客户端 ID

  • GOOGLE_DRIVE_CLIENT_SECRETGoogle Drive OAuth 客户端密钥

    Google Drive OAuth 客户端密钥

  • OAUTH_REDIRECT_BASE_URLOAuth 回调基准地址;使用自定义域名时推荐显式配置

    OAuth 回调基准地址;使用自定义域名时推荐显式配置

  • ONEDRIVE_CLIENT_IDOneDrive OAuth 客户端 ID

    OneDrive OAuth 客户端 ID

  • ONEDRIVE_CLIENT_SECRETOneDrive OAuth 客户端密钥

    OneDrive OAuth 客户端密钥

  • SECRETS_KVWorkers KV namespace binding storing 2FA keys, backups and the password hash (required)

    Workers KV namespace binding storing 2FA keys, backups and the password hash (required)

  • SECRETS_STOREDurable Object binding that serialises key read/write requests to avoid lost updates (recommended)

    Durable Object binding that serialises key read/write requests to avoid lost updates (recommended)

  • SW_VERSIONv1Service Worker version, injected by the deploy script

    Service Worker version, injected by the deploy script

2fa releases & version history

More in Backup

Rate this project

Click to rate — no account needed.

0 comments

Posting as guest
Loading comments…