Skip to content

Let branch previews sign in with Discord through dev - #154

Merged
ryanbarlow97 merged 3 commits into
mainfrom
preview-sign-in
Oct 10, 2026
Merged

ryanbarlow97 merged 3 commits into
mainfrom
preview-sign-in

Conversation

@ryanbarlow97

@ryanbarlow97 ryanbarlow97 commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Branch previews (<slug>.tfminecraft.net) could not sign anyone in: Discord only returns players to registered callbacks, and a new branch name never is one. Previews now sign in through dev, the way OpenFront's branch sites all use api.openfront.dev.

How it works

  1. The preview's /auth/discord/start puts a random state in its state cookie and sends the browser to dev's /api/auth/preview/start with the state, its origin and the return path.
  2. Dev accepts only https://<slug>.<PREVIEW_SIGN_IN_DOMAIN> origins with an unreserved slug. Without a dev session it signs the player in with Discord first; the callback brings them back to the same route.
  3. Dev refreshes the guild check with its bot, stores a hashed single-use ticket for that preview (120 seconds) and redirects to the preview's /api/auth/preview/callback.
  4. The preview checks the state against its cookie and posts the ticket and its origin to dev's /api/auth/preview/redeem, which deletes the ticket and returns the Discord identity, website role and guild check.
  5. The preview opens its own session with that role.

A player already signed in on dev goes straight through without Discord. Previews never hold the Discord secret or a dev session, and anything done there stays in the preview's copy of dev's data (the LuckPerms bridge, Patreon, CoreProtect and the Discord bot are all off on previews).

Settings

  • Dev: PREVIEW_SIGN_IN_DOMAIN=tfminecraft.net in backend/.env (added before this deploys).
  • Previews: SIGN_IN_SITE=https://dev.tfminecraft.net, baked into the preview backend image by the Preview workflow. Empty everywhere else.

No frontend changes: the sign-in button already points at the site's own /api/auth/discord/start.

Testing

  • src/auth/test_preview_sign_in.py: 54 tests covering allowed preview origins, the preview and dev halves of the flow, single use, expiry, site binding, odd answers from dev and dev being down.
  • pytest src/auth src/api/test_prod_guard.py: all pass.
  • End to end needs dev running this code, so it can only be tried on a preview after merge.

Docs: TF-Minecraft/Docs#123.

🤖 Generated with Claude Code

Discord only returns players to registered callbacks, so a preview at
<slug>.tfminecraft.net could not sign anyone in. Previews now send the
browser to dev, which signs the player in (or uses its existing session)
and returns them with a single-use, 120-second ticket. The preview
redeems it with dev for the Discord identity, website role and guild
check, then opens its own session. Previews hold no Discord secret.

Dev needs PREVIEW_SIGN_IN_DOMAIN=tfminecraft.net; preview images get
SIGN_IN_SITE=https://dev.tfminecraft.net at build time.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Oct 10, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 23 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 459ae809-f05d-4f4f-8ebc-7ec8a8f2784c

📥 Commits

Reviewing files that changed from the base of the PR and between 72998eb and 929f5b4.


📒 Files selected for processing (10)
  • .github/workflows/preview.yml
  • backend/Dockerfile
  • backend/server.py
  • backend/src/api/auth_routes.py
  • backend/src/auth/config.py
  • backend/src/auth/preview_sign_in.py
  • backend/src/auth/test_discord_client.py
  • backend/src/auth/test_preview_sign_in.py
  • backend/src/auth/users.py
  • backend/src/skins/schema.sql

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

- Drop preview start and callback queries from access logs, so a logged
  ticket cannot be redeemed by someone reading the logs.
- When dev's bot cannot refresh a guild check over 15 minutes old, sign
  in with Discord again instead of handing the preview a stale check
  that linking would refuse, in a loop.
- Refuse malformed preview origins instead of failing with a 500.
- Say in the Preview summary that sign-in goes through dev.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
"I've joined, check again" on a preview signs in through dev again. With
dev's bot unable to answer, dev handed back the recent "not a member"
check, so the button did nothing for up to 15 minutes. A preview that
already has a session now asks dev for a recheck, and dev then signs
in with Discord once (the saved return drops the recheck, so it ends).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ryanbarlow97
ryanbarlow97 merged commit 4581411 into main Oct 10, 2026
6 checks passed
@ryanbarlow97
ryanbarlow97 deleted the preview-sign-in branch October 10, 2026 20:38

This branch was successfully deployed

1 active deployment
preview — 929f5b4e Deployed Oct 10, 2026 by ryanbarlow97 via deploy #133
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