Skip to content

[WIP] Set up the super admin API skeleton#5554

Closed
carmenlau wants to merge 11 commits intoauthgear:mainfrom
carmenlau:dev-3422-superadmin-api-setup
Closed

[WIP] Set up the super admin API skeleton#5554
carmenlau wants to merge 11 commits intoauthgear:mainfrom
carmenlau:dev-3422-superadmin-api-setup

Conversation

@carmenlau
Copy link
Copy Markdown
Contributor

@carmenlau carmenlau commented Mar 4, 2026

ref DEV-3422

WIP:

  • local dev setup
  • Setup CORS middleware for external web app call

carmenlau and others added 11 commits March 4, 2026 15:36
Add PORTAL_SUPERADMIN_LISTEN_ADDR and PORTAL_SUPERADMIN_INTERNAL_LISTEN_ADDR
configuration fields with defaults to :3005 and :13005 respectively.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
Create the GraphQL schema layer with:
- schema.go: Initialize GraphQL schema with query and mutation
- query.go: Define Query object with __typename field
- mutation.go: Define Mutation object with __typename field
- context.go: Define GraphQL context for request-scoped data
- deps.go: Wire dependency injection set

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
Create the HTTP transport layer with:
- graphql.go: Configure GraphQL route at /api/graphql with GET and POST methods
- handler_graphql.go: Implement HTTP handler for GraphQL queries
- deps.go: Wire dependency injection set

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
Create CSP middleware that:
- Sets strict Content-Security-Policy header
- Disallows inline scripts and objects
- Restricts frame ancestors
- Supports only self and strict-dynamic scripts

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
Combine dependency injection sets from:
- portal deps (base dependencies)
- clock (for SessionInfoMiddleware)
- globaldb (for health check)
- globalredis (for health check)
- graphql (GraphQL layer)
- transport (HTTP transport layer)

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
Create wire injector functions to build:
- newPanicMiddleware: Panic recovery middleware
- newBodyLimitMiddleware: Request body size limiting
- newOtelMiddleware: OpenTelemetry tracing
- newSentryMiddleware: Error capture and reporting
- newSessionInfoMiddleware: Session validation via Authgear
- newHealthzHandler: Health check endpoint
- newGraphQLHandler: GraphQL query handler

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
Assemble the complete HTTP routing and middleware stack:
- Health check endpoint (/healthz)
- GraphQL endpoint (/api/graphql) with full middleware chain:
  1. OTel tracing
  2. Panic recovery
  3. Body size limiting
  4. Sentry error capture
  5. Session validation (via Authgear)
  6. Security headers (CSP, X-Frame-Options, etc.)
  7. Cache-Control: no-store
  8. Content-Type validation

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
Auto-generated wire_gen.go file via:
  wire gen ./pkg/portal/superadmin/...

Generates all dependency injection provider functions and
wires together the complete dependency graph for the superadmin package.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
Add optional superadmin server startup controlled by command-line arguments:

cmd/portal/server/server.go:
- Import superadmin package
- Add PortalMode and SuperadminMode flags to Controller struct
- Update Start() method to conditionally create server specs based on flags
- If PortalMode: start portal on :3003 with internal pprof on :13003
- If SuperadminMode: start superadmin on :3005 with internal pprof on :13005

cmd/portal/cmd/cmdstart/start.go:
- Parse command arguments: "portal" or "superadmin"
- Default to PortalMode if no args (backward compatible)
- Set only SuperadminMode=true if "superadmin" arg provided

Usage:
  ./authgear-portal start           # Starts portal (default)
  ./authgear-portal start portal    # Explicit portal mode
  ./authgear-portal start superadmin # Starts superadmin only

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
@carmenlau carmenlau requested a review from tung2744 March 4, 2026 16:19
Comment thread docs/plans/superadmin-api/01-superadmin-api-setup.md

import "net/http"

func SuperadminCSPMiddleware(next http.Handler) http.Handler {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reuse CSP middleware of portal?
Or what is the reason we need separated CSP Middleware?


import "github.com/authgear/authgear-server/pkg/util/httproute"

func ConfigureGraphQLRoute(route httproute.Route) []httproute.Route {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We also need to update nginx.conf. Define a path routing to the super admin port.

@carmenlau
Copy link
Copy Markdown
Contributor Author

The plan has changed, I'll open a another PR for the server setup.

@carmenlau carmenlau closed this Mar 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants