pub struct OAuthConfig {
pub link_by_verified_email: bool,
pub state_ttl_secs: u64,
pub success_redirect: String,
pub failure_redirect: String,
pub token_delivery: String,
pub name_field: String,
pub avatar_field: String,
pub providers: BTreeMap<String, OAuthProviderConfig>,
}Expand description
Signing in with somebody else’s account.
Each [oauth.<provider>] block turns one provider on, and a block needs
only the two credentials that provider issued:
[oauth.github]
client_id = "${GITHUB_CLIENT_ID}"
client_secret = "${GITHUB_CLIENT_SECRET}"
[oauth.google]
client_id = "${GOOGLE_CLIENT_ID}"
client_secret = "${GOOGLE_CLIENT_SECRET}"Everything else — the authorize URL, the token URL, where the profile is
read from, which scopes ask for an email, whether the provider wants PKCE,
whether it insists on the client secret as HTTP Basic — apiplant knows for
github, google, linkedin and x. A provider it does not know is
configured in full (see OAuthProviderConfig::style), which is how a
fifth one is added without waiting for a release.
Turning any of this on mounts <base>/auth/oauth/… and adds the
oauth_state resource. With no block at all, none of it
exists.
Fields§
§link_by_verified_email: boolWhether a verified address from a provider may sign somebody in to an existing account carrying the same address (default true).
This is the convenience that makes “I registered with a password, then came back through Google” work, and it is safe only because the address must be one the provider says it verified. An unverified address is never matched, whatever this is set to — that is not a policy, it is the difference between signing in and taking over. Set it false and a matching address is refused with an answer that says how to connect the two deliberately — sign in the way you already can, then link the provider from an authenticated session. Inconvenient, and never wrong.
The same refusal is what an unverified matching address always gets, whatever this is set to.
state_ttl_secs: u64How long a started sign-in stays completable, in seconds (default 600). Long enough to read a consent screen, short enough that an abandoned flow is not a lasting hole. Clamped to 60–3600.
success_redirect: StringWhere the browser lands after a successful sign-in through the
redirecting endpoint, as a path on this site (default /).
A caller can override it per flow with ?return_to=/somewhere, which is
accepted only as a path — never a full URL — because a redirect target
somebody else chooses is how a sign-in page becomes a phishing hop.
failure_redirect: StringWhere a failed sign-in lands, as a path. Empty (the default) answers with a plain JSON error instead, which is what you want while setting providers up and not what you want in front of users.
token_delivery: StringHow the session token reaches the browser on the redirecting endpoint:
| Value | Effect |
|---|---|
fragment (default) | …/#token=… — a fragment is never sent to a server, so it stays out of proxy logs and Referer headers |
query | …?token=… — easier to read from a server-rendered page, and it is in those logs |
json | no redirect at all: the callback answers { "token": …, "user": … }, which is what a single-page app posting the code itself wants |
name_field: StringThe user column a provider’s name is written to on sign-in, or empty
to write none. display_name is in the built-in model; an app that
calls it something else names it here, and one that would rather keep
its own copy of a name sets this to "".
avatar_field: StringThe user column a provider’s picture is written to, or empty for none.
Same bargain as name_field.
Both are written on every sign-in, not only the first: people change their name and their picture, and a copy that is only ever right on the day the account was created is worse than no copy.
providers: BTreeMap<String, OAuthProviderConfig>The providers, keyed by name. Written as [oauth.github] rather than
[oauth.providers.github] — the flattening is what buys that, and the
cost is that a mistyped setting above becomes a provider nobody asked
for, which is refused at boot rather than ignored.
Implementations§
Source§impl OAuthConfig
impl OAuthConfig
Trait Implementations§
Source§impl Clone for OAuthConfig
impl Clone for OAuthConfig
Source§fn clone(&self) -> OAuthConfig
fn clone(&self) -> OAuthConfig
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more