OAuth sign-in
Google and GitHub sign-in with PKCE and verified-only linking.
Register providers through Config.OAuth with a 32-byte StateKey, an
application origin and an exact redirect allowlist:
cfg.OAuth = &signet.OAuthConfig{
Providers: []signet.OAuthProvider{
google.Provider{ClientID: id, ClientSecret: secret},
github.Provider{ClientID: id, ClientSecret: secret},
},
RedirectBaseURL: "https://api.example.com",
AllowedRedirects: []string{"https://app.example.com/dashboard"},
StateKey: stateKey, // 32 bytes
}Signet ships two built-in adapters, Google and GitHub, plus a
generic OIDC provider for any OpenID Connect identity provider. Each implements the
same public OAuthProvider interface, so adding a provider never changes Signet internals.
POST /oauth/start returns the provider authorization URL. GET /oauth/callback
redeems the code, consumes the encrypted single-use state, and redirects to the
allowlisted target with a new session cookie.
The sealed state contains the provider, redirect, verifier, nonce and expiry, is encrypted
with AES-GCM using StateKey, and expires after 10 minutes. It is stored as a single-use
Token digest and consumed on callback.
Failures answer as a JSON error body at the callback URL — an expired state, a provider
error or an account conflict surface there instead of a redirect. When the provider identity
carries an unverified email, the callback still redirects to the allowlisted target and
appends ?link_token=... for explicit linking through LinkOAuthAccount.
Signet issues SameSite=Lax cookies and no CORS headers: keep the browser app and the API on
one origin, or put a reverse proxy on a single origin in front of both. See
Security.
Signet requires PKCE, encrypts and expires the state, and only auto-links a
provider identity when its email is verified. An unverified identity yields a
one-time link token for explicit account linking via LinkOAuthAccount.
A provider Account owned by another User returns ErrOAuthAccountConflict; creation is
rolled back on failure. On a successful OAuth sign-in the redacted OnSignIn hook fires.