diff options
| author | haturatu <taro@eyes4you.org> | 2025-10-13 02:58:46 +0900 |
|---|---|---|
| committer | haturatu <taro@eyes4you.org> | 2025-10-13 02:58:46 +0900 |
| commit | d062e70ba21e5a4ec5b84a356c8905778535ac9c (patch) | |
| tree | 67b7c677244d36b1bc2e92a45617a180f8f44773 | |
| parent | 203307941afefa6d55021e753c03005d97c4e31d (diff) | |
add(demo): startup shell
| -rw-r--r-- | .env.example | 12 | ||||
| -rw-r--r-- | README.ja.md | 6 | ||||
| -rw-r--r-- | README.md | 8 | ||||
| -rw-r--r-- | cmd/admin-cli/main.go | 4 | ||||
| -rwxr-xr-x | run-demo.sh | 63 |
5 files changed, 87 insertions, 6 deletions
diff --git a/.env.example b/.env.example index 70e44e4..430681f 100644 --- a/.env.example +++ b/.env.example @@ -10,6 +10,10 @@ TARGET_URL=http://localhost:8081 # For production, generate a new key using: openssl rand -base64 45 SESSION_SECRET= +# (Required) A 32-byte random key for CSRF protection. +# Generate with: openssl rand -base64 32 +CSRF_SECRET_KEY= + # --- Database --- # Use ONE of the following options: @@ -54,10 +58,6 @@ ACCESS_TOKEN_DURATION_MINUTES=15 # Duration for the API JWT refresh token REFRESH_TOKEN_DURATION_DAYS=7 -# --- PHP Frontend Settings (only needed if FRONTEND_TYPE=php) --- -# PHP_FPM_SOCKET=/run/php-fpm/php-fpm.sock -# PHP_DOC_ROOT= - # --- Optional: Path Overrides --- # Uncomment and change these to avoid URL conflicts with your backend application. # AUTH_PATH_LOGIN=/login @@ -68,3 +68,7 @@ REFRESH_TOKEN_DURATION_DAYS=7 # AUTH_PATH_ADMIN=/admin # AUTH_PATH_ADMIN_USERS_API=/api/admin/users # AUTH_ASSETS_PATH=/assets + +# --- PHP Frontend Settings (only needed if FRONTEND_TYPE=php) --- +# PHP_FPM_SOCKET=/run/php-fpm/php-fpm.sock +# PHP_DOC_ROOT=
\ No newline at end of file diff --git a/README.ja.md b/README.ja.md index e4be653..06f88f8 100644 --- a/README.ja.md +++ b/README.ja.md @@ -12,6 +12,12 @@ 特にセルフホストが好きな人にとってはどうアクセス制御するか、です。 ある主、このサーバーが認証基盤として機能して同じDBを参照することによってユーザ情報は共有できます。 +## おためし +```bash +chmod +x run-demo.sh +bash run-demo.sh +``` + ## 主な機能 - **認証**: ログイン、ログアウト、登録ページを提供します。 @@ -4,6 +4,12 @@ This is a simple authenticating reverse proxy written in Go. It provides a flexi It handles user registration, login, and session management, and proxies authenticated requests to the configured backend. It also includes an administration dashboard for user management. +## Try the Demo +```bash +chmod +x run-demo.sh +bash run-demo.sh +``` + ## Why I Built This I'm also the developer of [puremania](https://github.com/haturatu/puremania), and I wanted to avoid adding complex authentication logic to that project. @@ -484,4 +490,4 @@ The base path for these endpoints is `/api/admin/users`, which can be customized | `ENV` | The runtime environment. Set to `production` to enable secure cookies. | - | | `CSRF_SECRET_KEY` | **(Required)** A 32-byte random key for CSRF protection. Generate with `openssl rand -base64 32`. | - | | `CSRF_TRUSTED_ORIGINS` | A comma-separated list of trusted origins for CSRF protection. | - | -| `CSRF_SAME_SITE` | The SameSite attribute for the CSRF cookie. Can be `lax`, `strict`, or `none`. | `lax` |
\ No newline at end of file +| `CSRF_SAME_SITE` | The SameSite attribute for the CSRF cookie. Can be `lax`, `strict`, or `none`. | `lax` | diff --git a/cmd/admin-cli/main.go b/cmd/admin-cli/main.go index 91439c4..d7d4114 100644 --- a/cmd/admin-cli/main.go +++ b/cmd/admin-cli/main.go @@ -1,6 +1,7 @@ package main import ( + "auth-proxy/config" "auth-proxy/database" "auth-proxy/logging" "auth-proxy/models" @@ -16,10 +17,11 @@ func main() { // Initialize logging logging.InitLoggers() - // Load .env file + // Load .env file and initialize config if err := godotenv.Load(); err != nil { logging.AppLog.Info("No .env file found, using environment variables") } + config.Init() username := flag.String("username", "", "Username for the new admin user") password := flag.String("password", "", "Password for the new admin user") diff --git a/run-demo.sh b/run-demo.sh new file mode 100755 index 0000000..28852ac --- /dev/null +++ b/run-demo.sh @@ -0,0 +1,63 @@ +#!/bin/bash +# This script automates the setup of a local development environment. + +set -e + +cleanup() { + echo "" + echo "--- Shutting down server ---" + # The PID is stored in a variable. Kill the process. + if [ -n "$SERVER_PID" ]; then + kill $SERVER_PID 2>/dev/null || true + fi +} +trap cleanup EXIT + +echo "--> Creating .env file" +cat > .env << EOF +LISTEN_PORT=8080 +TARGET_URL=http://localhost:8081 +SESSION_SECRET=$(openssl rand -base64 32) +CSRF_SECRET_KEY=$(openssl rand -base64 32) +DATABASE_PATH=./auth.db +PROTECT_API=true +PROTECT_FRONTEND=true +MAX_LOGIN_ATTEMPTS=5 +LOCKOUT_DURATION_MINUTES=10 +EOF + +echo "--> Building application" +go build -o auth-proxy-server ./cmd/server +go build -o admin-cli ./cmd/admin-cli + +rm -f ./auth.db + +echo "--> Starting server in background" +./auth-proxy-server & +SERVER_PID=$! + +sleep 3 + +echo "--> Creating admin user" +./admin-cli --username "admin" --password "password123" + +echo "--> Fetching API token" +JSON_DATA='{"username": "admin", "password": "password123"}' +TOKEN_RESPONSE=$(curl -s -X POST -H "Content-Type: application/json" -d "$JSON_DATA" http://localhost:8080/api/auth/token) + +echo "" +echo "===================================" +echo "Dev Server is Ready" +echo "" +echo "Server is running (PID: $SERVER_PID)" +echo "Admin user: admin / password123" +echo "" +echo "API Token Response:" +echo "$TOKEN_RESPONSE" +echo "===================================" +echo "Proxy is listening on http://localhost:8080/login" +echo "Backend target is http://localhost:8081" +echo "" +echo "Press Ctrl+C to stop the server." + +wait $SERVER_PID |
