Provider definitions
A provider definition describes one OAuth provider as data, in a TOML file: its endpoints, how it proves the
account, whether it rotates refresh tokens, how the client authenticates, how a grant is revoked, the resource hosts an
account’s tokens may go to, and its timing. add --kind oauth-client --provider <PROVIDER> reads it once and seals it
into the OAuth client record. After that, neither a config edit nor an edit to the file changes where the client secret
or a token can be sent. To change a definition, enroll a new client record and sign each account in again with it.
--provider takes a shipped name, google or github-app, or the path of a file of at most 16 KiB; a value with a /
or ending in .toml is a path. The OAuth recipe uses both shipped definitions and writes one of
its own. The design is in oauth.md § Provider definitions.
Fields
| Field | Required | Value | Default |
|---|---|---|---|
authorize | yes | The authorization endpoint, an endpoint URL | none |
token | yes | The token endpoint, an endpoint URL | none |
redirect | no | The loopback address the browser is sent to: exactly http://127.0.0.1:<port>/, with a port from 1 to 65535 | http://127.0.0.1:42213/ |
authorize_params | no | A table of fixed extra consent-URL parameters, such as { access_type = "offline" } | none |
scopes | yes | "required": every login names a --scope. "optional". "none": --scope is refused, as for a GitHub App, whose permissions are set on the app | none |
add_scopes | no | Scopes every login asks for besides its --scopes, such as ["openid", "email"] | none |
account | yes | How login proves which account signed in: one of the account mechanisms | none |
rotation | yes | "never" or "always": see rotation | none |
client_auth | yes | "client_secret_post": the client ID and secret in the token request’s form body. "client_secret_basic": as HTTP Basic | none |
revoke | yes | { style = "rfc7009", url = "…" }: the provider’s RFC 7009 revocation endpoint, an endpoint URL. { style = "none" }: the service tells you to revoke at the provider | none |
resource_hosts | yes | The host patterns an account record’s origins must match | none |
min_retry_seconds | no | The least time between the starts of two refresh attempts, whatever the first one’s outcome | 60 for never, 300 for always |
refresh_margin_seconds | no | How much lifetime an access token must have left to be used without a refresh: see timing. From 30 to 1800 | 300 |
Any other field is refused, as is any other value of scopes, rotation, client_auth, account.style or
revoke.style. The sealed definition names every field, with its default filled in, so it never changes meaning when
a default does; add shows it in that form before it prompts for the client ID.
Endpoints
authorize, token, account.url and revoke.url follow the rules for a route’s
upstream: lowercase https://, no user info, no query and no fragment. Their origins
become the client record’s permitted origins, the only ones its client secret can be sent to. Every request the
service sends to a provider goes to one of these URLs exactly, or is refused before it is sent; it trusts only the
built-in roots, never a route’s ca_file, and never follows a redirect.
Redirect
Nothing listens at the redirect: you paste the address the browser lands on back into login. So it must be the IPv4
loopback literal, with an explicit port and the path /; a host name could resolve elsewhere, and a path or query
would only add places for a code to leak. Register it with the provider if the provider asks for a callback URL.
authorize_params
The service sets response_type, client_id, redirect_uri, scope, state, code_challenge and
code_challenge_method itself, so a definition can’t name any of them, in any case.
Account
login checks that the account the provider verified is the one --account names, ignoring ASCII case, and records
its issuer, subject and display name in the account record.
| Mechanism | Fields | What the service checks |
|---|---|---|
{ style = "id_token", issuers = ["…"] } | issuers: the values the token’s iss may take | The token response carries an OpenID Connect id_token whose iss is one of issuers, whose aud is the client ID, whose exp is in the future and whose email_verified is true. The subject is sub and the display name email. Add openid and email to add_scopes so the provider sends it. |
{ style = "userinfo", url = "…", subject = "…", display = "…" } | url: the account endpoint; subject and display: top-level fields of its JSON answer | One GET of url with the new access token. subject holds a stable identifier (a number is kept as its decimal text) and display the name --account must match. The issuer is the URL’s origin. |
Rotation
always means every refresh may retire the refresh token it spends. The service then writes a marker to the record
before it sends the refresh and stores the new refresh token before it uses the new access token, so a crash at any
point leaves either a usable token or a record that needs login, never a spent token sent again. A provider that
rotates only sometimes is always.
never means a refresh writes nothing to disk, unless the provider does send a refresh token. A rotating provider
declared never fails closed: after a crash at the wrong moment its record needs login. When unsure, choose always.
Resource hosts
A pattern is a lowercase DNS name, which matches only that host, or *. followed by a DNS name, which matches exactly
one more label, as in a TLS certificate: *.example.com matches api.example.com but neither example.com nor
a.b.example.com. A pattern names hosts only, so any port matches.
A name on the Public Suffix List, bare or after *., is refused, since its subdomains
belong to many owners: com, co.uk, github.io and googleapis.com are all on it. The check uses the copy of the
list built into Iron Vault and runs at enrollment only.
login --origin must match a resource host, and a route naming the account record may send its access token only to
one of the record’s origins.
Timing
The refresh margin for never is refresh_margin_seconds, capped at half the token’s lifetime, so a provider whose
tokens live shorter than the margin doesn’t refresh on every request. For always it is the larger of the two, so a
rotating refresh starts at half the lifetime, which leaves time for the service-wide lock to come free.
While the last refresh attempt started less than min_retry_seconds ago, a request uses the current token if it is
still valid and otherwise gets 503 with the reason token_unavailable. This keeps a caller that keeps getting 401
from causing a refresh per request.
Shipped definitions
# google
authorize = "https://accounts.google.com/o/oauth2/v2/auth"
token = "https://oauth2.googleapis.com/token"
authorize_params = { access_type = "offline", prompt = "consent" }
scopes = "required"
add_scopes = ["openid", "email"]
account = { style = "id_token", issuers = ["https://accounts.google.com", "accounts.google.com"] }
rotation = "never"
client_auth = "client_secret_post"
revoke = { style = "rfc7009", url = "https://oauth2.googleapis.com/revoke" }
resource_hosts = ["gmail.googleapis.com", "www.googleapis.com"]
googleapis.com is a public suffix, so the definition names Gmail’s host and www.googleapis.com, which Calendar uses.
Another Google API host needs a definition that names it.
# github-app
authorize = "https://github.com/login/oauth/authorize"
token = "https://github.com/login/oauth/access_token"
scopes = "none"
account = { style = "userinfo", url = "https://api.github.com/user", subject = "id", display = "login" }
rotation = "always"
client_auth = "client_secret_post"
revoke = { style = "none" }
resource_hosts = ["api.github.com"]
GitHub’s revocation call isn’t RFC 7009, so this definition says none.
When a definition is refused
add --kind oauth-client reads the definition before any prompt and answers
credential-invalid with a message that starts invalid provider definition:
and names the rule. Where the parser can place the fault, the message ends with its place in the file, such as
at line 3, column 9. Nothing is written.
| Fault | Message |
|---|---|
| unknown field | unknown field `token_lifetime`, expected one of `authorize`, `token`, … |
| missing field | missing field `token` |
endpoint not https | an endpoint follows the rules for a route's upstream URL: upstream URL must start with "https://" |
| endpoint with a query | an endpoint follows the rules for a route's upstream URL: upstream URL must not contain a query |
| another redirect | redirect must be exactly http://127.0.0.1:<port>/, with a port from 1 to 65535 and nothing else |
| a parameter the service sets | authorize_params sets "state", which the service sets itself |
| a malformed host pattern | a resource host is a lowercase DNS name, or *. followed by one |
| a public suffix | resource host co.uk names a public suffix, whose subdomains belong to many owners |
| refresh margin out of range | refresh_margin_seconds is 10; it must be from 30 to 1800 |