NGU-Web/docs/google-sign-in.md
Zaldimmar d4b39251d9 Add Google sign-in for @nextgenerationofunity.org admin accounts
The login page offers "Sign in with Google" above email and password,
once GOOGLE_CLIENT_ID and GOOGLE_CLIENT_SECRET are set on the service.
It's the server-side authorization-code flow with PKCE; the ID token
comes straight from Google's token endpoint and is checked for
issuer, audience, expiry, a verified email and the Workspace domain
(Google's hd claim).

Only accounts admin-cli has made get in. The first Google sign-in
links the account with the same email; later ones match by the link.
A disabled account, one linked to another Google account, or a
missing account is refused, with a message on the login page, and a
refused sign-in never changes the account. admin-cli list shows which
accounts are linked. Setup is in docs/google-sign-in.md.

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

67 lines
2.8 KiB
Markdown

# 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](https://console.cloud.google.com/), 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:
```ini
[Service]
Environment=GOOGLE_CLIENT_ID=<client id>
Environment=GOOGLE_CLIENT_SECRET=<client secret>
```
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.