feat: Google-backed JWT auth and Next.js frontend for GameServer sample#43
Merged
Conversation
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.
|
This PR is included in version 1.21.0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Exercises the new
Trax.Api.Auth.Jwtpackage (from Trax.Api#32) against a real OIDC provider (Google) with a full browser frontend. Paired with Trax.Docs#73.GameServer.Api changes
Trax.Api.Auth.Jwtpackage reference.AddTraxJwtAuth<GoogleJwtResolver>("https://accounts.google.com", googleClientId)conditionally onGoogle:ClientIdfrom config.GoogleJwtResolvermapssub/name/emailintoTraxPrincipaland grants thePlayerrole (demo-only so sample trains work; real deployments would lookup in the user table).New web sample
samples/LocalWorkers/trax-samples-gameserver-web/is a minimal Next.js 15 app:Authorization: Bearer <id-token>to the Trax API..env.locallayout, 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 buildof GameServer.Api succeeds locally (0 warnings) viapack-local.shnpx next buildof the web sample succeeds (0 errors)Playerrole granted