Skip to Content
FeaturesIntegrationsOAuthFrontend Integration

OAuth Frontend Integration

The login screen asks GET /cfg/accounts/oauth/providers/ and shows exactly the enabled providers. Each button calls POST oauth/<provider>/authorize/, stores the returned state in sessionStorage and redirects the page. The site’s /auth?provider=<id>&code&state page posts the code to oauth/<provider>/callback/ and finishes like an email-code login (2FA hand-off, saved return URL).

The package APIs (useAuthForm, AuthLayout, the callback component) are described in Accounts frontend. Backend contract and error codes: OAuth sign-in.

Buttons and branding

AuthLayout renders the buttons itself, providers first, then “or”, then the email field. No prop is needed: the list comes from the server. The optional oauthProviders prop only narrows it. A failed list request is retried twice (1s, 2s) before the screen settles on the email form alone, so a flaky mobile connection does not hide the buttons; the form holds their room meanwhile. Every provider button looks the same (one component, theme tokens, light and dark; only the mark and the name differ, and the Google “G” keeps its own colours); button text and error messages are translated in all 17 shipped locales. enableGithubAuth is deprecated and does nothing. Hook API: useOAuthLogin.

When a sign-in fails

The visitor is never stuck on a blocking card. The page returns to the normal sign-in form with a small dismissible notice (close button or Escape) and at most one next step:

CodeNoticeButton
Cancelled on the provider’s pagenonenone
link_not_allowed (staff or superuser address)“Use the email code for this address”none (the email field takes focus)
Expired link, exchange failed, provider down, unknownone short sentenceTry Google again
email_missing, email_not_verified, hosted_domain_not_allowedone sentencenone (the email field takes focus)
account_inactive, rate_limitedone sentencenone
origin_not_allowed, missing_redirect_uri, oauth_disabled (site not set up for the provider)“not available on this site”none (the email field takes focus)

The notice has one fixed layout for every code (icon, text, close button on the first line, close hit area 32px) and never a button for email: the field is already below it.

For origin_not_allowed the notice adds a small line for developers: which origin the backend refused, and the redirect URI to register at the provider (<origin>/auth?provider=<id>). Add the origin to the Django site’s origins; see Sites.

GitHub uses the same flow. The ?provider=&code=&state= parameters are removed from the address bar first, and a repeated render (React strict mode) never repeats the exchange.

Troubleshooting

SymptomCauseFixCheck
Provider buttons and the “or” divider are missing, only the email form showsThe provider list request failed even after its two retries (offline, gateway 502, CORS or origin_not_allowed on oauth/providers/), or no provider is enabled for the siteOpen the network tab: GET /cfg/accounts/oauth/providers/ must answer 200 with providers; fix the API host, CORS or the provider settingsThe same page on another network shows the buttons
Last updated on