Generate the job capture token from the admin panel
Deploy with Docker Compose / deploy (push) Successful in 52s
Deploy with Docker Compose / deploy (push) Successful in 52s
The userscript's bearer token was an env var, JOB_CAPTURE_TOKEN, so rotating it meant editing .env and redeploying. It is now minted on the admin diagnostics panel instead, and the env var is gone. - services.CaptureToken keeps only a SHA-256 of the token, in backend/token/job_capture_token.json beside the OAuth tokens, so it survives rebuilds and cannot be read back. The token is shown once. - GET/POST/DELETE /admin/capture-token report, generate (replacing any existing token) and revoke it, behind the cookie-authenticated admin group. - With no token generated the capture routes still answer 503. - Userscript bumped to 1.0.1 for the changed prompt text. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
+13
-5
@@ -6,7 +6,6 @@ import (
|
||||
"io"
|
||||
"log"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/99designs/gqlgen/graphql/handler"
|
||||
@@ -162,11 +161,15 @@ func main() {
|
||||
loginLimiter := services.NewRateLimiter(5, time.Minute)
|
||||
|
||||
// JOB CAPTURE
|
||||
// Trimmed because a stray newline in .env would otherwise make every
|
||||
// request fail the comparison with nothing to show why.
|
||||
jobCaptureToken := strings.TrimSpace(os.Getenv("JOB_CAPTURE_TOKEN"))
|
||||
// The userscript's bearer token is generated in the admin panel and kept
|
||||
// (hashed) beside the OAuth tokens. A damaged file is logged, not fatal:
|
||||
// capture stays off until a new token is generated.
|
||||
captureToken, err := services.InitCaptureToken(services.CAPTURE_TOKEN_JSON_PATH)
|
||||
if err != nil {
|
||||
log.Println("Job capture token not loaded:", err)
|
||||
}
|
||||
|
||||
store := handlers.Store{DB: db, SpotifyAuth: spotifyAuth, SpotifyClient: spotifyClient, Auth: auth, Notes: notes, LoginLimiter: loginLimiter, EmailSync: emailSync, GiteaHost: giteaHost, GiteaPort: giteaPort, SteamAPIKey: steamAPIKey, SteamID: steamID, PythonURL: pythonURL, JobCaptureToken: jobCaptureToken}
|
||||
store := handlers.Store{DB: db, SpotifyAuth: spotifyAuth, SpotifyClient: spotifyClient, Auth: auth, Notes: notes, LoginLimiter: loginLimiter, EmailSync: emailSync, GiteaHost: giteaHost, GiteaPort: giteaPort, SteamAPIKey: steamAPIKey, SteamID: steamID, PythonURL: pythonURL, CaptureToken: captureToken}
|
||||
|
||||
// Route groups. AdminMiddleware reads the claims AuthMiddlewear stored in
|
||||
// the Gin context, so the order in the admin group matters.
|
||||
@@ -226,6 +229,11 @@ func main() {
|
||||
// ADMIN DIAGNOSTICS: env-var checklist and log tail for the admin panel.
|
||||
admin.GET("/admin/config", store.ConfigCheck)
|
||||
admin.GET("/admin/logs", store.Logs)
|
||||
// The job capture token is managed with the session cookie, never with
|
||||
// the token itself.
|
||||
admin.GET("/admin/capture-token", store.GetCaptureToken)
|
||||
admin.POST("/admin/capture-token", store.GenerateCaptureToken)
|
||||
admin.DELETE("/admin/capture-token", store.RevokeCaptureToken)
|
||||
|
||||
// GRAPHQL
|
||||
// GraphQL is assembled by hand rather than with handler.NewDefaultServer
|
||||
|
||||
Reference in New Issue
Block a user