railyard/apps/gitea/scripts/add-oauth-sources.sh
caelum0x 765a46c6c2 feat(rithub): visible Sign up/Sign in header CTAs + GitHub/Google/Apple OAuth wiring
Owner complaint: "rithub still has no google github apple auth and create
account options" -- the header only showed an icon-only Register control
(no visible text), so a first-time visitor had no obvious way to create
an account.

- head_navbar.tmpl / theme-rithub.css: the signed-out Register/Sign In
  controls now show real "Sign up"/"Sign in" text next to their icons
  (filled accent pill for Sign up, plain icon+text for Sign in), as an
  explicit exception to the icon-only nav chrome rule. Dropped the
  mismatched localized aria-label in favor of matching English text/title
  (the visible text is now the accessible name).
- Login ("Register now.") and sign-up ("Sign in now!") cross-links were
  already present and styled bold -- verified live, left as-is.
- docker-compose.yml: [oauth2_client] ENABLE_AUTO_REGISTRATION=true,
  ACCOUNT_LINKING=auto, so a first OAuth login creates/links the account
  directly, no second form.
- New apps/gitea/scripts/add-rithub-oauth-sources.sh: runs on
  railyard-box (no SSH hop), reads /etc/products/rithub-oauth.env
  (root-only, owner-filled) and calls `gitea admin auth add-oauth` for
  GitHub/Google/Apple (Apple's ES256 client-secret JWT minted from the
  .p8 key via python3+PyJWT, already present on the box). Safe to re-run;
  skips sources that already exist or have no credentials. Verified live
  as a no-op with an empty env file.
- rithub-oauth.env.example documents the exact env keys; a real (empty)
  copy was created at /etc/products/rithub-oauth.env on railyard-box for
  the owner to fill in.
- Kept the existing Mac-side add-oauth-sources.sh working (cross-
  referenced, not replaced).

Deployed to railyard-box (apps/gitea only, backed up custom/+app.ini/
compose first). Verified live: header shows Sign up/Sign in text
(desktop + mobile), real signup via a mail.tm disposable address +
captcha succeeded end to end (account created, welcomed, deleted after).
No provider enabled yet -- OAuth app creation in each provider console
is an owner-only step, documented in plans/railyard.md.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-11-18 02:06:00 +03:00

50 lines
2.9 KiB
Bash

#!/usr/bin/env bash
# Adds GitHub / Google / Apple sign-in to Rithub (rithub.dev).
# Reads credentials from ~/products/.env. Run from the Mac:
# bash apps/gitea/scripts/add-oauth-sources.sh
# 2026-11-18: a second copy of this, add-rithub-oauth-sources.sh, runs
# ON railyard-box itself (no SSH hop) reading from the root-only
# /etc/products/rithub-oauth.env instead -- that's the one the owner's
# per-provider steps in plans/railyard.md actually point at now. Kept
# this Mac-side version working too (never delete a working path) for
# anyone who already has the creds in ~/products/.env.
# Callback URLs to register in each provider console:
# GitHub: https://rithub.dev/user/oauth2/GitHub/callback
# Google: https://rithub.dev/user/oauth2/Google/callback
# Apple : https://rithub.dev/user/oauth2/Apple/callback (Services ID, "Sign in with Apple")
# Each source is only added if its env vars are present; existing ones are skipped.
set -euo pipefail
ENV="$HOME/products/.env"
get() { grep -E "^$1=" "$ENV" | tail -1 | cut -d= -f2- | tr -d '"' || true; }
C=railyard-gitea-gitea-1
run() { ssh railyard-box "docker exec -u git $C gitea admin auth $*"; }
existing=$(ssh railyard-box "docker exec -u git $C gitea admin auth list" || true)
add() { # name provider key secret [extra args...]
local name=$1 provider=$2 key=$3 secret=$4; shift 4
if [ -z "$key" ] || [ -z "$secret" ]; then echo "skip $name: credentials not in .env"; return; fi
if grep -q "[[:space:]]$name[[:space:]]" <<<"$existing"; then echo "skip $name: already configured"; return; fi
run add-oauth --name "$name" --provider "$provider" --key "'$key'" --secret "'$secret'" "$@"
echo "added $name"
}
add GitHub github "$(get RITHUB_GITHUB_CLIENT_ID)" "$(get RITHUB_GITHUB_CLIENT_SECRET)" --scopes "'read:user,user:email'"
add Google openidConnect "$(get RITHUB_GOOGLE_CLIENT_ID)" "$(get RITHUB_GOOGLE_CLIENT_SECRET)" \
--auto-discover-url https://accounts.google.com/.well-known/openid-configuration --scopes "'openid email profile'"
# Apple: client secret is an ES256 JWT signed with the Sign in with Apple .p8 key (max 6 months; re-run to rotate).
APPLE_ID=$(get RITHUB_APPLE_SERVICES_ID); TEAM=$(get APPLE_TEAM_ID); KID=$(get RITHUB_APPLE_KEY_ID); P8=$(get RITHUB_APPLE_P8_PATH)
if [ -n "$APPLE_ID" ] && [ -n "$TEAM" ] && [ -n "$KID" ] && [ -f "${P8:-/nonexistent}" ]; then
SECRET=$(python3 - "$TEAM" "$KID" "$APPLE_ID" "$P8" <<'PY'
import sys,time,jwt
team,kid,sub,p8=sys.argv[1:]
now=int(time.time())
print(jwt.encode({"iss":team,"iat":now,"exp":now+180*86400,"aud":"https://appleid.apple.com","sub":sub},open(p8).read(),algorithm="ES256",headers={"kid":kid}))
PY
)
add Apple openidConnect "$APPLE_ID" "$SECRET" --auto-discover-url https://appleid.apple.com/.well-known/openid-configuration --scopes "'openid'"
else
echo "skip Apple: RITHUB_APPLE_SERVICES_ID / APPLE_TEAM_ID / RITHUB_APPLE_KEY_ID / RITHUB_APPLE_P8_PATH not all set"
fi
ssh railyard-box "docker exec -u git $C gitea admin auth list"