plugins/social
OAuth 2.0 and OpenID Connect sign-in and sign-up through 19 catalog providers or any other OAuth 2
server; account linking under a policy; Google One Tap; provider tokens on the user’s behalf (stored
encrypted, refreshed when expiring); and an OAuth proxy so preview and local origins sign in through
the stable origin registered at the providers. A sign-in ends in core’s login envelope (amr
["social:<provider>"]) or core’s mfa_required ticket.
Install
Section titled “Install”import "github.com/univeros/polaris.go/plugins/social"
cfg, err := polaris.FromEnv(db, social.New(social.Config{ BaseURL: "https://app.example.com/auth", // where Polaris is mounted, prefix included RedirectURIs: []string{"https://app.example.com/signed-in"}, Providers: map[string]social.Provider{ "google": {ClientID: os.Getenv("GOOGLE_CLIENT_ID"), ClientSecret: os.Getenv("GOOGLE_CLIENT_SECRET")}, "github": {ClientID: os.Getenv("GITHUB_CLIENT_ID"), ClientSecret: os.Getenv("GITHUB_CLIENT_SECRET")}, },}))p, err := polaris.New(cfg) // configuration errors (missing client id, unknown provider, bad Apple key) fail here_, err = p.Migrate(ctx) // creates polaris_social_account; the OAuth state lives in the cacheRegister BaseURL + "/social/<provider>/callback" at each provider.
Providers
Section titled “Providers”social.Catalog: google, apple, microsoft, github, gitlab, discord, facebook, x,
linkedin, slack, twitch, spotify, zoom, notion, dropbox, reddit, kick, tiktok,
huggingface — each needs only social.Provider{ClientID, ClientSecret}, except:
apple:ClientIDplusTeamID,KeyID,PrivateKey(the .p8 PEM) instead ofClientSecret.microsoft: optionalTenant(commondefault,organizations,consumers, a tenant id).- Any OpenID Connect server: any id with
Issuer(discovered at first use), optionalName,Scopes. - Any other OAuth 2 server:
Definition: &social.Definition{AuthorizationURL, TokenURL, UserinfoURL, Profile, …};social.OIDCProfilemaps standard claims.
Config
Section titled “Config”BaseURL, at least one provider and RedirectURIs are required; other zero values are the defaults.
| Field | Default | Purpose |
|---|---|---|
TrustedProviders | nil = google, apple | a verified email from these links to the existing user with that email; empty non-nil list trusts none. Never list a provider whose profile counts any returned email as verified (facebook, x, notion, kick, or such a custom Definition): it would let anyone take over an account by email |
AllowDifferentEmails | none | providers that may be linked with an email other than the account’s |
DisableSignUp | off (sign-up on) | refuse a sign-in that matches no user |
SkipMFA | off (gate on) | let a social sign-in past core’s MFA gate |
Proxy | none | stable origin registered at the providers when this deployment is mounted elsewhere; both share APP_KEY |
StateTTL | 10 min | how long a started sign-in waits for its callback |
HTTPClient | 10-second timeout | talks to the providers; redirects are never followed |
Routes
Section titled “Routes”| Method | Path | Purpose |
|---|---|---|
| POST | /social/{provider}/start | authorization url + state (redirect_uri, scopes optional) |
| GET | /social/{provider}/callback | provider callback; 302 to redirect_uri?code=&state= |
| POST | /social/{provider}/callback | same, response_mode=form_post (Apple) |
| POST | /social/exchange | trade the one-minute code for the login envelope (or {status: linked, account} after a link). The code is not bound to a browser: before exchanging it, check that this browser started a sign-in (a short-lived cookie your page set), or someone can send the redirect with their own code to another person |
| POST | /social/google/one-tap | sign in with a One Tap credential (needs google configured) |
| GET | /social/accounts | bearer: your linked provider accounts |
| POST | /social/{provider}/link | bearer, step-up gated, live session only: start linking a provider to your account; the callback refuses the link when that session has ended since |
| DELETE | /social/{provider} | bearer, step-up gated: unlink (refused if it is your last credential) |
| POST | /social/{provider}/token | bearer, step-up gated: the provider access token, refreshed first if expiring |
Compare the returned state with the one start answered before exchanging the code. The
authorization url carries its parameters form-encoded (RFC 6749 §4.1.1: a space is +).
Timestamps (created_at, updated_at, expires_at) are RFC 3339 in UTC (2026-11-20T18:32:59Z).
An id_token must name its key (kid) in the provider’s JWKS (keys an array, RFC 7517). The
key’s alg must be the token’s; a key without alg verifies the algorithm its type implies (RSA
RS256, EC P-256 ES256, OKP Ed25519 EdDSA) and any other key without alg verifies nothing. A
provider’s subject is its id as a string or a JSON number; a boolean or null names no account.
Events and permissions
Section titled “Events and permissions”Dispatches social.Event named social.EventSignedIn, EventSignedUp, EventLinked,
EventUnlinked, EventTokenRefreshed, EventRejected (social.*), plus core’s user.logged_in.
With plugins/audit registered they become audit rows (Plugin.AuditNames). No permissions.
Problems
Section titled “Problems”https://polaris.univeros.io/problems/social/ + provider_not_found (404), redirect_not_allowed,
state_invalid, token_invalid, email_required, code_invalid, invalid_input (422),
provider_error, account_disabled, email_unverified (403), account_exists, account_linked,
email_mismatch, last_credential, no_refresh (409), not_linked (404).
An email the provider does not vouch for
Section titled “An email the provider does not vouch for”A provider that returns an address without saying it verified it (email_verified false or
missing) proves nothing about who owns the mailbox, so nothing is created in that address’s name:
- with
Auth.Flows.RequireVerifiedEmailon (the default), the sign-up answersemail_unverifiedand leaves no account and no link behind. The person signs up with the address another way (registration, an email code) and links the provider from their account; - with it off, the account is created unverified and signs in. When someone later proves the
mailbox (a verification link on an account without a password, a password reset, an email code or
magic link, a trusted provider, SSO), that first proof removes the provider link with everything
else that could sign in before it (
Identity.ProveEmail); the owner links the provider again from their account.
A trusted provider’s verified email linking to an unverified account is such a first proof: the password, factors, passkeys, keys, other providers’ links and sessions of the unproven account go.
Host integration
Section titled “Host integration”- Social works without audit. Erasing a user deletes its provider accounts (email, profile,
tokens) inside the erasure’s transaction (
wiring.AccessEraser). - Unlinking checks for the last credential and deletes in one transaction with the user’s row locked, so concurrent unlinks cannot leave an account without a way to sign in. A flow completes only in the browser that started it (a binding cookie, decision 39).
Example
Section titled “Example”Example in example_test.go — go doc github.com/univeros/polaris.go/plugins/social.