# google

Continue with Google, into the program's own accounts and sessions. The
whole of it (the Google Cloud console's steps, what is kept, whose account
someone from Google is, running behind a proxy) is
[docs/google.md](../../docs/google.md).

```toml
# mote.toml
[packages]
google = "../mote/extensions/google"
```

```text
use "pkg:google/google.mote"

GoogleButton                      // or: button "Continue with Google" press=googleSignIn
```

Settings: `GOOGLE_CLIENT_ID`, `GOOGLE_CLIENT_SECRET` (the back end does not
start without it). Optional: `GOOGLE_REDIRECT` (set it in production:
`https://shop.example/auth/google/callback`), `GOOGLE_DOMAIN`,
`GOOGLE_LINK=ask`, `GOOGLE_PROMPT`, `GOOGLE_DISCOVERY`, and
`GOOGLE_AUTH_URL` `GOOGLE_TOKEN_URL` `GOOGLE_KEYS_URL` `GOOGLE_ISSUER`.

At Google: an OAuth client of type "Web application", with the authorized
redirect URI `<the site>/auth/google/callback`.

To say who may come in (nothing said: everyone Google vouches for), the
program declares the fn the extension `wants` (`GOOGLE_DOMAIN` is the other
way: a Workspace domain):

```text
fn googleMay(who: OidcWho): bool
  if !who.email.endsWith("@shop.example") fail("Only people of the shop sign in here.")?
  return true
```

False is a no in the extension's words, a failure one in the program's. (The
older way, a `server before OidcSignIn.add(who)` hook that fails, is still
asked after `googleMay`, for this release.)

| File | |
|---|---|
| `oidc.mote` | The flow, for any OpenID Connect provider: the authorization-code flow with PKCE, `state` and `nonce`; the id token checked claim by claim; the models (`OidcLink`, `OidcPending`, `OidcCache`, `OidcSignIn`); whose account a person is. |
| `google.mote` | Google's settings over it: the provider's record, the routes `GET /auth/google/start` and `/auth/google/callback`, `GoogleButton`, `googleSignIn`, `googleSignInTo(route)`, `googleConnect`, `googleProfile()`. |
| `tests.mote` | Its tests: `use "pkg:google/tests.mote"` in a program that takes `google.mote`, then `mote test`. |

Google's endpoints are written in `google.mote` from memory of its
discovery document: confirm them against
`https://accounts.google.com/.well-known/openid-configuration` when first
deploying, or set `GOOGLE_DISCOVERY` to that address.
