Skip to content

Take control over your live stream video by running it yourself. Streaming + chat out of the box.

test(auth): end-to-end integration tests for auth flows and plugin gates

Gabe Kangas1d5df9291e18
diff --git a/.github/workflows/activitypub-tests.yaml b/.github/workflows/activitypub-tests.yaml
index aeb7e150ad..dc92285a36 100644
--- a/.github/workflows/activitypub-tests.yaml
+++ b/.github/workflows/activitypub-tests.yaml
@@ -10,6 +10,8 @@ on:
- "config/**"
- "main.go"
- "webserver/**"
+ - "auth/**"
+ - "persistence/userrepository/**"
- "test/automated/activitypub/**"
- ".github/workflows/activitypub-tests.yaml"
pull_request:
@@ -19,6 +21,8 @@ on:
- "config/**"
- "main.go"
- "webserver/**"
+ - "auth/**"
+ - "persistence/userrepository/**"
- "test/automated/activitypub/**"
- ".github/workflows/activitypub-tests.yaml"
@@ -189,3 +193,99 @@ jobs:
run: |
cd test/automated/activitypub
CI=true ./test-featured-streams.sh
+
+ fediverse-auth-test:
+ runs-on: ubuntu-latest
+ steps:
+ - id: skip_check
+ uses: fkirc/skip-duplicate-actions@v5
+ with:
+ concurrent_skipping: "same_content_newer"
+
+ - name: Check out repository code
+ uses: actions/checkout@v6
+
+ - name: Set up Go
+ uses: actions/setup-go@v6
+ with:
+ go-version: "1.26.4"
+ cache: true
+
+ - name: Install Caddy
+ run: |
+ sudo apt-get update
+ sudo apt-get install -y debian-keyring debian-archive-keyring apt-transport-https curl
+ curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | sudo gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg
+ curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' | sudo tee /etc/apt/sources.list.d/caddy-stable.list
+ sudo apt-get update
+ sudo apt-get install -y caddy
+
+ - name: Install dependencies
+ run: |
+ sudo apt-get install -y snac2 ffmpeg jq
+
+ - name: Run setup
+ env:
+ # Authenticates the mkcert download in setup.sh against github.com
+ # to avoid the anonymous, shared-per-IP rate limit on CI runners.
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+ run: |
+ cd test/automated/activitypub
+ # Preserve GITHUB_TOKEN across sudo (sudo strips env by default) so
+ # setup.sh's github.com downloads use it.
+ sudo --preserve-env=GITHUB_TOKEN ./setup.sh
+
+ - name: Run Fediverse OTP auth test
+ timeout-minutes: 15
+ run: |
+ cd test/automated/activitypub
+ CI=true ./test-fediverse-otp.sh
+
+ indieauth-auth-test:
+ runs-on: ubuntu-latest
+ steps:
+ - id: skip_check
+ uses: fkirc/skip-duplicate-actions@v5
+ with:
+ concurrent_skipping: "same_content_newer"
+
+ - name: Check out repository code
+ uses: actions/checkout@v6
+
+ - name: Set up Go
+ uses: actions/setup-go@v6
+ with:
+ go-version: "1.26.4"
+ cache: true
+
+ - name: Install Caddy
+ run: |
+ sudo apt-get update
+ sudo apt-get install -y debian-keyring debian-archive-keyring apt-transport-https curl
+ curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | sudo gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg
+ curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' | sudo tee /etc/apt/sources.list.d/caddy-stable.list
+ sudo apt-get update
+ sudo apt-get install -y caddy
+
+ - name: Install dependencies
+ run: |
+ # snac2 is installed so setup.sh's dependency check is satisfied; the
+ # IndieAuth test itself only needs Caddy + jq (no federation peer).
+ sudo apt-get install -y snac2 ffmpeg jq
+
+ - name: Run setup
+ env:
+ # Authenticates the mkcert download in setup.sh against github.com
+ # to avoid the anonymous, shared-per-IP rate limit on CI runners.
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+ run: |
+ cd test/automated/activitypub
+ # Preserve GITHUB_TOKEN across sudo (sudo strips env by default) so
+ # setup.sh's github.com downloads use it.
+ sudo --preserve-env=GITHUB_TOKEN ./setup.sh
+
+ - name: Run IndieAuth auth test
+ timeout-minutes: 15
+ run: |
+ cd test/automated/activitypub
+ CI=true ./test-indieauth.sh
diff --git a/.github/workflows/auth-tests.yml b/.github/workflows/auth-tests.yml
new file mode 100644
index 0000000000..6b8dcb56ca
--- /dev/null
+++ b/.github/workflows/auth-tests.yml
@@ -0,0 +1,102 @@
+# Runs the end-to-end viewer-authentication ("auth gate") integration tests:
+# builds two auth.gate plugins from the Owncast plugin SDK (a shared-password
+# gate and an OAuth gate), loads them into a real Owncast instance, and verifies
+# the gate blocks viewers until they authenticate while admin stays reachable.
+# The OAuth suite authenticates against a real node-oidc-provider instance.
+# Mirrors the HLS test workflow (a self-contained ./run.sh).
+
+name: Auth gate tests
+
+on:
+ push:
+ branches:
+ - develop
+ paths:
+ - '**.go'
+ - 'go.mod'
+ - 'go.sum'
+ - 'test/automated/auth/**'
+ - '.github/workflows/auth-tests.yml'
+ pull_request:
+ paths:
+ - '**.go'
+ - 'go.mod'
+ - 'go.sum'
+ - 'test/automated/auth/**'
+ - '.github/workflows/auth-tests.yml'
+
+env:
+ # Authenticates github.com downloads in tools.sh (ffmpeg) to avoid the
+ # anonymous, shared-per-IP rate limit on CI runners.
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+
+jobs:
+ tests:
+ runs-on: ubuntu-latest
+
+ steps:
+ - id: skip_check
+ uses: fkirc/skip-duplicate-actions@v5
+ with:
+ concurrent_skipping: 'same_content_newer'
+
+ - name: Check out pull request code
+ uses: actions/checkout@v6
+ if: github.event_name == 'pull_request'
+ with:
+ repository: ${{ github.event.pull_request.head.repo.full_name }}
+ ref: ${{ github.event.pull_request.head.ref }}
+ fetch-depth: 0
+
+ - name: Fetch base branch for comparison
+ if: github.event_name == 'pull_request'
+ run: |
+ git remote add upstream https://github.com/${{ github.event.pull_request.base.repo.full_name }}.git || true
+ git fetch upstream ${{ github.event.pull_request.base.ref }}
+
+ - name: Check out repository code
+ uses: actions/checkout@v6
+ if: github.event_name == 'push'
+
+ - name: Get changed files
+ id: changed-files-yaml
+ uses: tj-actions/changed-files@v47
+ with:
+ files_yaml: |
+ src:
+ - '**/*.{go,mod,sum}'
+ - 'test/automated/auth/**'
+
+ - uses: actions/setup-go@v6
+ if: steps.changed-files-yaml.outputs.src_any_changed == 'true'
+ with:
+ go-version: '1.26.4'
+ cache: true
+
+ # The plugin SDK build (owncast-plugin) and the OAuth provider
+ # (node-oidc-provider) both require a recent Node; the runner default may
+ # be older, so pin it.
+ - uses: actions/setup-node@v4
+ if: steps.changed-files-yaml.outputs.src_any_changed == 'true'
+ with:
+ node-version: '24'
+
+ - name: Cache node modules
+ uses: actions/cache@v5
+ env:
+ cache-name: cache-node-modules-auth-tests
+ with:
+ path: ~/.npm
+ key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('test/automated/auth/package-lock.json') }}
+ restore-keys: |
+ ${{ runner.os }}-build-${{ env.cache-name }}-
+ ${{ runner.os }}-build-
+ ${{ runner.os }}-
+
+ - name: Auth gate tests (shared-password + OAuth)
+ if: steps.changed-files-yaml.outputs.src_any_changed == 'true'
+ uses: nick-fields/retry@v4
+ with:
+ timeout_minutes: 10
+ max_attempts: 3
+ command: cd test/automated/auth && ./run.sh
diff --git a/test/automated/activitypub/Caddyfile.indieauth b/test/automated/activitypub/Caddyfile.indieauth
new file mode 100644
index 0000000000..b8ac076aae
--- /dev/null
+++ b/test/automated/activitypub/Caddyfile.indieauth
@@ -0,0 +1,68 @@
+# Caddyfile for the IndieAuth end-to-end auth test.
+#
+# Fronts Owncast (owncast.local) and a self-contained FAKE IndieAuth provider
+# (indieauth.local) over HTTPS using the harness's mkcert certificates. The
+# fake provider implements just enough of IndieAuth for Owncast's client flow:
+#
+# GET / discovery document advertising the authorization_endpoint
+# GET /auth authorize: bounce the browser back to the client's
+# redirect_uri with a code (auto-approve, no UI)
+# POST /auth code exchange: return the canonical profile URL ("me"),
+# which must equal the host Owncast was pointed at
+#
+# PKCE is intentionally not enforced here — the provider's job is only to give
+# Owncast's client a protocol-correct response so the full discover -> redirect
+# -> callback -> exchange -> identity-link path can be exercised against a real
+# HTTPS host.
+{
+ auto_https off
+ admin off
+ log {
+ level error
+ }
+}
+
+https://:{$PROXY_PORT} {
+ tls {$CERT_FILE} {$KEY_FILE}
+
+ # Owncast under test.
+ @owncast host owncast.local
+ handle @owncast {
+ reverse_proxy localhost:{$OWNCAST_PORT}
+ }
+
+ # Fake IndieAuth provider: discovery document.
+ @ia_discovery {
+ host indieauth.local
+ path /
+ }
+ handle @ia_discovery {
+ header Content-Type text/html
+ respond `<!doctype html><html><head><link rel="authorization_endpoint" href="https://indieauth.local:{$PROXY_PORT}/auth"></head><body>fake indieauth provider</body></html>` 200
+ }
+
+ # Fake IndieAuth provider: authorize (browser leg) -> redirect back with a code.
+ @ia_auth_get {
+ host indieauth.local
+ path /auth
+ method GET
+ }
+ handle @ia_auth_get {
+ redir {http.request.uri.query.redirect_uri}?code=fakecode&state={http.request.uri.query.state} 302
+ }
+
+ # Fake IndieAuth provider: code exchange -> return the profile URL.
+ @ia_auth_post {
+ host indieauth.local
+ path /auth
+ method POST
+ }
+ handle @ia_auth_post {
+ header Content-Type application/json
+ respond `{"me":"https://indieauth.local:{$PROXY_PORT}/"}` 200
+ }
+
+ handle {
+ respond "Unknown host or path" 404
+ }
+}
diff --git a/test/automated/activitypub/README.md b/test/automated/activitypub/README.md
index ef21378025..1013a695ec 100644
--- a/test/automated/activitypub/README.md
+++ b/test/automated/activitypub/README.md
@@ -23,6 +23,10 @@ USER_COUNT=10 ./run.sh
# Run the featured streams test (two Owncast instances, no snac2)
./run.sh test-featured-streams.sh
+# Run the user-authentication tests
+./run.sh test-fediverse-otp.sh # Fediverse OTP login (uses snac2)
+./run.sh test-indieauth.sh # IndieAuth login (uses a fake provider, no snac2)
+
# Keep servers running after test for debugging
KEEP_RUNNING=true ./run.sh
@@ -69,6 +73,38 @@ behind the shared proxy. It:
5. Verifies the listing is readable on the public, unauthenticated endpoint
6. Verifies the reverse direction (instance 2 adds instance 1) also works
+### `test-fediverse-otp.sh` (Fediverse authentication, snac2-based)
+
+End-to-end test of logging in with a Fediverse account, with no backend stubs.
+It:
+
+1. Registers an anonymous chat user on Owncast (gets an access token)
+2. Requests a Fediverse OTP for a snac2 account; Owncast delivers the code as a
+ real ActivityPub direct message (webfinger + signed inbox POST)
+3. Reads the delivered code back out of snac2's stored DM
+4. Submits the code to Owncast's verify endpoint
+5. Verifies the admin users API now reports the user as authenticated with a
+ `Fediverse` provider
+
+### `test-indieauth.sh` (IndieAuth authentication, fake provider, no snac2)
+
+End-to-end test of logging in with IndieAuth against a fake provider hosted by
+the Caddy proxy at `indieauth.local` (see `Caddyfile.indieauth`). The provider
+serves a discovery document, auto-approves the authorization request, and
+returns a canonical `me` on code exchange. The test:
+
+1. Registers an anonymous chat user on Owncast
+2. Starts the IndieAuth flow pointed at the fake provider; Owncast discovers its
+ authorization endpoint and returns a redirect URL
+3. Follows the redirect like a browser would, through the provider and back to
+ Owncast's callback, where Owncast exchanges the code and links the identity
+4. Verifies the admin users API now reports the user as authenticated with an
+ `IndieAuth` provider
+
+Neither auth test changes the backend: `OWNCAST_ALLOW_INTERNAL_FEDERATION` lets
+Owncast accept the local test hosts, and the mkcert CA makes its outbound HTTPS
+calls trust the test certificates.
+
## Test Results
The test reports:
diff --git a/test/automated/activitypub/entrypoint.sh b/test/automated/activitypub/entrypoint.sh
index 34da4b9f39..32987a3da8 100755
--- a/test/automated/activitypub/entrypoint.sh
+++ b/test/automated/activitypub/entrypoint.sh
@@ -9,7 +9,7 @@ export CERT_DIR="/tmp/test-certs"
mkdir -p "${CERT_DIR}"
mkcert -cert-file "${CERT_DIR}/cert.pem" \
-key-file "${CERT_DIR}/key.pem" \
- owncast.local owncast2.local snac.local localhost 127.0.0.1
+ owncast.local owncast2.local snac.local indieauth.local localhost 127.0.0.1
# This container runs as root and the repo is bind-mounted from the host, so
# anything the test writes into the tree (Owncast's ./data dir, created mode
diff --git a/test/automated/activitypub/run.sh b/test/automated/activitypub/run.sh
index b00de4e0e2..7cf765d3eb 100755
--- a/test/automated/activitypub/run.sh
+++ b/test/automated/activitypub/run.sh
@@ -50,6 +50,7 @@ docker run --rm \
--add-host owncast.local:127.0.0.1 \
--add-host owncast2.local:127.0.0.1 \
--add-host snac.local:127.0.0.1 \
+ --add-host indieauth.local:127.0.0.1 \
-v "${REPO_ROOT}:/owncast" \
-v owncast-ap-test-gomod:/go/pkg/mod \
-v owncast-ap-test-gobuild:/root/.cache/go-build \
diff --git a/test/automated/activitypub/setup.sh b/test/automated/activitypub/setup.sh
index d7ecc99bb6..4e18e51d5a 100755
--- a/test/automated/activitypub/setup.sh
+++ b/test/automated/activitypub/setup.sh
@@ -56,18 +56,24 @@ chown "${ACTUAL_USER}:${ACTUAL_USER}" "${SCRIPT_DIR}/certs"
sudo -u "${ACTUAL_USER}" CAROOT="${ACTUAL_HOME}/.local/share/mkcert" mkcert \
-cert-file "${SCRIPT_DIR}/certs/cert.pem" \
-key-file "${SCRIPT_DIR}/certs/key.pem" \
- owncast.local owncast2.local snac.local localhost 127.0.0.1
+ owncast.local owncast2.local snac.local indieauth.local localhost 127.0.0.1
# 4. Add hosts entries
if ! grep -q "owncast.local" /etc/hosts; then
log_info "Adding hosts entries..."
- echo "127.0.0.1 owncast.local owncast2.local snac.local" >> /etc/hosts
+ echo "127.0.0.1 owncast.local owncast2.local snac.local indieauth.local" >> /etc/hosts
elif ! grep -q "owncast2.local" /etc/hosts; then
log_info "Adding owncast2.local hosts entry..."
echo "127.0.0.1 owncast2.local" >> /etc/hosts
else
log_info "Hosts entries already exist"
fi
+# indieauth.local (used by the IndieAuth auth test) may be missing on installs
+# whose hosts line predates it; ensure it independently.
+if ! grep -q "indieauth.local" /etc/hosts; then
+ log_info "Adding indieauth.local hosts entry..."
+ echo "127.0.0.1 indieauth.local" >> /etc/hosts
+fi
# 5. Check for snac2
if ! command -v snac &> /dev/null; then
diff --git a/test/automated/activitypub/test-fediverse-otp.sh b/test/automated/activitypub/test-fediverse-otp.sh
new file mode 100755
index 0000000000..8ca4314647
--- /dev/null
+++ b/test/automated/activitypub/test-fediverse-otp.sh
@@ -0,0 +1,263 @@
+#!/bin/bash
+
+# End-to-end Fediverse authentication test.
+#
+# Exercises the real OTP-over-ActivityPub login flow against a live snac2
+# instance, with no stubs:
+# 1. Register an anonymous chat user on Owncast (gets an access token).
+# 2. Ask Owncast to link a Fediverse account; Owncast DMs a one-time code to
+# that account over real federation (webfinger + signed inbox POST).
+# 3. Read the code back out of snac2's stored DM (same approach the
+# federation test uses to confirm message delivery).
+# 4. Submit the code to Owncast's verify endpoint.
+# 5. Assert the admin users API now reports the user as authenticated with a
+# "Fediverse" provider.
+#
+# Runs inside the same Docker harness as the federation tests:
+# ./run.sh test-fediverse-otp.sh
+#
+# Reuses the activitypub harness's certs (mkcert), Caddy reverse proxy, and
+# snac2 build. No backend code changes are needed: OWNCAST_ALLOW_INTERNAL_FEDERATION
+# and OWNCAST_INSECURE_SKIP_VERIFY let the federated DM flow run against localhost.
+
+set -o pipefail
+
+SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
+
+PROXY_PORT="${PROXY_PORT:-8443}"
+SNAC_PORT="${SNAC_PORT:-9080}"
+SNAC_HOSTNAME="snac.local"
+OWNCAST_PORT="${OWNCAST_PORT:-8080}"
+OWNCAST_HOSTNAME="owncast.local"
+
+OWNCAST_URL="https://${OWNCAST_HOSTNAME}:${PROXY_PORT}"
+
+ADMIN_USER="admin"
+ADMIN_PASS="abc123"
+FEDERATION_USERNAME="streamer"
+
+# The Fediverse account we'll authenticate against — a user we create in snac2.
+SNAC_USERNAME="otptester"
+FEDIVERSE_ACCOUNT="${SNAC_USERNAME}@${SNAC_HOSTNAME}:${PROXY_PORT}"
+
+TEMP_DIR=""
+SNAC_DATA_DIR=""
+SNAC_BIN=""
+OWNCAST_BIN=""
+OWNCAST_DB=""
+SNAC_PID=""
+OWNCAST_PID=""
+PROXY_PID=""
+
+RED='\033[0;31m'; GREEN='\033[0;32m'; CYAN='\033[0;36m'; NC='\033[0m'
+log_info() { echo -e "${GREEN}[INFO]${NC} $1"; }
+log_error() { echo -e "${RED}[ERROR]${NC} $1"; }
+log_test() { echo -e "${CYAN}[TEST]${NC} $1"; }
+
+# shellcheck disable=SC2329 # invoked via trap
+cleanup() {
+ log_info "Cleaning up..."
+ for pid in "${PROXY_PID}" "${OWNCAST_PID}" "${SNAC_PID}"; do
+ if [[ -n "${pid}" ]] && kill -0 "${pid}" 2>/dev/null; then
+ kill "${pid}" 2>/dev/null || true
+ wait "${pid}" 2>/dev/null || true
+ fi
+ done
+ pkill -f "snac httpd /tmp" 2>/dev/null || true
+ [[ -n "${TEMP_DIR}" && -d "${TEMP_DIR}" ]] && rm -rf "${TEMP_DIR}"
+ log_info "Cleanup complete."
+}
+trap cleanup EXIT
+
+setup_temp_dir() {
+ TEMP_DIR=$(mktemp -d)
+ SNAC_DATA_DIR="${TEMP_DIR}/snac-data"
+ OWNCAST_DB="${TEMP_DIR}/owncast.db"
+ log_info "Temp directory: ${TEMP_DIR}"
+}
+
+check_certs() {
+ CERT_DIR="${CERT_DIR:-${SCRIPT_DIR}/certs}"
+ if [[ ! -f "${CERT_DIR}/cert.pem" || ! -f "${CERT_DIR}/key.pem" ]]; then
+ log_error "Certificates not found in ${CERT_DIR} (run inside the Docker harness, or see README.md)"
+ exit 1
+ fi
+ export CERT_FILE="${CERT_DIR}/cert.pem"
+ export KEY_FILE="${CERT_DIR}/key.pem"
+ log_info "Using certificates from ${CERT_DIR}"
+}
+
+install_snac2() {
+ if command -v snac &>/dev/null; then
+ SNAC_BIN=$(command -v snac)
+ log_info "Using system snac2: ${SNAC_BIN}"
+ return
+ fi
+ local snac_src="${TEMP_DIR}/snac2-src"
+ log_info "Building snac2..."
+ git clone --depth 1 https://codeberg.org/grunfink/snac2.git "${snac_src}" 2>/dev/null
+ (cd "${snac_src}" && make >/dev/null 2>&1)
+ SNAC_BIN="${snac_src}/snac"
+}
+
+setup_snac() {
+ log_info "Initializing snac2 and creating @${SNAC_USERNAME}..."
+ printf "127.0.0.1\n%s\n%s\n\[email protected]\n" "${SNAC_PORT}" "${SNAC_HOSTNAME}:${PROXY_PORT}" |
+ "${SNAC_BIN}" init "${SNAC_DATA_DIR}" >/dev/null 2>&1
+ if [[ ! -f "${SNAC_DATA_DIR}/server.json" ]]; then
+ log_error "snac2 init failed"
+ exit 1
+ fi
+ printf "%s\n%s\n" "${SNAC_USERNAME}" "OTP Tester" |
+ "${SNAC_BIN}" adduser "${SNAC_DATA_DIR}" >/dev/null 2>&1
+}
+
+start_snac() {
+ log_info "Starting snac2..."
+ DEBUG=0 "${SNAC_BIN}" httpd "${SNAC_DATA_DIR}" >"${TEMP_DIR}/snac2.log" 2>&1 &
+ SNAC_PID=$!
+ for _ in $(seq 1 30); do
+ curl -s "http://127.0.0.1:${SNAC_PORT}/" >/dev/null 2>&1 && { log_info "snac2 ready"; return 0; }
+ sleep 1
+ done
+ log_error "snac2 did not become ready"; return 1
+}
+
+start_proxy() {
+ log_info "Starting Caddy reverse proxy..."
+ export PROXY_PORT OWNCAST_PORT SNAC_PORT
+ export OWNCAST2_PORT="${OWNCAST2_PORT:-8081}"
+ caddy run --config "${SCRIPT_DIR}/Caddyfile" --adapter caddyfile >"${TEMP_DIR}/caddy.log" 2>&1 &
+ PROXY_PID=$!
+ sleep 2
+ for _ in $(seq 1 10); do
+ curl -sk "https://127.0.0.1:${PROXY_PORT}/" >/dev/null 2>&1 && { log_info "Caddy ready"; return 0; }
+ sleep 1
+ done
+ log_error "Caddy did not become ready"; return 1
+}
+
+build_owncast() {
+ log_info "Building Owncast..."
+ OWNCAST_BIN="${TEMP_DIR}/owncast"
+ (cd "$(git rev-parse --show-toplevel)" && CGO_ENABLED=1 go build -o "${OWNCAST_BIN}" main.go) ||
+ { log_error "Owncast build failed"; exit 1; }
+}
+
+start_owncast() {
+ log_info "Starting Owncast..."
+ OWNCAST_ALLOW_INTERNAL_FEDERATION=true \
+ OWNCAST_INSECURE_SKIP_VERIFY=true \
+ "${OWNCAST_BIN}" -database "${OWNCAST_DB}" >"${TEMP_DIR}/owncast.log" 2>&1 &
+ OWNCAST_PID=$!
+ for _ in $(seq 1 30); do
+ curl -s "http://localhost:${OWNCAST_PORT}/api/status" >/dev/null 2>&1 && { log_info "Owncast ready"; return 0; }
+ sleep 1
+ done
+ log_error "Owncast did not become ready"; return 1
+}
+
+owncast_admin_post() {
+ local path="$1" body="$2"
+ curl -s -X POST "http://localhost:${OWNCAST_PORT}/api/admin/${path}" \
+ -u "${ADMIN_USER}:${ADMIN_PASS}" -H "Content-Type: application/json" -d "${body}" >/dev/null
+}
+
+configure_owncast() {
+ log_info "Configuring Owncast federation (${OWNCAST_URL})..."
+ owncast_admin_post "config/serverurl" "{\"value\": \"${OWNCAST_URL}\"}"
+ owncast_admin_post "config/federation/username" "{\"value\": \"${FEDERATION_USERNAME}\"}"
+ owncast_admin_post "config/federation/enable" '{"value": true}'
+ owncast_admin_post "config/federation/private" '{"value": false}'
+ sleep 2
+}
+
+# ---- the actual test ----------------------------------------------------
+
+run_otp_test() {
+ local base="http://localhost:${OWNCAST_PORT}"
+
+ log_test "Registering an anonymous chat user..."
+ local reg user_id token display
+ reg=$(curl -s -X POST "${base}/api/chat/register")
+ user_id=$(echo "${reg}" | jq -r '.id')
+ token=$(echo "${reg}" | jq -r '.accessToken')
+ display=$(echo "${reg}" | jq -r '.displayName')
+ if [[ -z "${token}" || "${token}" == "null" ]]; then
+ log_error "chat register failed: ${reg}"; return 1
+ fi
+ log_info "user_id=${user_id} display=${display}"
+
+ log_test "Requesting a Fediverse OTP for ${FEDIVERSE_ACCOUNT}..."
+ local otp_resp
+ otp_resp=$(curl -s -X POST "${base}/api/auth/fediverse?accessToken=${token}" \
+ -H "Content-Type: application/json" -d "{\"account\": \"${FEDIVERSE_ACCOUNT}\"}")
+ if ! echo "${otp_resp}" | grep -q '"success":true'; then
+ log_error "OTP registration failed: ${otp_resp}"
+ log_error "owncast log tail:"; tail -20 "${TEMP_DIR}/owncast.log" 2>/dev/null
+ return 1
+ fi
+
+ log_test "Waiting for the OTP to arrive as a Fediverse DM in snac2..."
+ local code=""
+ for _ in $(seq 1 30); do
+ code=$(grep -rl 'One-time code' "${SNAC_DATA_DIR}" 2>/dev/null |
+ xargs -r grep -hoE 'One-time code[^0-9]*[0-9]{6}' 2>/dev/null |
+ grep -oE '[0-9]{6}' | head -1)
+ [[ -n "${code}" ]] && break
+ sleep 1
+ done
+ if [[ -z "${code}" ]]; then
+ log_error "OTP code never arrived in snac2's inbox"
+ log_error "snac2 log tail:"; tail -20 "${TEMP_DIR}/snac2.log" 2>/dev/null
+ return 1
+ fi
+ log_info "Received OTP via federation: ${code}"
+
+ log_test "Verifying the OTP code..."
+ local verify_resp
+ verify_resp=$(curl -s -X POST "${base}/api/auth/fediverse/verify?accessToken=${token}" \
+ -H "Content-Type: application/json" -d "{\"code\": \"${code}\"}")
+ if ! echo "${verify_resp}" | grep -q '"success":true'; then
+ log_error "OTP verification failed: ${verify_resp}"; return 1
+ fi
+
+ log_test "Asserting the admin users API reports the Fediverse identity..."
+ local users
+ users=$(curl -s -u "${ADMIN_USER}:${ADMIN_PASS}" "${base}/api/admin/users?limit=200")
+ if echo "${users}" | jq -e --arg id "${user_id}" \
+ '.results[] | select(.id==$id) | (.authenticated==true and ((.authProviders // []) | index("Fediverse")))' >/dev/null; then
+ log_test "${GREEN}PASS${NC}: user is authenticated and shown with the Fediverse provider"
+ return 0
+ fi
+ log_error "user ${user_id} is not shown as Fediverse-authenticated"
+ echo "${users}" | jq --arg id "${user_id}" '.results[] | select(.id==$id)' 2>/dev/null
+ return 1
+}
+
+main() {
+ echo "=================================================="
+ echo " Fediverse OTP authentication — end-to-end test"
+ echo "=================================================="
+ setup_temp_dir
+ check_certs
+ install_snac2
+ setup_snac
+ build_owncast
+ start_snac
+ start_proxy
+ start_owncast
+ configure_owncast
+
+ if run_otp_test; then
+ echo ""
+ log_test "${GREEN}Fediverse OTP auth test passed.${NC}"
+ exit 0
+ else
+ echo ""
+ log_error "Fediverse OTP auth test FAILED."
+ exit 1
+ fi
+}
+
+main "$@"
diff --git a/test/automated/activitypub/test-indieauth.sh b/test/automated/activitypub/test-indieauth.sh
new file mode 100755
index 0000000000..32e14633ec
--- /dev/null
+++ b/test/automated/activitypub/test-indieauth.sh
@@ -0,0 +1,202 @@
+#!/bin/bash
+
+# End-to-end IndieAuth authentication test.
+#
+# Stands up a FAKE IndieAuth provider (served by Caddy at https://indieauth.local)
+# and drives Owncast's IndieAuth client flow against it, with no stubs in the
+# backend:
+# 1. Register an anonymous chat user on Owncast (gets an access token).
+# 2. Start the IndieAuth flow pointed at the fake provider; Owncast discovers
+# the provider's authorization endpoint and returns a redirect URL.
+# 3. Follow that redirect like a browser would: the fake provider auto-approves
+# and bounces back to Owncast's callback with a code; Owncast exchanges the
+# code with the fake provider and links the verified identity.
+# 4. Assert the admin users API now reports the user as authenticated with an
+# "IndieAuth" provider.
+#
+# Runs in the same Docker harness as the federation tests:
+# ./run.sh test-indieauth.sh
+#
+# No snac2 is needed. OWNCAST_ALLOW_INTERNAL_FEDERATION lets Owncast accept the
+# local fake host; the mkcert CA (installed in the container) makes Owncast's
+# own HTTPS calls to the provider trust the test certificate.
+
+set -o pipefail
+
+SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
+
+PROXY_PORT="${PROXY_PORT:-8443}"
+OWNCAST_PORT="${OWNCAST_PORT:-8080}"
+OWNCAST_HOSTNAME="owncast.local"
+INDIEAUTH_HOSTNAME="indieauth.local"
+
+OWNCAST_URL="https://${OWNCAST_HOSTNAME}:${PROXY_PORT}"
+INDIEAUTH_HOST="https://${INDIEAUTH_HOSTNAME}:${PROXY_PORT}/"
+
+ADMIN_USER="admin"
+ADMIN_PASS="abc123"
+
+TEMP_DIR=""
+OWNCAST_BIN=""
+OWNCAST_DB=""
+OWNCAST_PID=""
+PROXY_PID=""
+
+RED='\033[0;31m'; GREEN='\033[0;32m'; CYAN='\033[0;36m'; NC='\033[0m'
+log_info() { echo -e "${GREEN}[INFO]${NC} $1"; }
+log_error() { echo -e "${RED}[ERROR]${NC} $1"; }
+log_test() { echo -e "${CYAN}[TEST]${NC} $1"; }
+
+# shellcheck disable=SC2329 # invoked via trap
+cleanup() {
+ log_info "Cleaning up..."
+ for pid in "${PROXY_PID}" "${OWNCAST_PID}"; do
+ if [[ -n "${pid}" ]] && kill -0 "${pid}" 2>/dev/null; then
+ kill "${pid}" 2>/dev/null || true
+ wait "${pid}" 2>/dev/null || true
+ fi
+ done
+ [[ -n "${TEMP_DIR}" && -d "${TEMP_DIR}" ]] && rm -rf "${TEMP_DIR}"
+ log_info "Cleanup complete."
+}
+trap cleanup EXIT
+
+setup_temp_dir() {
+ TEMP_DIR=$(mktemp -d)
+ OWNCAST_DB="${TEMP_DIR}/owncast.db"
+ log_info "Temp directory: ${TEMP_DIR}"
+}
+
+check_certs() {
+ CERT_DIR="${CERT_DIR:-${SCRIPT_DIR}/certs}"
+ if [[ ! -f "${CERT_DIR}/cert.pem" || ! -f "${CERT_DIR}/key.pem" ]]; then
+ log_error "Certificates not found in ${CERT_DIR} (run inside the Docker harness, or see README.md)"
+ exit 1
+ fi
+ export CERT_FILE="${CERT_DIR}/cert.pem"
+ export KEY_FILE="${CERT_DIR}/key.pem"
+ log_info "Using certificates from ${CERT_DIR}"
+}
+
+build_owncast() {
+ log_info "Building Owncast..."
+ OWNCAST_BIN="${TEMP_DIR}/owncast"
+ (cd "$(git rev-parse --show-toplevel)" && CGO_ENABLED=1 go build -o "${OWNCAST_BIN}" main.go) ||
+ { log_error "Owncast build failed"; exit 1; }
+}
+
+start_owncast() {
+ log_info "Starting Owncast..."
+ OWNCAST_ALLOW_INTERNAL_FEDERATION=true \
+ OWNCAST_INSECURE_SKIP_VERIFY=true \
+ "${OWNCAST_BIN}" -database "${OWNCAST_DB}" >"${TEMP_DIR}/owncast.log" 2>&1 &
+ OWNCAST_PID=$!
+ for _ in $(seq 1 30); do
+ curl -s "http://localhost:${OWNCAST_PORT}/api/status" >/dev/null 2>&1 && { log_info "Owncast ready"; return 0; }
+ sleep 1
+ done
+ log_error "Owncast did not become ready"; return 1
+}
+
+configure_owncast() {
+ # IndieAuth requires the Owncast server URL to be set (it becomes the OAuth
+ # client_id and the redirect_uri base).
+ log_info "Configuring Owncast server URL (${OWNCAST_URL})..."
+ curl -s -X POST "http://localhost:${OWNCAST_PORT}/api/admin/config/serverurl" \
+ -u "${ADMIN_USER}:${ADMIN_PASS}" -H "Content-Type: application/json" \
+ -d "{\"value\": \"${OWNCAST_URL}\"}" >/dev/null
+ sleep 1
+}
+
+start_proxy() {
+ log_info "Starting Caddy (Owncast + fake IndieAuth provider)..."
+ export PROXY_PORT OWNCAST_PORT
+ caddy run --config "${SCRIPT_DIR}/Caddyfile.indieauth" --adapter caddyfile >"${TEMP_DIR}/caddy.log" 2>&1 &
+ PROXY_PID=$!
+ sleep 2
+ for _ in $(seq 1 10); do
+ curl -sk "https://127.0.0.1:${PROXY_PORT}/" >/dev/null 2>&1 && { log_info "Caddy ready"; return 0; }
+ sleep 1
+ done
+ log_error "Caddy did not become ready"; return 1
+}
+
+# ---- the actual test ----------------------------------------------------
+
+run_indieauth_test() {
+ local base="http://localhost:${OWNCAST_PORT}"
+
+ log_test "Sanity-check: the fake IndieAuth provider advertises its endpoint..."
+ if ! curl -sk "${INDIEAUTH_HOST}" | grep -q 'rel="authorization_endpoint"'; then
+ log_error "fake provider discovery document missing the authorization_endpoint link"
+ return 1
+ fi
+
+ log_test "Registering an anonymous chat user..."
+ local reg user_id token
+ reg=$(curl -s -X POST "${base}/api/chat/register")
+ user_id=$(echo "${reg}" | jq -r '.id')
+ token=$(echo "${reg}" | jq -r '.accessToken')
+ if [[ -z "${token}" || "${token}" == "null" ]]; then
+ log_error "chat register failed: ${reg}"; return 1
+ fi
+ log_info "user_id=${user_id}"
+
+ log_test "Starting the IndieAuth flow against ${INDIEAUTH_HOST}..."
+ local start_resp redirect
+ start_resp=$(curl -s -X POST "${base}/api/auth/indieauth?accessToken=${token}" \
+ -H "Content-Type: application/json" -d "{\"authHost\": \"${INDIEAUTH_HOST}\"}")
+ redirect=$(echo "${start_resp}" | jq -r '.redirect')
+ if [[ -z "${redirect}" || "${redirect}" == "null" ]]; then
+ log_error "StartAuthFlow returned no redirect: ${start_resp}"
+ log_error "owncast log tail:"; tail -20 "${TEMP_DIR}/owncast.log" 2>/dev/null
+ return 1
+ fi
+ log_info "authorization redirect: ${redirect}"
+
+ log_test "Following the authorization redirect through the fake provider and back to Owncast..."
+ # Like a browser: GET the provider's /auth (302 back to Owncast's callback
+ # with a code), then Owncast's callback exchanges the code with the provider
+ # and links the identity. -L follows the whole chain; -k because the browser
+ # leg hits the mkcert cert by IP/host.
+ local final_code
+ final_code=$(curl -Lsk -o /dev/null -w "%{http_code}" "${redirect}")
+ log_info "final response after callback chain: HTTP ${final_code}"
+
+ log_test "Asserting the admin users API reports the IndieAuth identity..."
+ local users
+ users=$(curl -s -u "${ADMIN_USER}:${ADMIN_PASS}" "${base}/api/admin/users?limit=200")
+ if echo "${users}" | jq -e --arg id "${user_id}" \
+ '.results[] | select(.id==$id) | (.authenticated==true and ((.authProviders // []) | index("IndieAuth")))' >/dev/null; then
+ log_test "${GREEN}PASS${NC}: user is authenticated and shown with the IndieAuth provider"
+ return 0
+ fi
+ log_error "user ${user_id} is not shown as IndieAuth-authenticated"
+ echo "${users}" | jq --arg id "${user_id}" '.results[] | select(.id==$id)' 2>/dev/null
+ log_error "owncast log tail:"; tail -20 "${TEMP_DIR}/owncast.log" 2>/dev/null
+ return 1
+}
+
+main() {
+ echo "=================================================="
+ echo " IndieAuth authentication — end-to-end test"
+ echo "=================================================="
+ setup_temp_dir
+ check_certs
+ build_owncast
+ start_proxy
+ start_owncast
+ configure_owncast
+
+ if run_indieauth_test; then
+ echo ""
+ log_test "${GREEN}IndieAuth auth test passed.${NC}"
+ exit 0
+ else
+ echo ""
+ log_error "IndieAuth auth test FAILED."
+ exit 1
+ fi
+}
+
+main "$@"
diff --git a/test/automated/auth/fake-oauth-server.mjs b/test/automated/auth/fake-oauth-server.mjs
new file mode 100644
index 0000000000..4d9bf4b2c6
--- /dev/null
+++ b/test/automated/auth/fake-oauth-server.mjs
@@ -0,0 +1,98 @@
+// Internal OAuth2 / OIDC provider for the OAuth auth-gate integration test.
+//
+// This is NOT a hand-rolled fake: it is node-oidc-provider, a certified,
+// production-grade OpenID Connect provider. It enforces real client
+// registration, redirect_uri matching, and client authentication, and issues
+// real RS256-signed tokens — so the test exercises the plugin's OAuth *client*
+// against a spec-compliant server, not a stub.
+//
+// The only test-shaped parts are the bits a hermetic test must control:
+// - a single pre-registered confidential client (the plugin),
+// - a fixed account, and
+// - a scripted interaction handler that auto-approves login + consent so no
+// human has to click through the (real) consent flow.
+//
+// Routes are mapped to the conventional /authorize, /token, /userinfo paths.
+import { createServer } from "node:http";
+import Provider from "oidc-provider";
+
+const PORT = Number(process.env.FAKE_OAUTH_PORT || 9876);
+const ISSUER = `http://localhost:${PORT}`;
+const CLIENT_ID = "owncast-oauth-test";
+const CLIENT_SECRET = "owncast-oauth-test-secret";
+const REDIRECT_URI = "http://localhost:8080/plugins/oauth-gate-test/callback";
+const ACCOUNT = "oauth-test-user";
+
+const configuration = {
+ clients: [
+ {
+ client_id: CLIENT_ID,
+ client_secret: CLIENT_SECRET,
+ grant_types: ["authorization_code"],
+ response_types: ["code"],
+ redirect_uris: [REDIRECT_URI],
+ token_endpoint_auth_method: "client_secret_post",
+ },
+ ],
+ pkce: { required: () => false },
+ routes: { authorization: "/authorize", token: "/token", userinfo: "/userinfo" },
+ features: { devInteractions: { enabled: false } },
+ claims: { openid: ["sub"], profile: ["name", "preferred_username"] },
+ cookies: { keys: ["oauth-gate-test-cookie-key"] },
+ findAccount: (_ctx, id) => ({
+ accountId: id,
+ claims: async () => ({
+ sub: id,
+ name: "OAuth Test User",
+ preferred_username: "oauthtester",
+ }),
+ }),
+};
+
+const provider = new Provider(ISSUER, configuration);
+const oidc = provider.callback();
+
+// Auto-complete the (real) interaction: log in the fixed account, then grant
+// the requested scopes. node-oidc-provider drives this as two prompts (login,
+// then consent); the cookie-following client walks both redirects.
+async function handleInteraction(req, res) {
+ const details = await provider.interactionDetails(req, res);
+ const { prompt, params, grantId } = details;
+
+ if (prompt.name === "login") {
+ return provider.interactionFinished(
+ req,
+ res,
+ { login: { accountId: ACCOUNT } },
+ { mergeWithLastSubmission: false },
+ );
+ }
+
+ const grant = grantId
+ ? await provider.Grant.find(grantId)
+ : new provider.Grant({ accountId: ACCOUNT, clientId: params.client_id });
+ if (params.scope) grant.addOIDCScope(params.scope);
+ const newGrantId = await grant.save();
+ return provider.interactionFinished(
+ req,
+ res,
+ { consent: { grantId: newGrantId } },
+ { mergeWithLastSubmission: true },
+ );
+}
+
+const server = createServer((req, res) => {
+ const url = new URL(req.url, ISSUER);
+ if (url.pathname.startsWith("/interaction/")) {
+ handleInteraction(req, res).catch((e) => {
+ res.statusCode = 500;
+ res.end(String(e));
+ });
+ return;
+ }
+ oidc(req, res);
+});
+
+server.listen(PORT, "localhost", () => {
+ console.log(`[fake-oauth] node-oidc-provider listening at ${ISSUER}`);
+});
diff --git a/test/automated/auth/oauth-gate-test/package.json b/test/automated/auth/oauth-gate-test/package.json
new file mode 100644
index 0000000000..6f7b6f6475
--- /dev/null
+++ b/test/automated/auth/oauth-gate-test/package.json
@@ -0,0 +1,12 @@
+{
+ "name": "oauth-gate-test",
+ "version": "0.1.0",
+ "private": true,
+ "scripts": {
+ "build": "owncast-plugin build",
+ "test": "owncast-plugin build && owncast-plugin test"
+ },
+ "dependencies": {
+ "@owncast/plugin-sdk": "file:../../../sdks/js"
+ }
+}
diff --git a/test/automated/auth/oauth-gate-test/plugin.manifest.json b/test/automated/auth/oauth-gate-test/plugin.manifest.json
new file mode 100644
index 0000000000..e3a465e85c
--- /dev/null
+++ b/test/automated/auth/oauth-gate-test/plugin.manifest.json
@@ -0,0 +1,17 @@
+{
+ "api": "1",
+ "name": "OAuth Gate Test",
+ "slug": "oauth-gate-test",
+ "version": "0.1.0",
+ "description": "Test-only viewer-auth gate that signs viewers in against an internal OAuth2/OIDC provider using the standard authorization-code flow. Used by the OAuth auth-plugin integration test; not for production.",
+ "permissions": [
+ "auth.gate",
+ "users.register",
+ "http.serve",
+ "network.fetch",
+ "storage.kv"
+ ],
+ "network": {
+ "allowedHosts": ["localhost", "127.0.0.1", "localhost:9876", "127.0.0.1:9876"]
+ }
+}
diff --git a/test/automated/auth/oauth-gate-test/src/plugin.js b/test/automated/auth/oauth-gate-test/src/plugin.js
new file mode 100644
index 0000000000..c2f22e3ce7
--- /dev/null
+++ b/test/automated/auth/oauth-gate-test/src/plugin.js
@@ -0,0 +1,123 @@
+// OAuth viewer-auth gate (test fixture).
+//
+// A standard OAuth2 authorization-code client served under
+// /plugins/oauth-gate-test/:
+//
+// GET / -> "sign in" screen linking to the provider's authorize URL
+// GET /callback -> the provider redirects back with ?code; we exchange it for
+// a token, fetch the userinfo, register the identity, and
+// grant the gate session
+// GET /logout -> clear the session
+//
+// Everything is hardcoded to the internal OAuth2 provider the test harness
+// starts (fake-oauth-server.mjs, a real node-oidc-provider instance on :9876).
+// The host owns the signed session cookie end to end via owncast.auth.
+const { definePlugin, owncast } = require('@owncast/plugin-sdk');
+
+const ISSUER = 'http://localhost:9876';
+const AUTHORIZE_URL = ISSUER + '/authorize';
+const TOKEN_URL = ISSUER + '/token';
+const USERINFO_URL = ISSUER + '/userinfo';
+const CLIENT_ID = 'owncast-oauth-test';
+const CLIENT_SECRET = 'owncast-oauth-test-secret';
+const REDIRECT_URI = 'http://localhost:8080/plugins/oauth-gate-test/callback';
+
+function formEncode(obj) {
+ return Object.keys(obj)
+ .map(function (k) {
+ return encodeURIComponent(k) + '=' + encodeURIComponent(obj[k]);
+ })
+ .join('&');
+}
+
+module.exports = definePlugin({
+ onHttpRequest(req) {
+ const query = req.query || {};
+
+ // Login screen: send the viewer to the OAuth provider's authorize endpoint.
+ if (req.method === 'GET' && req.path === '/') {
+ const returnTo = query.return_to || '/';
+ // A real plugin uses a random, per-request state; a fixed one keeps the
+ // test deterministic (a single serial login flow).
+ const state = 'oauth-test-state';
+ owncast.kv.set('oauth_state:' + state, returnTo);
+ const authorize =
+ AUTHORIZE_URL +
+ '?' +
+ formEncode({
+ response_type: 'code',
+ client_id: CLIENT_ID,
+ redirect_uri: REDIRECT_URI,
+ scope: 'openid profile',
+ state: state,
+ });
+ return {
+ status: 200,
+ headers: { 'content-type': 'text/html' },
+ body:
+ '<!doctype html><meta charset=utf-8><title>Sign in</title>' +
+ '<h1>This stream is private</h1>' +
+ '<a id="login" href="' +
+ authorize +
+ '">Sign in with OAuth</a>',
+ };
+ }
+
+ // OAuth callback: exchange the code, look up the user, grant a session.
+ if (req.method === 'GET' && req.path === '/callback') {
+ const code = query.code || '';
+ const state = query.state || '';
+
+ // CSRF: the state must match one we issued.
+ const returnTo = owncast.kv.get('oauth_state:' + state);
+ if (!returnTo) return { status: 400, body: 'invalid or expired state' };
+ owncast.kv.set('oauth_state:' + state, ''); // consume it
+
+ // Exchange the authorization code for an access token (client_secret_post).
+ const tokenResp = owncast.http.fetch(TOKEN_URL, {
+ method: 'POST',
+ headers: {
+ 'content-type': 'application/x-www-form-urlencoded',
+ accept: 'application/json',
+ },
+ body: formEncode({
+ grant_type: 'authorization_code',
+ code: code,
+ redirect_uri: REDIRECT_URI,
+ client_id: CLIENT_ID,
+ client_secret: CLIENT_SECRET,
+ }),
+ });
+ const accessToken = JSON.parse(tokenResp.body || '{}').access_token || '';
+ if (!accessToken) return { status: 502, body: 'token exchange failed' };
+
+ // Look up the authenticated user behind the token.
+ const userResp = owncast.http.fetch(USERINFO_URL, {
+ headers: {
+ authorization: 'Bearer ' + accessToken,
+ accept: 'application/json',
+ },
+ });
+ const profile = JSON.parse(userResp.body || '{}');
+ const authId = 'oauth:' + profile.sub;
+ const display = profile.name || profile.preferred_username || authId;
+
+ // Identity, then session. register() finds-or-creates the Owncast user for
+ // this OAuth identity (the host namespaces authId by our slug).
+ const { userId } = owncast.users.register({
+ authId: authId,
+ displayName: display,
+ });
+ owncast.auth.grantSession({ userId: userId });
+
+ return { status: 302, headers: { Location: returnTo || '/' } };
+ }
+
+ if (req.method === 'GET' && req.path === '/logout') {
+ owncast.auth.endSession();
+ return { status: 302, headers: { Location: '/' } };
+ }
+
+ return { status: 404, body: 'not found' };
+ },
+});
diff --git a/test/automated/auth/oauth-gate.test.js b/test/automated/auth/oauth-gate.test.js
new file mode 100644
index 0000000000..25c633afbf
--- /dev/null
+++ b/test/automated/auth/oauth-gate.test.js
@@ -0,0 +1,202 @@
+// End-to-end OAuth viewer-authentication gate test. Runs against a live Owncast
+// instance (started by run.sh) with the `oauth-gate-test` plugin installed and a
+// real OpenID Connect provider (node-oidc-provider, started by run.sh) on :9876.
+//
+// It proves that with the gate enabled: viewer resources are blocked until you
+// authenticate, the admin surface stays reachable throughout, completing the
+// real OAuth authorization-code flow issues a session that unlocks everything,
+// and the resulting identity is recorded on the user.
+var request = require('supertest');
+request = request('http://127.0.0.1:8080');
+
+const ADMIN = ['admin', 'abc123'];
+const SLUG = 'oauth-gate-test';
+const SESSION_COOKIE = 'owncast_session';
+const LOGIN_PREFIX = `/plugins/${SLUG}/`;
+const CALLBACK_PREFIX = `http://localhost:8080/plugins/${SLUG}/callback`;
+
+const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
+
+function sessionCookieFrom(res) {
+ const setCookie = res.headers['set-cookie'] || [];
+ const match = setCookie.find((c) => c.startsWith(`${SESSION_COOKIE}=`));
+ return match ? match.split(';')[0] : null;
+}
+
+// A cookie-aware redirect follower — the "browser" for the OAuth provider leg.
+// node-oidc-provider drives login + consent as a chain of redirects backed by
+// session cookies, so plain fetch (no cookie jar) can't complete it. We stop as
+// soon as the provider bounces back to the plugin's callback and let supertest
+// drive that final hop, so we can observe the Set-Cookie Owncast issues.
+async function followToCallback(startUrl) {
+ const jar = {};
+ let url = startUrl;
+ for (let i = 0; i < 25; i++) {
+ const cookie = Object.entries(jar)
+ .map(([k, v]) => `${k}=${v}`)
+ .join('; ');
+ const res = await fetch(url, {
+ redirect: 'manual',
+ headers: cookie ? { cookie } : {},
+ });
+ for (const c of res.headers.getSetCookie()) {
+ const pair = c.split(';')[0];
+ const idx = pair.indexOf('=');
+ const name = pair.slice(0, idx).trim();
+ const val = pair.slice(idx + 1).trim();
+ if (val === '') delete jar[name];
+ else jar[name] = val;
+ }
+ const loc = res.headers.get('location');
+ if (res.status >= 300 && res.status < 400 && loc) {
+ url = new URL(loc, url).toString();
+ if (url.startsWith(CALLBACK_PREFIX)) return url;
+ continue;
+ }
+ throw new Error(
+ `OAuth provider flow stopped unexpectedly: status=${res.status} url=${url}`,
+ );
+ }
+ throw new Error('OAuth provider flow exceeded redirect limit');
+}
+
+beforeAll(async () => {
+ await request
+ .post(`/api/admin/plugins/${SLUG}/enable`)
+ .auth(...ADMIN)
+ .expect(200);
+ await sleep(1500);
+});
+
+afterAll(async () => {
+ await request.post(`/api/admin/plugins/${SLUG}/disable`).auth(...ADMIN);
+});
+
+describe('before authenticating', () => {
+ test('a viewer API endpoint is blocked and redirected to the login screen', async () => {
+ const res = await request.get('/api/config').redirects(0).expect(302);
+ expect(res.headers.location).toContain(LOGIN_PREFIX);
+ });
+
+ test('the home page is blocked and redirected to the login screen', async () => {
+ const res = await request.get('/').redirects(0).expect(302);
+ expect(res.headers.location).toContain(LOGIN_PREFIX);
+ });
+
+ test('the HLS stream playlist is blocked', async () => {
+ const res = await request.get('/hls/stream.m3u8').redirects(0);
+ expect(res.status).toBe(302);
+ expect(res.headers.location).toContain(LOGIN_PREFIX);
+ });
+
+ test("the gate plugin's own login screen stays reachable (bootstrap)", async () => {
+ await request.get(LOGIN_PREFIX).redirects(0).expect(200);
+ });
+
+ test('the admin API stays reachable with admin credentials', async () => {
+ await request
+ .get('/api/admin/plugins')
+ .auth(...ADMIN)
+ .redirects(0)
+ .expect(200);
+ });
+
+ test('the admin web app stays reachable with admin credentials', async () => {
+ await request
+ .get('/admin/')
+ .auth(...ADMIN)
+ .redirects(0)
+ .expect(200);
+ });
+});
+
+describe('authenticating via the OAuth provider', () => {
+ let sessionCookie;
+
+ test('completing the real OAuth authorization-code flow issues a signed session', async () => {
+ // 1. The plugin's login screen links to the provider's authorize endpoint.
+ const login = await request.get(LOGIN_PREFIX).redirects(0).expect(200);
+ const m = login.text.match(/href="([^"]+\/authorize[^"]*)"/);
+ expect(m).toBeTruthy();
+ const authorizeUrl = m[1].replace(/&amp;/g, '&');
+
+ // 2. Drive the real provider: authorize -> (login + consent) -> redirect
+ // back to the plugin's callback with a real authorization code.
+ const callbackUrl = await followToCallback(authorizeUrl);
+ const cb = new URL(callbackUrl);
+ expect(cb.searchParams.get('code')).toBeTruthy();
+
+ // 3. Owncast's callback: the plugin exchanges the code for a token, fetches
+ // userinfo, registers the identity, and the host grants the session.
+ const res = await request
+ .get(cb.pathname + cb.search)
+ .redirects(0)
+ .expect(302);
+ sessionCookie = sessionCookieFrom(res);
+ expect(sessionCookie).toBeTruthy();
+ // The signed token is "<payload>.<sig>".
+ expect(sessionCookie.slice(SESSION_COOKIE.length + 1)).toContain('.');
+ });
+
+ test('the session cookie unlocks the viewer API', async () => {
+ await request
+ .get('/api/config')
+ .set('Cookie', sessionCookie)
+ .redirects(0)
+ .expect(200);
+ });
+
+ test('the session cookie unlocks the home page', async () => {
+ await request
+ .get('/')
+ .set('Cookie', sessionCookie)
+ .redirects(0)
+ .expect(200);
+ });
+
+ test('a tampered cookie is rejected and redirected to login', async () => {
+ const value = sessionCookie.slice(SESSION_COOKIE.length + 1);
+ const flipped = value.slice(0, -1) + (value.endsWith('A') ? 'B' : 'A');
+ const res = await request
+ .get('/api/config')
+ .set('Cookie', `${SESSION_COOKIE}=${flipped}`)
+ .redirects(0)
+ .expect(302);
+ expect(res.headers.location).toContain(LOGIN_PREFIX);
+ });
+
+ test('the OAuth identity is recorded on the user (admin users API)', async () => {
+ const res = await request
+ .get('/api/admin/users?limit=200')
+ .auth(...ADMIN)
+ .redirects(0)
+ .expect(200);
+ const match = res.body.results.filter(
+ (u) => (u.authProviders || []).includes(SLUG) && u.authenticated,
+ );
+ expect(match.length).toBeGreaterThanOrEqual(1);
+ });
+
+ test('logout clears the session cookie', async () => {
+ const res = await request
+ .get(`${LOGIN_PREFIX}logout`)
+ .set('Cookie', sessionCookie)
+ .redirects(0)
+ .expect(302);
+ const setCookie = res.headers['set-cookie'] || [];
+ const cleared = setCookie.find((c) => c.startsWith(`${SESSION_COOKIE}=`));
+ expect(cleared).toBeTruthy();
+ expect(cleared).toMatch(/owncast_session=;|Max-Age=0/i);
+ });
+});
+
+describe('after the gate is disabled', () => {
+ test('viewer endpoints are reachable again without a session', async () => {
+ await request
+ .post(`/api/admin/plugins/${SLUG}/disable`)
+ .auth(...ADMIN)
+ .expect(200);
+ await sleep(1000);
+ await request.get('/api/config').redirects(0).expect(200);
+ });
+});
diff --git a/test/automated/auth/package-lock.json b/test/automated/auth/package-lock.json
index 89ebdaa5b1..d8699ac48d 100644
--- a/test/automated/auth/package-lock.json
+++ b/test/automated/auth/package-lock.json
@@ -12,7 +12,8 @@
},
"devDependencies": {
"jest": "^29.7.0",
- "jest-jasmine2": "^29.7.0"
+ "jest-jasmine2": "^29.7.0",
+ "oidc-provider": "^9.0.0"
}
},
"node_modules/@babel/code-frame": {
@@ -880,6 +881,43 @@
"@jridgewell/sourcemap-codec": "^1.4.14"
}
},
+ "node_modules/@koa/cors": {
+ "version": "5.0.0",
+ "resolved": "https://registry.npmjs.org/@koa/cors/-/cors-5.0.0.tgz",
+ "integrity": "sha512-x/iUDjcS90W69PryLDIMgFyV21YLTnG9zOpPXS7Bkt2b8AsY3zZsIpOLBkYr9fBcF3HbkKaER5hOBZLfpLgYNw==",
+ "dev": true,
+ "license": "MIT",
+ "dependencies": {
+ "vary": "^1.1.2"
+ },
+ "engines": {
+ "node": ">= 14.0.0"
+ }
+ },
+ "node_modules/@koa/router": {
+ "version": "15.6.0",
+ "resolved": "https://registry.npmjs.org/@koa/router/-/router-15.6.0.tgz",
+ "integrity": "sha512-iEOXlvGIBqSNkGXrg0XtMARAOm5zA24oedXxiTGEkrD4JgwVjfRDddCQvW1s4WEcwDYvyecRbf8BikXsuEEj8w==",
+ "dev": true,
+ "license": "MIT",
+ "dependencies": {
+ "debug": "^4.4.3",
+ "http-errors": "^2.0.1",
+ "koa-compose": "^4.1.0",
+ "path-to-regexp": "^8.4.2"
+ },
+ "engines": {
+ "node": ">= 20"
+ },
+ "peerDependencies": {
+ "koa": "^2.0.0 || ^3.0.0"
+ },
+ "peerDependenciesMeta": {
+ "koa": {
+ "optional": false
+ }
+ }
+ },
"node_modules/@noble/hashes": {
"version": "1.8.0",
"resolved": "https://registry.npmjs.org/@noble/hashes/-/hashes-1.8.0.tgz",
@@ -1044,6 +1082,20 @@
"dev": true,
"license": "MIT"
},
+ "node_modules/accepts": {
+ "version": "1.3.8",
+ "resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.8.tgz",
+ "integrity": "sha512-PYAthTa2m2VKxuvSD3DPC/Gy+U+sOA1LAuT8mkmRuvw+NACSaeXEQ+NHcVF7rONl6qcaxV3Uuemwawk+7+SJLw==",
+ "dev": true,
+ "license": "MIT",
+ "dependencies": {
+ "mime-types": "~2.1.34",
+ "negotiator": "0.6.3"
+ },
+ "engines": {
+ "node": ">= 0.6"
+ }
+ },
"node_modules/ansi-escapes": {
"version": "4.3.2",
"resolved": "https://registry.npmjs.org/ansi-escapes/-/ansi-escapes-4.3.2.tgz",
@@ -1333,6 +1385,16 @@
"dev": true,
"license": "MIT"
},
+ "node_modules/bytes": {
+ "version": "3.1.2",
+ "resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.2.tgz",
+ "integrity": "sha512-/Nf7TyzTx6S3yRJObOAV7956r8cr2+Oj8AC5dt8wSP3BQAoeX58NoHyCU8P8zGkNXStjTSi6fzO6F0pBdcYbEg==",
+ "dev": true,
+ "license": "MIT",
+ "engines": {
+ "node": ">= 0.8"
+ }
+ },
"node_modules/call-bind-apply-helpers": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/call-bind-apply-helpers/-/call-bind-apply-helpers-1.0.2.tgz",
@@ -1534,6 +1596,30 @@
"dev": true,
"license": "MIT"
},
+ "node_modules/content-disposition": {
+ "version": "1.0.1",
+ "resolved": "https://registry.npmjs.org/content-disposition/-/content-disposition-1.0.1.tgz",
+ "integrity": "sha512-oIXISMynqSqm241k6kcQ5UwttDILMK4BiurCfGEREw6+X9jkkpEe5T9FZaApyLGGOnFuyMWZpdolTXMtvEJ08Q==",
+ "dev": true,
+ "license": "MIT",
+ "engines": {
+ "node": ">=18"
+ },
+ "funding": {
+ "type": "opencollective",
+ "url": "https://opencollective.com/express"
+ }
+ },
+ "node_modules/content-type": {
+ "version": "1.0.5",
+ "resolved": "https://registry.npmjs.org/content-type/-/content-type-1.0.5.tgz",
+ "integrity": "sha512-nTjqfcBFEipKdXCv4YDQWCfmcLZKm81ldF0pAopTvyrFGVbcR6P/VAAd5G7N+0tTr8QqiU0tFadD6FK4NtJwOA==",
+ "dev": true,
+ "license": "MIT",
+ "engines": {
+ "node": ">= 0.6"
+ }
+ },
"node_modules/convert-source-map": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/convert-source-map/-/convert-source-map-2.0.0.tgz",
@@ -1547,6 +1633,20 @@
"integrity": "sha512-LDx6oHrK+PhzLKJU9j5S7/Y3jM/mUHvD/DeI1WQmJn652iPC5Y4TBzC9l+5OMOXlyTTA+SmVUPm0HQUwpD5Jqw==",
"license": "MIT"
},
+ "node_modules/cookies": {
+ "version": "0.9.1",
+ "resolved": "https://registry.npmjs.org/cookies/-/cookies-0.9.1.tgz",
+ "integrity": "sha512-TG2hpqe4ELx54QER/S3HQ9SRVnQnGBtKUz5bLQWtYAQ+o6GpgMs6sYUvaiJjVxb+UXwhRhAEP3m7LbsIZ77Hmw==",
+ "dev": true,
+ "license": "MIT",
+ "dependencies": {
+ "depd": "~2.0.0",
+ "keygrip": "~1.1.0"
+ },
+ "engines": {
+ "node": ">= 0.8"
+ }
+ },
"node_modules/create-jest": {
"version": "29.7.0",
"resolved": "https://registry.npmjs.org/create-jest/-/create-jest-29.7.0.tgz",
@@ -1616,6 +1716,13 @@
}
}
},
+ "node_modules/deep-equal": {
+ "version": "1.0.1",
+ "resolved": "https://registry.npmjs.org/deep-equal/-/deep-equal-1.0.1.tgz",
+ "integrity": "sha512-bHtC0iYvWhyaTzvV3CZgPeZQqCOBGyGsVV7v4eevpdkLHfiSrXUdBG+qAuSz4RI70sszvjQ1QSZ98An1yNwpSw==",
+ "dev": true,
+ "license": "MIT"
+ },
"node_modules/deepmerge": {
"version": "4.3.1",
"resolved": "https://registry.npmjs.org/deepmerge/-/deepmerge-4.3.1.tgz",
@@ -1635,6 +1742,34 @@
"node": ">=0.4.0"
}
},
+ "node_modules/delegates": {
+ "version": "1.0.0",
+ "resolved": "https://registry.npmjs.org/delegates/-/delegates-1.0.0.tgz",
+ "integrity": "sha512-bd2L678uiWATM6m5Z1VzNCErI3jiGzt6HGY8OVICs40JQq/HALfbyNJmp0UDakEY4pMMaN0Ly5om/B1VI/+xfQ==",
+ "dev": true,
+ "license": "MIT"
+ },
+ "node_modules/depd": {
+ "version": "2.0.0",
+ "resolved": "https://registry.npmjs.org/depd/-/depd-2.0.0.tgz",
+ "integrity": "sha512-g7nH6P6dyDioJogAAGprGpCtVImJhpPk/roCzdb3fIh61/s/nPsfR6onyMwkCAR/OlC3yBC0lESvUoQEAssIrw==",
+ "dev": true,
+ "license": "MIT",
+ "engines": {
+ "node": ">= 0.8"
+ }
+ },
+ "node_modules/destroy": {
+ "version": "1.2.0",
+ "resolved": "https://registry.npmjs.org/destroy/-/destroy-1.2.0.tgz",
+ "integrity": "sha512-2sJGJTaXIIaR1w4iJSNoN0hnMY7Gpc/n8D4qSCJw8QqFWXf7cuAgnEHxBpweaVcPevC2l3KpjYCx3NypQQgaJg==",
+ "dev": true,
+ "license": "MIT",
+ "engines": {
+ "node": ">= 0.8",
+ "npm": "1.2.8000 || >= 1.4.16"
+ }
+ },
"node_modules/detect-newline": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/detect-newline/-/detect-newline-3.1.0.tgz",
@@ -1679,6 +1814,13 @@
"node": ">= 0.4"
}
},
+ "node_modules/ee-first": {
+ "version": "1.1.1",
+ "resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz",
+ "integrity": "sha512-WMwm9LhRUo+WUaRN+vRuETqG89IgZphVSNkdFgeb6sS/E4OrDIN7t48CAewSHXc6C8lefD8KKfr5vY61brQlow==",
+ "dev": true,
+ "license": "MIT"
+ },
"node_modules/electron-to-chromium": {
"version": "1.5.376",
"resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.5.376.tgz",
@@ -1706,6 +1848,16 @@
"dev": true,
"license": "MIT"
},
+ "node_modules/encodeurl": {
+ "version": "2.0.0",
+ "resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-2.0.0.tgz",
+ "integrity": "sha512-Q0n9HRi4m6JuGIV1eFlmvJB7ZEVxu93IrMyiMsGC0lrMJMWzRgx6WGquyfQgZVb31vhGgXnfmPNNXmxnOkRBrg==",
+ "dev": true,
+ "license": "MIT",
+ "engines": {
+ "node": ">= 0.8"
+ }
+ },
"node_modules/error-ex": {
"version": "1.3.4",
"resolved": "https://registry.npmjs.org/error-ex/-/error-ex-1.3.4.tgz",
@@ -1771,6 +1923,13 @@
"node": ">=6"
}
},
+ "node_modules/escape-html": {
+ "version": "1.0.3",
+ "resolved": "https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz",
+ "integrity": "sha512-NiSupZ4OeuGwr68lGIeym/ksIZMJodUGOSCZ/FSnTxcrekbvqrgdUxlJOMpijaKZVjAJrWrGs/6Jy8OMuyj9ow==",
+ "dev": true,
+ "license": "MIT"
+ },
"node_modules/escape-string-regexp": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-2.0.0.tgz",
@@ -1795,6 +1954,19 @@
"node": ">=4"
}
},
+ "node_modules/eta": {
+ "version": "4.6.0",
+ "resolved": "https://registry.npmjs.org/eta/-/eta-4.6.0.tgz",
+ "integrity": "sha512-lW6is4T1NFOYnmqGZIfvixqj7A7sSvScF+DN8EK6K58xI5MZ5UvYe0GjopxOXQtZvUn4eDdVuZ8XSoYWTMEKwA==",
+ "dev": true,
+ "license": "MIT",
+ "engines": {
+ "node": ">=20"
+ },
+ "funding": {
+ "url": "https://github.com/bgub/eta?sponsor=1"
+ }
+ },
"node_modules/execa": {
"version": "5.1.1",
"resolved": "https://registry.npmjs.org/execa/-/execa-5.1.1.tgz",
@@ -1926,6 +2098,16 @@
"url": "https://ko-fi.com/tunnckoCore/commissions"
}
},
+ "node_modules/fresh": {
+ "version": "0.5.2",
+ "resolved": "https://registry.npmjs.org/fresh/-/fresh-0.5.2.tgz",
+ "integrity": "sha512-zJ2mQYM18rEFOudeV4GShTGIQ7RbzA7ozbU9I/XBpm7kqgMywgmylMwXHxZJmkVoYkna9d2pVXVXPdYTP9ej8Q==",
+ "dev": true,
+ "license": "MIT",
+ "engines": {
+ "node": ">= 0.6"
+ }
+ },
"node_modules/fs.realpath": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz",
@@ -2134,6 +2316,78 @@
"dev": true,
"license": "MIT"
},
+ "node_modules/http-assert": {
+ "version": "1.5.0",
+ "resolved": "https://registry.npmjs.org/http-assert/-/http-assert-1.5.0.tgz",
+ "integrity": "sha512-uPpH7OKX4H25hBmU6G1jWNaqJGpTXxey+YOUizJUAgu0AjLUeC8D73hTrhvDS5D+GJN1DN1+hhc/eF/wpxtp0w==",
+ "dev": true,
+ "license": "MIT",
+ "dependencies": {
+ "deep-equal": "~1.0.1",
+ "http-errors": "~1.8.0"
+ },
+ "engines": {
+ "node": ">= 0.8"
+ }
+ },
+ "node_modules/http-assert/node_modules/depd": {
+ "version": "1.1.2",
+ "resolved": "https://registry.npmjs.org/depd/-/depd-1.1.2.tgz",
+ "integrity": "sha512-7emPTl6Dpo6JRXOXjLRxck+FlLRX5847cLKEn00PLAgc3g2hTZZgr+e4c2v6QpSmLeFP3n5yUo7ft6avBK/5jQ==",
+ "dev": true,
+ "license": "MIT",
+ "engines": {
+ "node": ">= 0.6"
+ }
+ },
+ "node_modules/http-assert/node_modules/http-errors": {
+ "version": "1.8.1",
+ "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-1.8.1.tgz",
+ "integrity": "sha512-Kpk9Sm7NmI+RHhnj6OIWDI1d6fIoFAtFt9RLaTMRlg/8w49juAStsrBgp0Dp4OdxdVbRIeKhtCUvoi/RuAhO4g==",
+ "dev": true,
+ "license": "MIT",
+ "dependencies": {
+ "depd": "~1.1.2",
+ "inherits": "2.0.4",
+ "setprototypeof": "1.2.0",
+ "statuses": ">= 1.5.0 < 2",
+ "toidentifier": "1.0.1"
+ },
+ "engines": {
+ "node": ">= 0.6"
+ }
+ },
+ "node_modules/http-assert/node_modules/statuses": {
+ "version": "1.5.0",
+ "resolved": "https://registry.npmjs.org/statuses/-/statuses-1.5.0.tgz",
+ "integrity": "sha512-OpZ3zP+jT1PI7I8nemJX4AKmAX070ZkYPVWV/AaKTJl+tXCTGyVdC1a4SL8RUQYEwk/f34ZX8UTykN68FwrqAA==",
+ "dev": true,
+ "license": "MIT",
+ "engines": {
+ "node": ">= 0.6"
+ }
+ },
+ "node_modules/http-errors": {
+ "version": "2.0.1",
+ "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-2.0.1.tgz",
+ "integrity": "sha512-4FbRdAX+bSdmo4AUFuS0WNiPz8NgFt+r8ThgNWmlrjQjt1Q7ZR9+zTlce2859x4KSXrwIsaeTqDoKQmtP8pLmQ==",
+ "dev": true,
+ "license": "MIT",
+ "dependencies": {
+ "depd": "~2.0.0",
+ "inherits": "~2.0.4",
+ "setprototypeof": "~1.2.0",
+ "statuses": "~2.0.2",
+ "toidentifier": "~1.0.1"
+ },
+ "engines": {
+ "node": ">= 0.8"
+ },
+ "funding": {
+ "type": "opencollective",
+ "url": "https://opencollective.com/express"
+ }
+ },
"node_modules/human-signals": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/human-signals/-/human-signals-2.1.0.tgz",
@@ -2144,6 +2398,23 @@
"node": ">=10.17.0"
}
},
+ "node_modules/iconv-lite": {
+ "version": "0.7.2",
+ "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.7.2.tgz",
+ "integrity": "sha512-im9DjEDQ55s9fL4EYzOAv0yMqmMBSZp6G0VvFyTMPKWxiSBHUj9NW/qqLmXUwXrrM7AvqSlTCfvqRb0cM8yYqw==",
+ "dev": true,
+ "license": "MIT",
+ "dependencies": {
+ "safer-buffer": ">= 2.1.2 < 3.0.0"
+ },
+ "engines": {
+ "node": ">=0.10.0"
+ },
+ "funding": {
+ "type": "opencollective",
+ "url": "https://opencollective.com/express"
+ }
+ },
"node_modules/import-local": {
"version": "3.2.0",
"resolved": "https://registry.npmjs.org/import-local/-/import-local-3.2.0.tgz",
@@ -2975,6 +3246,16 @@
"url": "https://github.com/chalk/supports-color?sponsor=1"
}
},
+ "node_modules/jose": {
+ "version": "6.2.3",
+ "resolved": "https://registry.npmjs.org/jose/-/jose-6.2.3.tgz",
+ "integrity": "sha512-YYVDInQKFJfR/xa3ojUTl8c2KoTwiL1R5Wg9YCydwH0x0B9grbzlg5HC7mMjCtUJjbQ/YnGEZIhI5tCgfTb4Hw==",
+ "dev": true,
+ "license": "MIT",
+ "funding": {
+ "url": "https://github.com/sponsors/panva"
+ }
+ },
"node_modules/js-tokens": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz",
@@ -3029,6 +3310,19 @@
"node": ">=6"
}
},
+ "node_modules/keygrip": {
+ "version": "1.1.0",
+ "resolved": "https://registry.npmjs.org/keygrip/-/keygrip-1.1.0.tgz",
+ "integrity": "sha512-iYSchDJ+liQ8iwbSI2QqsQOvqv58eJCEanyJPJi+Khyu8smkcKSFUCbPwzFcL7YVtZ6eONjqRX/38caJ7QjRAQ==",
+ "dev": true,
+ "license": "MIT",
+ "dependencies": {
+ "tsscmp": "1.0.6"
+ },
+ "engines": {
+ "node": ">= 0.6"
+ }
+ },
"node_modules/kleur": {
"version": "3.0.3",
"resolved": "https://registry.npmjs.org/kleur/-/kleur-3.0.3.tgz",
@@ -3039,6 +3333,70 @@
"node": ">=6"
}
},
+ "node_modules/koa": {
+ "version": "3.2.1",
+ "resolved": "https://registry.npmjs.org/koa/-/koa-3.2.1.tgz",
+ "integrity": "sha512-e7IpWJrnanNUroVK2taAgMxoEZvHLXdQiNjeExSu/DEIWm83jaKGBgb7tLmu2rMYpA027qFB3iLR/k3AVpFRnA==",
+ "dev": true,
+ "license": "MIT",
+ "dependencies": {
+ "accepts": "^1.3.8",
+ "content-disposition": "~1.0.1",
+ "content-type": "^1.0.5",
+ "cookies": "~0.9.1",
+ "delegates": "^1.0.0",
+ "destroy": "^1.2.0",
+ "encodeurl": "^2.0.0",
+ "escape-html": "^1.0.3",
+ "fresh": "~0.5.2",
+ "http-assert": "^1.5.0",
+ "http-errors": "^2.0.0",
+ "koa-compose": "^4.1.0",
+ "mime-types": "^3.0.1",
+ "on-finished": "^2.4.1",
+ "parseurl": "^1.3.3",
+ "statuses": "^2.0.1",
+ "type-is": "^2.0.1",
+ "vary": "^1.1.2"
+ },
+ "engines": {
+ "node": ">= 18"
+ }
+ },
+ "node_modules/koa-compose": {
+ "version": "4.1.0",
+ "resolved": "https://registry.npmjs.org/koa-compose/-/koa-compose-4.1.0.tgz",
+ "integrity": "sha512-8ODW8TrDuMYvXRwra/Kh7/rJo9BtOfPc6qO8eAfC80CnCvSjSl0bkRM24X6/XBBEyj0v1nRUQ1LyOy3dbqOWXw==",
+ "dev": true,
+ "license": "MIT"
+ },
+ "node_modules/koa/node_modules/mime-db": {
+ "version": "1.54.0",
+ "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.54.0.tgz",
+ "integrity": "sha512-aU5EJuIN2WDemCcAp2vFBfp/m4EAhWJnUNSSw0ixs7/kXbd6Pg64EmwJkNdFhB8aWt1sH2CTXrLxo/iAGV3oPQ==",
+ "dev": true,
+ "license": "MIT",
+ "engines": {
+ "node": ">= 0.6"
+ }
+ },
+ "node_modules/koa/node_modules/mime-types": {
+ "version": "3.0.2",
+ "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-3.0.2.tgz",
+ "integrity": "sha512-Lbgzdk0h4juoQ9fCKXW4by0UJqj+nOOrI9MJ1sSj4nI8aI2eo1qmvQEie4VD1glsS250n15LsWsYtCugiStS5A==",
+ "dev": true,
+ "license": "MIT",
+ "dependencies": {
+ "mime-db": "^1.54.0"
+ },
+ "engines": {
+ "node": ">=18"
+ },
+ "funding": {
+ "type": "opencollective",
+ "url": "https://opencollective.com/express"
+ }
+ },
"node_modules/leven": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/leven/-/leven-3.1.0.tgz",
@@ -3127,6 +3485,16 @@
"node": ">= 0.4"
}
},
+ "node_modules/media-typer": {
+ "version": "1.1.0",
+ "resolved": "https://registry.npmjs.org/media-typer/-/media-typer-1.1.0.tgz",
+ "integrity": "sha512-aisnrDP4GNe06UcKFnV5bfMNPBUw4jsLGaWwWfnH3v02GnBuXX2MCVn5RbrWo0j3pczUilYblq7fQ7Nw2t5XKw==",
+ "dev": true,
+ "license": "MIT",
+ "engines": {
+ "node": ">= 0.8"
+ }
+ },
"node_modules/merge-stream": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/merge-stream/-/merge-stream-2.0.0.tgz",
@@ -3219,6 +3587,25 @@
"integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==",
"license": "MIT"
},
+ "node_modules/nanoid": {
+ "version": "5.1.15",
+ "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-5.1.15.tgz",
+ "integrity": "sha512-kBg3RpGtIe+RpTbyXwoI6pk5yD7KUiI3sygUqgeBMRst42KmhB4RZC7eiO9Wa1HIpaCCtpE2DJ6OI4Wi5ebwFw==",
+ "dev": true,
+ "funding": [
+ {
+ "type": "github",
+ "url": "https://github.com/sponsors/ai"
+ }
+ ],
+ "license": "MIT",
+ "bin": {
+ "nanoid": "bin/nanoid.js"
+ },
+ "engines": {
+ "node": "^18 || >=20"
+ }
+ },
"node_modules/natural-compare": {
"version": "1.4.0",
"resolved": "https://registry.npmjs.org/natural-compare/-/natural-compare-1.4.0.tgz",
@@ -3226,6 +3613,16 @@
"dev": true,
"license": "MIT"
},
+ "node_modules/negotiator": {
+ "version": "0.6.3",
+ "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.3.tgz",
+ "integrity": "sha512-+EUsqGPLsM+j/zdChZjsnX51g4XrHFOIXwfnCVPGlQk/k5giakcKsuxCObBRu6DSm9opw/O6slWbJdghQM4bBg==",
+ "dev": true,
+ "license": "MIT",
+ "engines": {
+ "node": ">= 0.6"
+ }
+ },
"node_modules/node-int64": {
"version": "0.4.0",
"resolved": "https://registry.npmjs.org/node-int64/-/node-int64-0.4.0.tgz",
@@ -3278,6 +3675,41 @@
"url": "https://github.com/sponsors/ljharb"
}
},
+ "node_modules/oidc-provider": {
+ "version": "9.8.5",
+ "resolved": "https://registry.npmjs.org/oidc-provider/-/oidc-provider-9.8.5.tgz",
+ "integrity": "sha512-07Wqkea8jdfPI8GvbVwf9rMNNitLUzzDqPua7hWbqZreFNpfnlNVdqmllaripVmgDZS2tHHLYQYLW0Ay7yux9w==",
+ "dev": true,
+ "license": "MIT",
+ "dependencies": {
+ "@koa/cors": "^5.0.0",
+ "@koa/router": "^15.5.0",
+ "debug": "^4.4.3",
+ "eta": "^4.6.0",
+ "jose": "^6.2.3",
+ "jsesc": "^3.1.0",
+ "koa": "^3.2.1",
+ "nanoid": "^5.1.11",
+ "quick-lru": "^7.3.0",
+ "raw-body": "^3.0.2"
+ },
+ "funding": {
+ "url": "https://github.com/sponsors/panva"
+ }
+ },
+ "node_modules/on-finished": {
+ "version": "2.4.1",
+ "resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.4.1.tgz",
+ "integrity": "sha512-oVlzkg3ENAhCk2zdv7IJwd/QUD4z2RxRwpkcGY8psCVcCYZNq4wYnVWALHM+brtuJjePWiYF/ClmuDr8Ch5+kg==",
+ "dev": true,
+ "license": "MIT",
+ "dependencies": {
+ "ee-first": "1.1.1"
+ },
+ "engines": {
+ "node": ">= 0.8"
+ }
+ },
"node_modules/once": {
"version": "1.4.0",
"resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz",
@@ -3377,6 +3809,16 @@
"url": "https://github.com/sponsors/sindresorhus"
}
},
+ "node_modules/parseurl": {
+ "version": "1.3.3",
+ "resolved": "https://registry.npmjs.org/parseurl/-/parseurl-1.3.3.tgz",
+ "integrity": "sha512-CiyeOxFT/JZyN5m0z9PfXw4SCBJ6Sygz1Dpl0wqjlhDEGGBP1GnsUVEL0p63hoG1fcj3fHynXi9NYO4nWOL+qQ==",
+ "dev": true,
+ "license": "MIT",
+ "engines": {
+ "node": ">= 0.8"
+ }
+ },
"node_modules/path-exists": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/path-exists/-/path-exists-4.0.0.tgz",
@@ -3414,6 +3856,17 @@
"dev": true,
"license": "MIT"
},
+ "node_modules/path-to-regexp": {
+ "version": "8.4.2",
+ "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-8.4.2.tgz",
+ "integrity": "sha512-qRcuIdP69NPm4qbACK+aDogI5CBDMi1jKe0ry5rSQJz8JVLsC7jV8XpiJjGRLLol3N+R5ihGYcrPLTno6pAdBA==",
+ "dev": true,
+ "license": "MIT",
+ "funding": {
+ "type": "opencollective",
+ "url": "https://opencollective.com/express"
+ }
+ },
"node_modules/picocolors": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.1.1.tgz",
@@ -3531,6 +3984,35 @@
"url": "https://github.com/sponsors/ljharb"
}
},
+ "node_modules/quick-lru": {
+ "version": "7.3.0",
+ "resolved": "https://registry.npmjs.org/quick-lru/-/quick-lru-7.3.0.tgz",
+ "integrity": "sha512-k9lSsjl36EJdK7I06v7APZCbyGT2vMTsYSRX1Q2nbYmnkBqgUhRkAuzH08Ciotteu/PLJmIF2+tti7o3C/ts2g==",
+ "dev": true,
+ "license": "MIT",
+ "engines": {
+ "node": ">=18"
+ },
+ "funding": {
+ "url": "https://github.com/sponsors/sindresorhus"
+ }
+ },
+ "node_modules/raw-body": {
+ "version": "3.0.2",
+ "resolved": "https://registry.npmjs.org/raw-body/-/raw-body-3.0.2.tgz",
+ "integrity": "sha512-K5zQjDllxWkf7Z5xJdV0/B0WTNqx6vxG70zJE4N0kBs4LovmEYWJzQGxC9bS9RAKu3bgM40lrd5zoLJ12MQ5BA==",
+ "dev": true,
+ "license": "MIT",
+ "dependencies": {
+ "bytes": "~3.1.2",
+ "http-errors": "~2.0.1",
+ "iconv-lite": "~0.7.0",
+ "unpipe": "~1.0.0"
+ },
+ "engines": {
+ "node": ">= 0.10"
+ }
+ },
"node_modules/react-is": {
"version": "18.3.1",
"resolved": "https://registry.npmjs.org/react-is/-/react-is-18.3.1.tgz",
@@ -3603,6 +4085,13 @@
"node": ">=10"
}
},
+ "node_modules/safer-buffer": {
+ "version": "2.1.2",
+ "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz",
+ "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==",
+ "dev": true,
+ "license": "MIT"
+ },
"node_modules/semver": {
"version": "6.3.1",
"resolved": "https://registry.npmjs.org/semver/-/semver-6.3.1.tgz",
@@ -3613,6 +4102,13 @@
"semver": "bin/semver.js"
}
},
+ "node_modules/setprototypeof": {
+ "version": "1.2.0",
+ "resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.2.0.tgz",
+ "integrity": "sha512-E5LDX7Wrp85Kil5bhZv46j8jOeboKq5JMmYM3gVGdGH8xFpPWXUMsNrlODCrkoxMEeNi/XZIwuRvY4XNwYMJpw==",
+ "dev": true,
+ "license": "ISC"
+ },
"node_modules/shebang-command": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-2.0.0.tgz",
@@ -3773,6 +4269,16 @@
"node": ">=10"
}
},
+ "node_modules/statuses": {
+ "version": "2.0.2",
+ "resolved": "https://registry.npmjs.org/statuses/-/statuses-2.0.2.tgz",
+ "integrity": "sha512-DvEy55V3DB7uknRo+4iOGT5fP1slR8wQohVdknigZPMpMstaKJQWhwiYBACJE3Ul2pTnATihhBYnRhZQHGBiRw==",
+ "dev": true,
+ "license": "MIT",
+ "engines": {
+ "node": ">= 0.8"
+ }
+ },
"node_modules/string-length": {
"version": "4.0.2",
"resolved": "https://registry.npmjs.org/string-length/-/string-length-4.0.2.tgz",
@@ -3957,6 +4463,26 @@
"node": ">=8.0"
}
},
+ "node_modules/toidentifier": {
+ "version": "1.0.1",
+ "resolved": "https://registry.npmjs.org/toidentifier/-/toidentifier-1.0.1.tgz",
+ "integrity": "sha512-o5sSPKEkg/DIQNmH43V0/uerLrpzVedkUh8tGNvaeXpfpuwjKenlSox/2O/BTlZUtEe+JG7s5YhEz608PlAHRA==",
+ "dev": true,
+ "license": "MIT",
+ "engines": {
+ "node": ">=0.6"
+ }
+ },
+ "node_modules/tsscmp": {
+ "version": "1.0.6",
+ "resolved": "https://registry.npmjs.org/tsscmp/-/tsscmp-1.0.6.tgz",
+ "integrity": "sha512-LxhtAkPDTkVCMQjt2h6eBVY28KCjikZqZfMcC15YBeNjkgUpdCfBu5HoiOTDu86v6smE8yOjyEktJ8hlbANHQA==",
+ "dev": true,
+ "license": "MIT",
+ "engines": {
+ "node": ">=0.6.x"
+ }
+ },
"node_modules/type-detect": {
"version": "4.0.8",
"resolved": "https://registry.npmjs.org/type-detect/-/type-detect-4.0.8.tgz",
@@ -3980,6 +4506,66 @@
"url": "https://github.com/sponsors/sindresorhus"
}
},
+ "node_modules/type-is": {
+ "version": "2.1.0",
+ "resolved": "https://registry.npmjs.org/type-is/-/type-is-2.1.0.tgz",
+ "integrity": "sha512-faYHw0anBbc/kWF3zFTEnxSFOAGUX9GFbOBthvDdLsIlEoWOFOtS0zgCiQYwIskL9iGXZL3kAXD8OoZ4GmMATA==",
+ "dev": true,
+ "license": "MIT",
+ "dependencies": {
+ "content-type": "^2.0.0",
+ "media-typer": "^1.1.0",
+ "mime-types": "^3.0.0"
+ },
+ "engines": {
+ "node": ">= 18"
+ },
+ "funding": {
+ "type": "opencollective",
+ "url": "https://opencollective.com/express"
+ }
+ },
+ "node_modules/type-is/node_modules/content-type": {
+ "version": "2.0.0",
+ "resolved": "https://registry.npmjs.org/content-type/-/content-type-2.0.0.tgz",
+ "integrity": "sha512-j/O/d7GcZCyNl7/hwZAb606rzqkyvaDctLmckbxLzHvFBzTJHuGEdodATcP3yIRoDrLHkIATJuvzbFlp/ki2cQ==",
+ "dev": true,
+ "license": "MIT",
+ "engines": {
+ "node": ">=18"
+ },
+ "funding": {
+ "type": "opencollective",
+ "url": "https://opencollective.com/express"
+ }
+ },
+ "node_modules/type-is/node_modules/mime-db": {
+ "version": "1.54.0",
+ "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.54.0.tgz",
+ "integrity": "sha512-aU5EJuIN2WDemCcAp2vFBfp/m4EAhWJnUNSSw0ixs7/kXbd6Pg64EmwJkNdFhB8aWt1sH2CTXrLxo/iAGV3oPQ==",
+ "dev": true,
+ "license": "MIT",
+ "engines": {
+ "node": ">= 0.6"
+ }
+ },
+ "node_modules/type-is/node_modules/mime-types": {
+ "version": "3.0.2",
+ "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-3.0.2.tgz",
+ "integrity": "sha512-Lbgzdk0h4juoQ9fCKXW4by0UJqj+nOOrI9MJ1sSj4nI8aI2eo1qmvQEie4VD1glsS250n15LsWsYtCugiStS5A==",
+ "dev": true,
+ "license": "MIT",
+ "dependencies": {
+ "mime-db": "^1.54.0"
+ },
+ "engines": {
+ "node": ">=18"
+ },
+ "funding": {
+ "type": "opencollective",
+ "url": "https://opencollective.com/express"
+ }
+ },
"node_modules/undici-types": {
"version": "8.3.0",
"resolved": "https://registry.npmjs.org/undici-types/-/undici-types-8.3.0.tgz",
@@ -3987,6 +4573,16 @@
"dev": true,
"license": "MIT"
},
+ "node_modules/unpipe": {
+ "version": "1.0.0",
+ "resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz",
+ "integrity": "sha512-pjy2bYhSsufwWlKwPc+l3cN7+wuJlK6uz0YdJEOlQDbl6jo/YlPi4mb8agUkVC8BF7V8NuzeyPNqRksA3hztKQ==",
+ "dev": true,
+ "license": "MIT",
+ "engines": {
+ "node": ">= 0.8"
+ }
+ },
"node_modules/update-browserslist-db": {
"version": "1.2.3",
"resolved": "https://registry.npmjs.org/update-browserslist-db/-/update-browserslist-db-1.2.3.tgz",
@@ -4033,6 +4629,16 @@
"node": ">=10.12.0"
}
},
+ "node_modules/vary": {
+ "version": "1.1.2",
+ "resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz",
+ "integrity": "sha512-BNGbWLfd0eUPabhkXUVm0j8uuvREyTh5ovRa/dyow/BqAbZJyC+5fU+IzQOzmAKzYqYRAISoRhdQr3eIZ/PXqg==",
+ "dev": true,
+ "license": "MIT",
+ "engines": {
+ "node": ">= 0.8"
+ }
+ },
"node_modules/walker": {
"version": "1.0.8",
"resolved": "https://registry.npmjs.org/walker/-/walker-1.0.8.tgz",
diff --git a/test/automated/auth/package.json b/test/automated/auth/package.json
index b584c2984b..6f3d66c2bb 100644
--- a/test/automated/auth/package.json
+++ b/test/automated/auth/package.json
@@ -9,7 +9,8 @@
},
"devDependencies": {
"jest": "^29.7.0",
- "jest-jasmine2": "^29.7.0"
+ "jest-jasmine2": "^29.7.0",
+ "oidc-provider": "^9.0.0"
},
"jest": {
"verbose": true,
diff --git a/test/automated/auth/run.sh b/test/automated/auth/run.sh
index 0d10d11aae..3adce5028f 100755
--- a/test/automated/auth/run.sh
+++ b/test/automated/auth/run.sh
@@ -1,14 +1,18 @@
#!/bin/bash
-# Standalone end-to-end viewer-authentication ("auth gate") integration test.
+# Standalone end-to-end viewer-authentication ("auth gate") integration tests.
#
-# Builds the SDK's `basic-auth` example (a shared-password auth.gate plugin),
-# installs it into a real Owncast instance, then verifies via HTTP that:
-# - viewer endpoints are blocked (302 to the login screen) before auth,
-# - the admin API and the gate plugin's own routes stay reachable,
-# - a correct password issues a signed `owncast_session` cookie,
-# - that cookie unlocks the gated endpoints, and a tampered one does not,
-# - logout clears the cookie.
+# Builds two auth.gate plugins and installs them into a real Owncast instance:
+# - the SDK's `basic-auth` example (a shared-password gate), and
+# - `oauth-gate-test` (this repo's fixture: a standard OAuth2 client built
+# from scratch against the SDK), which authenticates against a real,
+# certified OpenID Connect provider (node-oidc-provider) started below.
+#
+# The suites verify, for each gate, that viewer endpoints are blocked (302 to
+# the login screen) before auth while the admin surface and the gate plugin's
+# own routes stay reachable, that authenticating issues a signed
+# `owncast_session` cookie that unlocks the gated endpoints (and a tampered one
+# does not), and that logout clears the cookie.
#
# Env overrides (same contract as test/automated/plugins/run.sh):
# PLUGIN_SDK_DIR path to an existing SDK checkout (skips the clone)
@@ -17,6 +21,7 @@
set -e
+# shellcheck disable=SC1091 # tools.sh is sourced at runtime; not available to the linter
source ../tools.sh
REPO_ROOT="$(git rev-parse --show-toplevel)"
@@ -25,7 +30,9 @@ PLUGIN_SDK_REPO="${PLUGIN_SDK_REPO:-https://github.com/owncast/plugin-sdk}"
PLUGIN_SDK_REF="${PLUGIN_SDK_REF:-main}"
PLUGIN_NAME="basic-auth"
+OAUTH_PLUGIN_NAME="oauth-gate-test"
PLUGIN_DIR="${REPO_ROOT}/data/plugins"
+SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# Resolve the SDK source: an existing local checkout, or a fresh clone.
if [[ -n "$PLUGIN_SDK_DIR" ]]; then
@@ -44,6 +51,9 @@ fi
# Tear down installed plugins (and the SDK clone, never a caller-supplied local
# checkout) on top of tools.sh's server/database cleanup.
auth_finish() {
+ if [[ -n "${FAKE_OAUTH_PID}" ]] && kill -0 "${FAKE_OAUTH_PID}" 2>/dev/null; then
+ kill "${FAKE_OAUTH_PID}" 2>/dev/null || true
+ fi
rm -rf "$PLUGIN_DIR"
if [[ "$CLONED_SDK" == "1" ]]; then
rm -rf "$SDK_DIR"
@@ -61,13 +71,30 @@ mkdir -p "$PLUGIN_DIR"
(cd "$SDK_DIR" && ./tools/build-plugin.sh "examples/js/${PLUGIN_NAME}")
cp "${SDK_DIR}/plugins/${PLUGIN_NAME}.ocpkg" "${PLUGIN_DIR}/"
+echo "Building the ${OAUTH_PLUGIN_NAME} plugin (this repo's fixture, against the SDK)..."
+cp -R "${SCRIPT_DIR}/${OAUTH_PLUGIN_NAME}" "${SDK_DIR}/examples/js/${OAUTH_PLUGIN_NAME}"
+(cd "$SDK_DIR" && ./tools/build-plugin.sh "examples/js/${OAUTH_PLUGIN_NAME}")
+cp "${SDK_DIR}/plugins/${OAUTH_PLUGIN_NAME}.ocpkg" "${PLUGIN_DIR}/"
+
echo "Installing the JS test framework..."
npm install --quiet --no-progress
install_ffmpeg
start_owncast
-# The plugin is installed (discovered) but disabled; the test enables it in
-# its beforeAll and disables it in afterAll so the gate is only live for the
-# duration of this suite.
+# Start the internal OAuth2 / OIDC provider the oauth-gate-test plugin
+# authenticates against (node-oidc-provider), then wait for it to be ready.
+echo "Starting the internal OAuth2 provider (node-oidc-provider)..."
+node "${SCRIPT_DIR}/fake-oauth-server.mjs" &
+FAKE_OAUTH_PID=$!
+for _ in $(seq 1 15); do
+ if curl -s "http://localhost:9876/.well-known/openid-configuration" >/dev/null 2>&1; then
+ break
+ fi
+ sleep 1
+done
+
+# The plugins are installed (discovered) but disabled; each suite enables its
+# gate in beforeAll and disables it in afterAll so a gate is only live for the
+# duration of that suite.
npm test