NGU-Web/docs/google-sign-in.md
Aidan Dona e4c7e165d1 Profile accounts: invites, any-Google sign-in, claiming People, visibility, Discord
Migration 076 adds a member role below viewer (the site and its own
profile, never the admin: /api/admin now needs viewer), invites, person
claims, a Discord link on accounts and people.hide_* switches. Public reads
of people go through v_people_public, which nulls hidden fields, and the
views that read people are rebuilt over it.

Admins invite an email from Data -> Profile accounts (link shown once,
emailed on request). The invitee sets a password or signs in with any
Google account under that email, asks to claim their People record, and
once approved edits it and chooses what shows at /account.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-16 18:14:30 -05:00

154 lines
6.9 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
Three kinds of account can sign in with Google:
- **Group accounts**, when access groups are set up (below): anyone in
one of the site's Workspace groups. Their account is made at their
first sign-in, and their role follows the group.
- **Accounts made with admin-cli**, as before.
- **Profile accounts** (members, `docs/profile-accounts.md`), invited
from Data → Profile accounts. These are the one case outside the
Workspace: any Google account under the invited email, from the
site's `/sign-in` page or the invite's welcome page.
Created 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 (and in no access group), 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) unless it's a profile account's,
an unverified email.
Code: `server/src/googleAuth.js` (the Google side),
`server/src/routes/auth.js` (matching and linking accounts) and
`server/src/accessGroups.js` (access groups).
## Access groups
Panel → Site settings → **Access (Google groups)** names a Workspace
group for each of Admin, Editor and Viewer, eg.
`web-admins@nextgenerationofunity.org`. Any of them may be blank.
- **First sign-in:** someone in one of the groups signs in with Google
and gets an account with the highest role their groups give (in both
the editors and viewers groups: editor). No password: Google only.
Groups inside groups count.
- **The role follows the group**, checked at every sign-in, about once
an hour while they're signed in, and whenever a superadmin presses
Panel → Google groups → **Re-sync now**. Moved to another group: the
role changes. Out of every group: the account is disabled and signed
out; put back in one, it's turned on again at the next sign-in or
re-sync.
- **In the Panel**, a group account says "Google group" and its role
can't be changed there (change the membership instead). Disable still
works, and sticks: no group check turns back on an account a
superadmin disabled.
- **Not affected:** superadmins (there's no superadmin group) and
accounts made with admin-cli, which keep the role set in the Panel
whatever groups they're in.
- **If Google can't be asked** (an outage, a setup mistake), a sign-in
is refused ("Couldn't check your Google groups"), but the hourly
check leaves accounts as they are and tries again; nobody is signed
out because Google was down. Password and admin-cli accounts still
get in.
Panel → Google groups → **Check their groups** shows what role an email
would get, changing nothing: the quickest check of the setup.
### Setting it up
Group lookups use the service account from
`docs/google-drive-and-mail.md` (step 1 there), through the Admin SDK
Directory API:
1. Cloud Console, the service account's project → APIs & Services →
Library → enable the **Admin SDK API**.
2. Admin console → Security → Access and data control → API controls →
Manage domain wide delegation → the service account's entry → Edit.
Add the scope (comma separated, beside `gmail.send`):
`https://www.googleapis.com/auth/admin.directory.group.member.readonly`
3. Pick a Workspace **user** who can see the groups' members: a super
admin, or an admin with a role that includes Groups → Read. The
lookups are made as them. Set it on the service:
```ini
Environment=GOOGLE_DIRECTORY_AS=<that user, eg. it-admin@nextgenerationofunity.org>
```
4. Make the groups in Google Admin (or Groups), add people, and put the
addresses in Site settings → Access. Restart `ngu-api` after the
`systemctl edit`.
`GOOGLE_SERVICE_ACCOUNT` and `GOOGLE_DIRECTORY_AS` without any groups
set changes nothing; groups set without them show a warning in the
Panel and Google sign-in works as before.
Errors in the Panel or journal (`grep access`): `groupKey` means a group
address in Site settings isn't a group Google knows; `unauthorized_client`
means the delegation or scope (step 2) is missing, or
`GOOGLE_DIRECTORY_AS` isn't a user; `Not Authorized to access this
resource` means that user can't read the group.
## 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>
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.