The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
fix(docs): Fix Oauth docs and code to use redirect_url (#45966)
Timothy Lim0884060914ca
diff --git a/apps/docs/content/guides/auth/oauth-server/getting-started.mdx b/apps/docs/content/guides/auth/oauth-server/getting-started.mdxindex 5304c8cbb74..1d40792deaf 100644--- a/apps/docs/content/guides/auth/oauth-server/getting-started.mdx+++ b/apps/docs/content/guides/auth/oauth-server/getting-started.mdx@@ -238,6 +238,11 @@ export default async function ConsentPage({return <div>Error: {error?.message || 'Invalid authorization request'}</div>}+ // if no authorization_id returned, user has previously consented, redirect them+ if (!('authorization_id' in authDetails)) {+ redirect(authDetails['redirect_url'])+ }+return (<div><h1>Authorize {authDetails.client.name}</h1>@@ -313,7 +318,7 @@ export async function POST(request: Request) {}// Redirect back to the client with authorization code- return NextResponse.redirect(data.redirect_to)+ return NextResponse.redirect(data.redirect_url)} else {const { data, error } = await supabase.auth.oauth.denyAuthorization(authorizationId)@@ -322,7 +327,7 @@ export async function POST(request: Request) {}// Redirect back to the client with error- return NextResponse.redirect(data.redirect_to)+ return NextResponse.redirect(data.redirect_url)}}```@@ -388,7 +393,7 @@ export function OAuthConsent() {setError(error.message)} else {// Redirect to client app- window.location.href = data.redirect_to+ window.location.href = data.redirect_url}}@@ -401,7 +406,7 @@ export function OAuthConsent() {setError(error.message)} else {// Redirect to client app with error- window.location.href = data.redirect_to+ window.location.href = data.redirect_url}}@@ -455,8 +460,8 @@ export function OAuthConsent() {6. **Handle decision** - When the user clicks approve/deny:- Call `supabase.auth.oauth.approveAuthorization(authorization_id)` or `denyAuthorization(authorization_id)`- These methods handle all OAuth logic internally (generating authorization codes, etc.)- - They return a `redirect_to` URL-7. **Redirect back** - Redirect the user to the `redirect_to` URL, which sends them back to the third-party app with either an authorization code (approved) or error (denied)+ - They return a `redirect_url` URL+7. **Redirect back** - Redirect the user to the `redirect_url` URL, which sends them back to the third-party app with either an authorization code (approved) or error (denied)## Register an OAuth clientdiff --git a/apps/docs/content/guides/auth/oauth-server/oauth-flows.mdx b/apps/docs/content/guides/auth/oauth-server/oauth-flows.mdxindex ec39a958843..04291fe8018 100644--- a/apps/docs/content/guides/auth/oauth-server/oauth-flows.mdx+++ b/apps/docs/content/guides/auth/oauth-server/oauth-flows.mdx@@ -56,7 +56,7 @@ Here's a visual representation of the complete authorization code flow:│ (code_verifier, code_challenge) ││ │ ││ 2. Redirect to /oauth/authorize with code_challenge │- ├────────────────────────────────────────────────────────────────>│+ ├───────────────────────────────────────────────────────────────>││ │ ││ │ 3. Validate params & redirect ││ │ to authorization_path │@@ -71,7 +71,7 @@ Here's a visual representation of the complete authorization code flow:│ │ ││ │ 6. approveAuthorization() ││ ├────────────────────────────────>│- │ │ Return redirect_to with code │+ │ │ Return redirect_url with code ││ │<────────────────────────────────┤│ │ ││ 7. Redirect to client callback with code │@@ -79,18 +79,18 @@ Here's a visual representation of the complete authorization code flow:│ │ ││ 8. Exchange code for tokens (POST /oauth/token) ││ with code_verifier │- ├────────────────────────────────────────────────────────────────>│+ ├───────────────────────────────────────────────────────────────>││ │ ││ 9. Return tokens (access, refresh, ID) │- │<────────────────────────────────────────────────────────────────┤+ │<───────────────────────────────────────────────────────────────┤│ │ ││ 10. Access resources with access_token ││ │ ││ 11. Refresh tokens (POST /oauth/token with refresh_token) │- ├────────────────────────────────────────────────────────────────>│+ ├───────────────────────────────────────────────────────────────>││ │ ││ 12. Return new tokens │- │<────────────────────────────────────────────────────────────────┤+ │<───────────────────────────────────────────────────────────────┤│ │ │```@@ -189,7 +189,7 @@ Your frontend application at the authorization path should:5. **Handle user decision** - When the user approves or denies:- Call `supabase.auth.oauth.approveAuthorization(authorization_id)` to approve- Call `supabase.auth.oauth.denyAuthorization(authorization_id)` to deny- - Redirect user to the returned `redirect_to` URL+ - Redirect user to the returned `redirect_url` URLThis is a **frontend implementation** using `supabase-js`. Supabase Auth handles all the backend OAuth logic (generating authorization codes, validating requests, etc.) after you call the approve/deny methods.