#!/usr/bin/env bash # Tomter Vel's colours on Rauthy's pages (sign-in, account, the admin), # as the deploy keeps them: Rauthy has no file for a theme, only its API, # so this script is the file. The palette is the site's (custom.css in # tomtervel/questions): accent #1785c2, paper #fffceb, ink #111111, line # #e6dfbf, error #ff4136, as HSL. Rauthy themes per OIDC client; the # sign-in page shows the client's theme and the account pages Rauthy's # own (`rauthy`), so both get the same. Needs RAUTHY_HOST and # RAUTHY_API_KEY with Clients read and update; without those rights it # says so and changes nothing. set -euo pipefail for v in RAUTHY_HOST RAUTHY_API_KEY; do [ -n "${!v:-}" ] || { echo "rauthy-theme: $v is not set; nothing changed"; exit 0; } done base="https://$RAUTHY_HOST/auth/v1" auth="Authorization: API-Key $RAUTHY_API_KEY" # Light: paper and ink. Dark: the same blue on a night sky. theme=$(jq -n '{ light: { text: [46, 15, 27], text_high: [0, 0, 7], bg: [51, 100, 96], bg_high: [49, 44, 90], action: [201, 79, 43], accent: [201, 79, 33], error: [3, 100, 61], btn_text: "white", theme_sun: "hsla(var(--action) / .7)", theme_moon: "hsla(var(--accent) / .85)" }, dark: { text: [49, 30, 78], text_high: [51, 100, 96], bg: [201, 35, 9], bg_high: [201, 25, 16], action: [201, 79, 52], accent: [201, 70, 70], error: [3, 100, 61], btn_text: "hsl(var(--bg))", theme_sun: "hsla(var(--action) / .7)", theme_moon: "hsla(var(--accent) / .85)" }, border_radius: "6px" }') for client in rauthy ${OAUTH2_CLIENT_ID:-portal} ${CHAT_OAUTH2_CLIENT_ID:-}; do body=$(jq --arg c "$client" '. + {client_id: $c}' <<<"$theme") code=$(curl -s -o /tmp/rauthy-theme.out -w '%{http_code}' -X PUT -H "$auth" -H 'Content-Type: application/json' -d "$body" "$base/theme/$client") case "$code" in 200|201|204) echo "rauthy-theme: $client themed" ;; 403) echo "rauthy-theme: the API key may not update clients (403); give it Clients read+update, or set the theme in the admin. Nothing changed."; exit 0 ;; *) echo "rauthy-theme: $client: http $code: $(head -c 300 /tmp/rauthy-theme.out)"; exit 1 ;; esac done