NGU-Web/docs/google-sign-in.md
Zaldimmar e932ee3007 Show Google sign-in even when site.json isn't deployed
/api/auth/providers read site.json to build Google's return address,
and the deploy copies server/ into /srv/ngu-api without site.json, so
it threw and the login page hid the button. Whether Google is on now
depends only on the client id and secret; a missing return address is
logged when a sign-in starts, naming GOOGLE_REDIRECT_URI and
SITE_CONFIG. The docs say how the server is actually deployed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-27 21:51:40 -05:00

3.3 KiB

Google sign-in

The admin login offers "Sign in with Google" for @nextgenerationofunity.org accounts, alongside email and password. It's off until the service has an OAuth client ID and secret.

Who gets in

Only accounts that already exist. Create them as before with admin-cli.js add <email> (the password it asks for stays as a way in if Google is ever unavailable). The first time that person signs in with Google, their Google account is linked to the admin account with the same email; after that it matches by the link, even if the email later changes. admin-cli.js list shows which accounts are linked.

Refused, with a message on the login page: no admin account for that email, an email already linked to a different Google account, a disabled account, any account outside the Workspace domain (checked by Google's hd claim, not just the email), an unverified email.

Code: server/src/googleAuth.js (the Google side) and server/src/routes/auth.js (matching and linking accounts).

Setting up the OAuth client

In Google Cloud Console, signed in as a Workspace admin for nextgenerationofunity.org:

  1. Create or pick a project, eg. "NGU Website".
  2. APIs & Services → OAuth consent screen (Google Auth Platform → Branding / Audience):
    • User type / audience: Internal. Only accounts in the Workspace can use it, and Google doesn't need to review the app.
    • App name: NGU Admin. Support email: yours.
    • Scopes: openid, email, profile (nothing else is needed).
  3. APIs & Services → Credentials → Create credentials → OAuth client ID (Google Auth Platform → Clients):
    • Application type: Web application. Name: NGU admin.
    • Authorized redirect URIs:
      • https://nextgenerationofunity.org/api/auth/google/callback
      • for local work, also the dev address, eg. http://localhost:5174/api/auth/google/callback
    • No JavaScript origins are needed: the browser never talks to Google directly.
  4. Copy the Client ID and Client secret.

Turning it on

On the server, add them to the ngu-api unit (systemctl edit ngu-api) and restart. Never commit the secret or paste it into the repo:

[Service]
Environment=GOOGLE_CLIENT_ID=<client id>
Environment=GOOGLE_CLIENT_SECRET=<client secret>
Environment=GOOGLE_REDIRECT_URI=https://nextgenerationofunity.org/api/auth/google/callback

GOOGLE_REDIRECT_URI must match the redirect URI in step 3 exactly. Without it the API builds it from site.json's url, which the API only finds if site.json is deployed with it and SITE_CONFIG points at it (the deploy copies server/ into /srv/ngu-api, and site.json lives at the repo root, so it isn't there by default). If neither is set, sign-in fails and the log says so.

Optional:

Variable Default
GOOGLE_REDIRECT_URI <site.json url>/api/auth/google/callback. Set it for local work, eg. http://localhost:5174/api/auth/google/callback, and add the same URI in step 3.
GOOGLE_ALLOWED_DOMAIN nextgenerationofunity.org

The login page asks /api/auth/providers whether Google is set up, so the button appears as soon as the service restarts with both values. Locally, also set COOKIE_SECURE=false when working over plain http.