-
Notifications
You must be signed in to change notification settings - Fork 493
feat(stack): typed external OAuth providers and redirect allow list #5816
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
martijnwalraven
wants to merge
3
commits into
supabase:develop
Choose a base branch
from
martijnwalraven:callboard/auth-external-providers
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
eda79bd
feat(stack): typed external OAuth providers and redirect allow list
martijnwalraven 5ee3902
fix(stack): treat empty external redirect_uri as unset, always emit URL
martijnwalraven 8aa9ad2
fix(stack): pin auth externalUrl to the gateway path, derive callback…
martijnwalraven File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,125 @@ | ||
| import { describe, expect, test } from "vitest"; | ||
| import { makeAuthServiceDocker, makeAuthServiceNative } from "./auth.ts"; | ||
|
|
||
| const baseOptions = { | ||
| dbPort: 54322, | ||
| authPort: 54324, | ||
| siteUrl: "http://localhost:3000", | ||
| jwtSecret: "super-secret-jwt-token-with-at-least-32-characters-long", | ||
| jwtExpiry: 3600, | ||
| externalUrl: "http://127.0.0.1:54321/auth/v1", | ||
| dependencies: [], | ||
| }; | ||
|
|
||
| describe("auth external providers", () => { | ||
| // The contract: `external` is the typed surface for GoTrue OAuth | ||
| // providers, translated to GOTRUE_EXTERNAL_<ID>_* env the way the | ||
| // classic CLI translates [auth.external.*]. | ||
| test("native: a declared provider enables with the issuer-derived redirect", () => { | ||
| const def = makeAuthServiceNative({ | ||
| ...baseOptions, | ||
| binPath: "/opt/supabase", | ||
| external: { google: { clientId: "client-id", secret: "client-secret" } }, | ||
| }); | ||
|
|
||
| expect(def.env).toMatchObject({ | ||
| GOTRUE_EXTERNAL_GOOGLE_ENABLED: "true", | ||
| GOTRUE_EXTERNAL_GOOGLE_CLIENT_ID: "client-id", | ||
| GOTRUE_EXTERNAL_GOOGLE_SECRET: "client-secret", | ||
| GOTRUE_EXTERNAL_GOOGLE_REDIRECT_URI: "http://127.0.0.1:54321/auth/v1/callback", | ||
| // Defaults survive beside the provider translation. | ||
| GOTRUE_SITE_URL: "http://localhost:3000", | ||
| }); | ||
| // Defaults emit explicitly, url's empty string included: native | ||
| // spawns extend the parent env, so an omitted var would inherit the | ||
| // shell's value (GoTrue reads an empty URL as its provider default). | ||
| expect(def.env).toMatchObject({ | ||
| GOTRUE_EXTERNAL_GOOGLE_URL: "", | ||
| GOTRUE_EXTERNAL_GOOGLE_SKIP_NONCE_CHECK: "false", | ||
| GOTRUE_EXTERNAL_GOOGLE_EMAIL_OPTIONAL: "false", | ||
| }); | ||
| }); | ||
|
|
||
| test("docker: explicit fields reach the container args; enabled=false stays declared", () => { | ||
| const def = makeAuthServiceDocker({ | ||
| ...baseOptions, | ||
| image: "supabase/gotrue:test", | ||
| dbHost: "127.0.0.1", | ||
| networkArgs: [], | ||
| apiPort: 54321, | ||
| external: { | ||
| github: { | ||
| enabled: false, | ||
| clientId: "gh-id", | ||
| secret: "gh-secret", | ||
| redirectUri: "http://example.test/cb", | ||
| url: "https://ghe.example.test", | ||
| skipNonceCheck: true, | ||
| }, | ||
| }, | ||
| }); | ||
|
|
||
| const args = def.args ?? []; | ||
| expect(args).toContain("GOTRUE_EXTERNAL_GITHUB_ENABLED=false"); | ||
| expect(args).toContain("GOTRUE_EXTERNAL_GITHUB_CLIENT_ID=gh-id"); | ||
| expect(args).toContain("GOTRUE_EXTERNAL_GITHUB_SECRET=gh-secret"); | ||
| expect(args).toContain("GOTRUE_EXTERNAL_GITHUB_REDIRECT_URI=http://example.test/cb"); | ||
| expect(args).toContain("GOTRUE_EXTERNAL_GITHUB_URL=https://ghe.example.test"); | ||
| expect(args).toContain("GOTRUE_EXTERNAL_GITHUB_SKIP_NONCE_CHECK=true"); | ||
| }); | ||
|
|
||
| test("a secretless provider emits an empty secret, like the classic CLI", () => { | ||
| const def = makeAuthServiceNative({ | ||
| ...baseOptions, | ||
| binPath: "/opt/supabase", | ||
| external: { apple: { clientId: "apple-id" } }, | ||
| }); | ||
|
|
||
| expect(def.env).toMatchObject({ | ||
| GOTRUE_EXTERNAL_APPLE_ENABLED: "true", | ||
| GOTRUE_EXTERNAL_APPLE_SECRET: "", | ||
| }); | ||
| }); | ||
|
|
||
| test("empty redirectUri and url mean unset, like the classic surface", () => { | ||
| // The generated config.toml template ships redirect_uri = "" and | ||
| // url = "" — TOML strings can't be absent — and start.go substitutes | ||
| // the derived callback for an empty redirect_uri. The URL var still | ||
| // emits (empty = GoTrue's provider default) so a shell variable can | ||
| // never supply it under native-mode env extension. | ||
| const def = makeAuthServiceNative({ | ||
| ...baseOptions, | ||
| binPath: "/opt/supabase", | ||
| external: { | ||
| gitlab: { clientId: "gl-id", secret: "gl-secret", redirectUri: "", url: "" }, | ||
| }, | ||
| }); | ||
|
|
||
| expect(def.env).toMatchObject({ | ||
| GOTRUE_EXTERNAL_GITLAB_REDIRECT_URI: "http://127.0.0.1:54321/auth/v1/callback", | ||
| GOTRUE_EXTERNAL_GITLAB_URL: "", | ||
| }); | ||
| }); | ||
|
|
||
| test("no external config adds no provider env", () => { | ||
| const def = makeAuthServiceNative({ ...baseOptions, binPath: "/opt/supabase" }); | ||
| const providerKeys = Object.keys(def.env ?? {}).filter( | ||
| (key) => key.startsWith("GOTRUE_EXTERNAL_") && key !== "GOTRUE_EXTERNAL_EMAIL_ENABLED", | ||
| ); | ||
| expect(providerKeys).toEqual([]); | ||
| // Empty but present: [] must mean "no extra redirects", not "whatever | ||
| // the parent shell says". | ||
| expect(def.env).toMatchObject({ GOTRUE_URI_ALLOW_LIST: "" }); | ||
| }); | ||
|
|
||
| test("additional redirect urls translate to the comma-joined allow list", () => { | ||
| const def = makeAuthServiceNative({ | ||
| ...baseOptions, | ||
| binPath: "/opt/supabase", | ||
| additionalRedirectUrls: ["http://localhost:3000", "https://app.example.test"], | ||
| }); | ||
| expect(def.env).toMatchObject({ | ||
| GOTRUE_URI_ALLOW_LIST: "http://localhost:3000,https://app.example.test", | ||
| }); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When callers rely on the new optional
secretfield,enabledstill defaults to true, soauth: { external: { google: { clientId } } }starts GoTrue withGOTRUE_EXTERNAL_GOOGLE_ENABLED=trueand an empty secret. The current auth service used by the stack rejects enabled OAuth providers with an empty secret inValidateOAuth, so the advertised secretless provider path fails at/authorize; require a secret for enabled providers or avoid enabling them when it is omitted.Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one matches GoTrue's intended model, so the surface stays as is (with a sharper doc comment in 8aa9ad2): the secretless path isn't
/authorize— it's the id-token grant (google one-tap, sign-in with apple), which reads the provider config directly intoken_oidc.goand never callsValidateOAuth, so no secret is needed there. That's also why the config package's own schema exempts exactlyappleandgooglefrom its enabled-requires-secret check, and the classic CLI emits an empty secret the same way. For flows that do need a secret, GoTrue refuses loudly at/authorize("missing OAuth secret") — identical to classic behavior. Requiring a secret here would break id-token-only configurations upstream itself supports, and auto-disabling would silently turn off a provider the caller declared; provider-specific validation stays with the config layer (which has it) and GoTrue (which enforces it at request time).