Skip to content

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.

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 cache

Register BaseURL + "/social/<provider>/callback" at each provider.

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: ClientID plus TeamID, KeyID, PrivateKey (the .p8 PEM) instead of ClientSecret.
  • microsoft: optional Tenant (common default, organizations, consumers, a tenant id).
  • Any OpenID Connect server: any id with Issuer (discovered at first use), optional Name, Scopes.
  • Any other OAuth 2 server: Definition: &social.Definition{AuthorizationURL, TokenURL, UserinfoURL, Profile, …}; social.OIDCProfile maps standard claims.

BaseURL, at least one provider and RedirectURIs are required; other zero values are the defaults.

FieldDefaultPurpose
TrustedProvidersnil = google, applea 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
AllowDifferentEmailsnoneproviders that may be linked with an email other than the account’s
DisableSignUpoff (sign-up on)refuse a sign-in that matches no user
SkipMFAoff (gate on)let a social sign-in past core’s MFA gate
Proxynonestable origin registered at the providers when this deployment is mounted elsewhere; both share APP_KEY
StateTTL10 minhow long a started sign-in waits for its callback
HTTPClient10-second timeouttalks to the providers; redirects are never followed
MethodPathPurpose
POST/social/{provider}/startauthorization url + state (redirect_uri, scopes optional)
GET/social/{provider}/callbackprovider callback; 302 to redirect_uri?code=&state=
POST/social/{provider}/callbacksame, response_mode=form_post (Apple)
POST/social/exchangetrade 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-tapsign in with a One Tap credential (needs google configured)
GET/social/accountsbearer: your linked provider accounts
POST/social/{provider}/linkbearer, 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}/tokenbearer, 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.

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.

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).

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.RequireVerifiedEmail on (the default), the sign-up answers email_unverified and 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.

  • 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 in example_test.go — go doc github.com/univeros/polaris.go/plugins/social.