Skip to content

OAuth Providers

Supatype supports sign-in with third-party OAuth providers. Users are redirected to the provider, authenticate there, and are redirected back to your app with a session.

Supported providers

ProviderKeyNotes
GitHubgithubDefault scope: user:email. url for GitHub Enterprise
GooglegoogleDefault scopes: email, profile
AppleappleRequires Apple Developer account
DiscorddiscordDefault scopes: email, identify
TwittertwitterOAuth 1.0a. Use x for X’s OAuth 2.0
GitLabgitlaburl for a self-hosted GitLab
Bitbucketbitbucket
MicrosoftazureThe multi-tenant common endpoint unless url names a tenant
Slackslackslack_oidc for Sign in with Slack (OIDC)

The full list of keys is under Configure the provider. Scopes you pass to signInWithOAuth are added to a provider’s defaults.

Setup

1. Create an OAuth app with the provider

Each provider requires you to register an OAuth application and obtain a Client ID and Client Secret.

Callback URL. Register your project’s API URL followed by /auth/v1/callback in the provider’s OAuth app settings, and use the same URL as the redirect URI below:

<API URL>/auth/v1/callback
  • Local development (Docker): http://localhost:<gateway port>/auth/v1/callback. The gateway port is SUPATYPE_KONG_PORT in .env (18473 unless init picked another).
  • Self-host: your public API URL, the API_EXTERNAL_URL in the stack’s .env, for example https://api.example.com/auth/v1/callback.

2. Configure the provider

Supatype Cloud does not yet pass OAuth provider settings to a project’s auth server, and Studio shows providers read-only, so configure providers on local development or self-host.

Declare the provider in supatype.config.ts. supatype dev and supatype self-host compose turn it into the SUPATYPE_EXTERNAL_<PROVIDER>_* variables the auth server reads:

// docs:no-check (a fragment: the rest of your config stays as it is)
import { defineConfig, env } from "@supatype/cli"
export default defineConfig({
auth: {
providers: {
github: { clientId: "Iv1.0123456789abcdef", secret: env("GITHUB_SECRET") },
google: { clientId: env("GOOGLE_CLIENT_ID"), secret: env("GOOGLE_SECRET") },
},
},
})
.env
GITHUB_SECRET=...
GOOGLE_CLIENT_ID=...
GOOGLE_SECRET=...
  • Secrets are env("NAME") only. A literal secret is rejected: the config is committed, and the generated compose file names the variable rather than holding the value.
  • The redirect URI defaults to your public API URL followed by /auth/v1/callback. Set redirectUri only when the public URL differs, and register the same URL with the provider.
  • Other fields: enabled (default true), url for self-hosted providers (GitHub Enterprise, GitLab, Keycloak, WorkOS), skipNonceCheck, emailOptional.
  • Provider names are the ones signInWithOAuth({ provider }) takes: apple, azure, bitbucket, discord, facebook, figma, fly, github, gitlab, google, kakao, keycloak, linkedin, linkedin_oidc, notion, slack, slack_oidc, snapchat, spotify, twitch, twitter, vercel_marketplace, workos, x, zoom.
  • supatype dev warns when an enabled provider’s secret is set nowhere.

.env wins over the config. A SUPATYPE_EXTERNAL_<PROVIDER>_* value in .env overrides what the config would write, so a project configured through .env alone keeps working. A provider configured only in .env gets no default redirect URI: set its own SUPATYPE_EXTERNAL_<PROVIDER>_REDIRECT_URI, or the provider sends users back to a path that answers 404:

Terminal window
SUPATYPE_EXTERNAL_GITHUB_ENABLED=true
SUPATYPE_EXTERNAL_GITHUB_CLIENT_ID=your-client-id
SUPATYPE_EXTERNAL_GITHUB_SECRET=your-client-secret
SUPATYPE_EXTERNAL_GITHUB_REDIRECT_URI=<your API URL>/auth/v1/callback

Your API URL is API_EXTERNAL_URL in .env: under Docker, the project’s gateway (http://localhost: and its SUPATYPE_KONG_PORT); with the native provider, the server itself (http://localhost:18471 unless you set server.port).

3. Trigger the OAuth flow

const { data, error } = await supatype.auth.signInWithOAuth({
provider: "github",
options: {
redirectTo: "https://myapp.com/auth/callback",
scopes: "read:org",
},
})
if (error) {
// For example provider_disabled: the auth server lists this provider as off
console.error(error.message)
} else {
// Redirect the user to the provider
window.location.href = data.url
}

redirectTo must be on the same host as the site URL, on a loopback address, or match the auth server’s redirect allow list (SUPATYPE_URI_ALLOW_LIST); otherwise the user is sent to the site URL instead.

4. Handle the callback

The provider sends the user back to your redirectTo URL with the session in it. In a browser the client finishes the sign-in itself as it starts: it reads the tokens from the URL hash (or exchanges ?code= when you used flowType: "pkce"), emits SIGNED_IN and removes the parameters from the address bar. On your callback page, wait for that and check the result:

// On /auth/callback
const { error } = await supatype.auth.initialize()
const { data: { session } } = await supatype.auth.getSession()
if (error) {
console.error(`Sign-in with ${error.provider ?? "the provider"} failed:`, error.message)
} else if (session) {
// User is signed in
window.location.assign("/dashboard")
}

With detectSessionInUrl: false in the client’s auth options, or outside a browser (a React Native deep link), the client leaves the URL alone: call supatype.auth.getSessionFromUrl(url) with the callback URL instead.

Provider-specific setup

GitHub

  1. Go to GitHub Developer Settings
  2. Create a new OAuth App
  3. Set the callback URL to your Supatype callback URL
  4. Copy the Client ID and Client Secret

Google

  1. Go to Google Cloud Console
  2. Create an OAuth 2.0 Client ID
  3. Add your callback URL to Authorized redirect URIs
  4. Copy the Client ID and Client Secret

Apple

  1. Go to Apple Developer Portal
  2. Register a Services ID
  3. Configure Sign in with Apple with your callback URL
  4. Generate a client secret key

Custom OAuth and OIDC providers

A provider not in the list above (an internal identity provider, a GitHub Enterprise or Keycloak you would rather not configure through the built-in key) can be registered as a custom provider at runtime, without a restart. The auth server must have SUPATYPE_CUSTOM_OAUTH_ENABLED=true (SUPATYPE_CUSTOM_OAUTH_MAX_PROVIDERS caps how many; 0 is no cap). Providers are managed with the service role key through the admin API:

RequestDoes
GET /auth/v1/admin/custom-providerslists them (?type=oauth2 or ?type=oidc to filter)
POST /auth/v1/admin/custom-providersregisters one
GET, PUT, DELETE /auth/v1/admin/custom-providers/custom:<name>reads, changes or removes one

A provider’s identifier must start with custom: (custom:acme), and provider_type is oauth2 (give authorization_url, token_url and userinfo_url) or oidc (give issuer, and optionally discovery_url). Both take name, client_id, client_secret and scopes. Sign in with it by its identifier: signInWithOAuth({ provider: "custom:acme" }).

Callback URL. A custom provider sends the browser back to the same path as the built-in ones, so register this with the identity provider:

<API URL>/auth/v1/callback

The auth server builds it from its external URL (API_EXTERNAL_URL on self-host), adding /auth/v1 unless the URL already ends with it. Before 0.7.0 a custom provider was given <API URL>/callback, which is not an auth route, so sign-in ended in a 404: if you registered that URL with an identity provider, change it to the one above.

Linking accounts

If a user signs in with OAuth and an account with the same email already exists (from email/password sign-up), the auth server links the new identity to that account automatically, provided the provider reports the email as verified (or the server auto-confirms emails, which local dev does unless auth.email.enableConfirmations is true, and a self-hosted stack does only when it is false). Linking happens on every such sign-in, and supatype.config.ts has no key to turn it off. The user’s identities list then holds one entry per provider.