peppa/scripts/create-oauth-app.sh
Асель 2b0f2fd984 PEP-1: web platform with Gitea login, projects, goals, tasks, sessions
- web: Gitea OAuth2 login, signed session cookie, everything behind login;
  inbox with answers, project board (goals → tasks), task page with
  OpenSpec artifacts, questions and session controls; new project form;
  auto-refresh, light/dark, mobile
- users + projects.owner_id; tokens AES-256-GCM encrypted; owner-only access
- provisionProject (runner): new or existing Gitea repo, peppa-bot
  collaborator, template + openspec init, push, rollback; used by web and
  peppa project create (replaces scripts/bootstrap-project.sh)
- peppa web login-link, peppa project owner; Gitea OAuth app script
- bins/template resolved via PEPPA_ROOT (works inside the Next build)
- testkit: mock-gitea + 10 tests (42 e2e total, all green)
- OpenSpec: pep-1-web-platform archived into specs web-auth,
  project-provisioning, web-workspace

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-12 20:55:02 +05:00

23 lines
1.4 KiB
Bash
Executable File

#!/usr/bin/env bash
# Creates the Gitea OAuth2 application for web login (owned by peppa-bot) and writes
# GITEA_OAUTH_CLIENT_ID / GITEA_OAUTH_CLIENT_SECRET into .env. Idempotent: an existing
# "Peppa" app is reused only if .env already has its secret (Gitea never shows it again).
set -euo pipefail
cd "$(dirname "$0")/.."
PEPPA_ROOT="$PWD"; . scripts/lib/load-env.sh
. scripts/gitea-lib.sh
REDIRECTS="[\"${PEPPA_WEB_URL%/}/auth/callback\",\"http://localhost:3100/auth/callback\"]"
existing=$(gitea_api "$GITEA_URL/api/v1/user/applications/oauth2" | python3 -c 'import json,sys;print(next((str(a["id"]) for a in json.load(sys.stdin) if a["name"]=="Peppa"),""))')
if [ -n "$existing" ] && [ -n "${GITEA_OAUTH_CLIENT_SECRET:-}" ]; then echo "OAuth app exists (id $existing), .env has its secret"; exit 0; fi
[ -n "$existing" ] && gitea_api -X DELETE "$GITEA_URL/api/v1/user/applications/oauth2/$existing" >/dev/null
gitea_api -X POST "$GITEA_URL/api/v1/user/applications/oauth2" \
-d "{\"name\":\"Peppa\",\"redirect_uris\":$REDIRECTS,\"confidential_client\":true}" |
python3 -c '
import json,re,sys
d=json.load(sys.stdin); p=".env"; s=open(p).read()
for k,v in (("GITEA_OAUTH_CLIENT_ID",d["client_id"]),("GITEA_OAUTH_CLIENT_SECRET",d["client_secret"])):
s=re.sub(rf"^{k}=.*\n?","",s,flags=re.M)
s=s.rstrip("\n")+f"\n{k}={v}\n"
open(p,"w").write(s)
print("created OAuth app, client id", d["client_id"])'