Extensions/ComfyUI-OTP-Auth
ComfyUI Extension

ComfyUI-OTP-Auth

Adds simple One-Time Password (OTP) authentication using Google Authenticator to protect publicly accessible ComfyUI instances.

By ah-kun·Created 7 months ago·Updated 7 months ago· 3
ah-kun/ComfyUI-OTP-Auth
Nodes
On cloudLocal install
Stars3
Updated7 months ago
Readme

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.

Login Screen

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

  1. Clone or download this repository into your ComfyUI custom_nodes folder.
  2. Install the required dependencies:
pip install -r requirements.txt

First-Time Setup

  1. Start ComfyUI.
  2. Open ComfyUI in your browser. You will see the Initial Setup screen.

Setup Screen

  1. 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.
  2. Enter the 6-digit code shown in your app and click "Complete Setup".
  3. 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.ini and restart ComfyUI. A new secret key and QR code will be generated.
  • Method 2 (Keep Key): Edit config.ini and change IS_SETUP_COMPLETED to False, then restart. The setup screen will appear again using the current secret key.

<a name="日本語"></a>

ComfyUI-OTP-Auth (Japanese)

ComfyUIにGoogle AuthenticatorなどのOTP(ワンタイムパスワード)を使用した簡易的な認証機能を追加するカスタムノードです。 グローバル公開されているサーバーなどでの不正利用を防ぐための「門番」として機能します。

Login Screen

機能

  • OTP認証: Google Authenticatorなどで生成されたコードによるログイン。
  • 初回セットアップ: 初回起動時にQRコードを表示し、スマホアプリとの連携を容易にします。
  • 永続ログイン: クッキーを使用して一定期間(30日)ログイン状態を保持します。
  • IPホワイトリスト: 指定したIPアドレスやCIDR範囲からのアクセスを認証不要にできます。
  • ローカル除外: localhost からのアクセスを認証不要にする設定が可能です。

インストール

  1. ComfyUIの custom_nodes フォルダにこのリポジトリを配置します。
  2. 依存ライブラリをインストールします。
pip install -r requirements.txt

初回セットアップ

  1. ComfyUIを起動します。
  2. ブラウザでComfyUIにアクセスすると、Initial Setup 画面が表示されます。

Setup Screen

  1. 画面に表示された QRコード をGoogle Authenticatorなどの認証アプリで読み取ります。
    • ※ ローカル(自分のPC)だけで使う場合は、「Allow Localhost without Auth」にチェックを入れると、次回からローカルアクセス時の認証がスキップされます。
  2. アプリに表示された6桁のコードを入力し、「Complete Setup」をクリックします。
  3. 正しいコードであれば認証が完了し、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.iniIS_SETUP_COMPLETEDFalse に書き換えて再起動する。現在の鍵のままセットアップ画面が表示されます。