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>
2.8 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:
- Create or pick a project, eg. "NGU Website".
- 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).
- 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.
- 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>
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.