ComfyUI-OTP-Auth
Adds simple One-Time Password (OTP) authentication using Google Authenticator to protect publicly accessible ComfyUI instances.
ComfyUI-OTP-Auth
A custom node for ComfyUI that adds a simple One-Time Password (OTP) authentication using Google Authenticator or similar apps. It acts as a "gatekeeper" to prevent unauthorized use when hosting ComfyUI on a publicly accessible server.

Features
- OTP Authentication: Secure login using codes generated by Google Authenticator (TOTP).
- First-Run Setup: Displays a QR code on the first launch for easy pairing with your authenticator app.
- Persistent Login: Keeps you logged in for a set period (30 days) using cookies.
- IP Whitelist: Bypass authentication for specific IP addresses or CIDR ranges.
- Localhost Exemption: Option to skip authentication when accessing from
localhost.
Installation
- Clone or download this repository into your ComfyUI
custom_nodesfolder. - Install the required dependencies:
pip install -r requirements.txt
First-Time Setup
- Start ComfyUI.
- Open ComfyUI in your browser. You will see the Initial Setup screen.

- Scan the displayed QR Code with your authenticator app (e.g., Google Authenticator).
- Note: If you are using this locally, check "Allow Localhost without Auth" to skip authentication for local access in the future.
- Enter the 6-digit code shown in your app and click "Complete Setup".
- If the code is correct, setup is complete and you will be redirected to ComfyUI.
Configuration (config.ini)
A config.ini file is automatically generated upon the first run. Edit this file to change settings.
Restart ComfyUI to apply changes.
[AUTH]
# Secret key for OTP (Base32). Automatically generated.
SECRET_KEY = XXXXXXXXXXXXXXXXXXXXXXX
# Cookie name for authentication. Automatically generated.
COOKIE_NAME = ComfyUI_Auth_abcdef12
# Setup completion flag. If True, skips the setup screen.
# Set to False to re-run the setup process.
IS_SETUP_COMPLETED = True
# Whether to skip authentication for localhost (127.0.0.1, ::1).
# True = Skip, False = Require Auth
SKIP_AUTH_ON_LOCALHOST = False
# List of IP addresses to skip authentication.
# Comma-separated list of IPs or CIDRs.
# Example: 192.168.1.5, 192.168.10.0/24
IP_WHITELIST =
How to Reset / Re-setup
If you want to reset your secret key or change authentication settings:
- Method 1 (Full Reset): Delete
config.iniand restart ComfyUI. A new secret key and QR code will be generated. - Method 2 (Keep Key): Edit
config.iniand changeIS_SETUP_COMPLETEDtoFalse, then restart. The setup screen will appear again using the current secret key.
<a name="日本語"></a>
ComfyUI-OTP-Auth (Japanese)
ComfyUIにGoogle AuthenticatorなどのOTP(ワンタイムパスワード)を使用した簡易的な認証機能を追加するカスタムノードです。 グローバル公開されているサーバーなどでの不正利用を防ぐための「門番」として機能します。

機能
- OTP認証: Google Authenticatorなどで生成されたコードによるログイン。
- 初回セットアップ: 初回起動時にQRコードを表示し、スマホアプリとの連携を容易にします。
- 永続ログイン: クッキーを使用して一定期間(30日)ログイン状態を保持します。
- IPホワイトリスト: 指定したIPアドレスやCIDR範囲からのアクセスを認証不要にできます。
- ローカル除外:
localhostからのアクセスを認証不要にする設定が可能です。
インストール
- ComfyUIの
custom_nodesフォルダにこのリポジトリを配置します。 - 依存ライブラリをインストールします。
pip install -r requirements.txt
初回セットアップ
- ComfyUIを起動します。
- ブラウザでComfyUIにアクセスすると、Initial Setup 画面が表示されます。

- 画面に表示された QRコード をGoogle Authenticatorなどの認証アプリで読み取ります。
- ※ ローカル(自分のPC)だけで使う場合は、「Allow Localhost without Auth」にチェックを入れると、次回からローカルアクセス時の認証がスキップされます。
- アプリに表示された6桁のコードを入力し、「Complete Setup」をクリックします。
- 正しいコードであれば認証が完了し、ComfyUIの画面が表示されます。
設定 (config.ini)
初回起動時に config.ini が自動生成されます。後から設定を変更したい場合はこのファイルを編集してください。
ComfyUIを再起動すると変更が反映されます。
[AUTH]
# OTP認証用の秘密鍵 (Base32)。自動生成されます。
SECRET_KEY = XXXXXXXXXXXXXXXXXXXXXXX
# 認証クッキー名。自動生成されます。
COOKIE_NAME = ComfyUI_Auth_abcdef12
# セットアップ完了フラグ。Trueの場合、セットアップ画面をスキップします。
# 再セットアップしたい場合は False に戻してください。
IS_SETUP_COMPLETED = True
# ローカルホスト (127.0.0.1, ::1) からのアクセスで認証をスキップするかどうか。
# True = スキップする, False = スキップしない
SKIP_AUTH_ON_LOCALHOST = False
# 認証をスキップするIPアドレスのリスト。
# カンマ区切りで複数のIPやCIDRを指定できます。
# 例: 192.168.1.5, 192.168.10.0/24
IP_WHITELIST =
再セットアップ方法
もし秘密鍵をリセットしたい、または認証設定をやり直したい場合は以下のいずれかを行ってください。
- 方法1 (簡単):
config.iniを削除してComfyUIを再起動する。すべてが初期化され、新しいQRコードが生成されます。 - 方法2 (鍵を維持):
config.iniのIS_SETUP_COMPLETEDをFalseに書き換えて再起動する。現在の鍵のままセットアップ画面が表示されます。