Skip to content

feat: Google-backed JWT auth and Next.js frontend for GameServer sample#43

Merged
Theauxm merged 1 commit into
mainfrom
feat/jwt-google-oidc-sample
Apr 17, 2026
Merged

feat: Google-backed JWT auth and Next.js frontend for GameServer sample#43
Theauxm merged 1 commit into
mainfrom
feat/jwt-google-oidc-sample

Conversation

@Theauxm
Copy link
Copy Markdown
Member

@Theauxm Theauxm commented Apr 17, 2026

Summary

Exercises the new Trax.Api.Auth.Jwt package (from Trax.Api#32) against a real OIDC provider (Google) with a full browser frontend. Paired with Trax.Docs#73.

Depends on Trax.Api#32. CI will fail NU1101 on Trax.Api.Auth.Jwt until that PR merges and publishes the package to nuget.org. Locally the package resolves via pack-local.sh; in CI it needs the published version. Merge Trax.Api first, then rerun Samples CI.

GameServer.Api changes

  • Adds Trax.Api.Auth.Jwt package reference.
  • Wires AddTraxJwtAuth<GoogleJwtResolver>("https://accounts.google.com", googleClientId) conditionally on Google:ClientId from config.
  • GoogleJwtResolver maps sub/name/email into TraxPrincipal and grants the Player role (demo-only so sample trains work; real deployments would lookup in the user table).
  • Client id is read from .NET user-secrets, not appsettings, to avoid committing per-developer OAuth credentials.

New web sample

samples/LocalWorkers/trax-samples-gameserver-web/ is a minimal Next.js 15 app:

  • NextAuth v5 with Google provider, captures id-token onto the session JWT.
  • Dark-themed single page with sign in, sign out, two GraphQL buttons (discover trains, lookup player). Sends Authorization: Bearer <id-token> to the Trax API.
  • No framework styling, ~150 lines of CSS, easy to rip apart.
  • README with Google Cloud Console setup, .env.local layout, and the full auth flow diagram.

The cross-origin Bearer pattern was chosen over cookie-based OIDC because Next.js lives on a separate origin and cross-origin cookies are painful. A BFF proxy variant is called out in the README as the production-hardened upgrade path.

Test plan

  • dotnet build of GameServer.Api succeeds locally (0 warnings) via pack-local.sh
  • npx next build of the web sample succeeds (0 errors)
  • Tested end-to-end: Google sign-in → id-token captured → GraphQL discover/lookup calls return with Player role granted
  • CI green after Trax.Api#32 merges and publishes

The GameServer.Api sample now accepts Google-issued id-tokens alongside
its existing API-key scheme. AddTraxJwtAuth is wired conditionally on
Google:ClientId (via user secrets, not appsettings). A custom resolver
grants every authenticated Google user the Player role so the sample's
trains work out of the box for anyone with a Google account — demo only,
real deployments would look up the principal in the game user table.

The new trax-samples-gameserver-web directory is a minimal Next.js 15
companion that signs users in with Google via NextAuth v5, captures the
id-token on the session JWT, and forwards it as Authorization: Bearer to
the Trax API. Includes:

- NextAuth v5 with Google provider (src/auth.ts).
- Single-page UI with sign in, sign out, two GraphQL calls (discover
  trains, lookup player).
- README covering Google Cloud Console setup, user-secrets configuration,
  and the full browser → Next.js → Trax API flow.

pack-local.sh picks up the two new auth packages automatically via the
Trax.Api slnx update; no change needed here.
@Theauxm Theauxm merged commit f417ec5 into main Apr 17, 2026
1 of 6 checks passed
@Theauxm Theauxm deleted the feat/jwt-google-oidc-sample branch April 17, 2026 20:33
@traxsharp
Copy link
Copy Markdown

traxsharp Bot commented May 6, 2026

This PR is included in version 1.21.0

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.

1 participant