# oauth

Sign-in with another service's word, into the program's own accounts and
sessions, one provider a file; a provider's tokens kept for its API; the
flows with no browser. The whole of it is [docs/oauth.md](../../docs/oauth.md).

```toml
[packages]
oauth = "../mote/extensions/oauth"
```

```text
use "pkg:oauth/github.mote"
GithubButton
```

| File | |
|---|---|
| `oauth.mote` | The flow: authorization code with PKCE, `state` and `nonce`; discovery; keys kept and fetched again on rotation; an id token checked claim by claim; GitHub's and Discord's APIs for who a token is; whose account someone is; `oauthMay`; connecting and disconnecting. Models `OidcPending`, `OidcLink`, `OidcCache`, `OidcSignIn` (their names from when this was Google's alone). |
| `github.mote` `microsoft.mote` `apple.mote` `discord.mote` `gitlab.mote` `linkedin.mote` `slack.mote` | One provider each: its record, its routes, its button, its fns. |
| `issuer.mote` | Any OpenID provider by its issuer's address, from settings (`/auth/oidc/…`). |
| `sso.mote` | A connection for each customer (`OauthIssuer`), its domains held to. |
| `tokens.mote` | `OauthGrant`, sealed; `oauthToken`, `oauthCall`, `oauthUserinfo`, `oauthRevoke`, `oauthConnected`. Needs `OAUTH_TOKEN_KEY`. |
| `machine.mote` | `oauthClientToken` (client credentials), `oauthDeviceBegin` and `oauthDevicePoll` (the device code). |
| `tests.mote` | Its tests: `use "pkg:oauth/tests.mote"` beside the providers, then `mote test`. |

Covered: sign-in and connecting for the providers above, the linking rules
of Google's extension for all of them, tokens with refresh and rotation and
revocation, client credentials, the device code, B2B connections. Left out
on purpose: the implicit and hybrid flows, a public client with no secret
(a page cannot keep one: the back end is the client), JWT client
authentication (`private_key_jwt`) except Apple's secret, PAR and JAR,
front- and back-channel logout, SAML ([docs/saml.md](../../docs/saml.md)).

**Not yet run against any real provider**: only against the pretend one in
`tests/google_fakeidp.mjs` and `given net` stand-ins. The steps to check
each with a real client id are in the docs.
