Skip to content

feat: add state parameter support to OAuth provider sign-in#134

Merged
Tr00d merged 2 commits into
masterfrom
guillaumefaas/sdk-1230-missing-oauth2-state-parameter-in-server-side-pkce
Jul 10, 2026
Merged

feat: add state parameter support to OAuth provider sign-in#134
Tr00d merged 2 commits into
masterfrom
guillaumefaas/sdk-1230-missing-oauth2-state-parameter-in-server-side-pkce

Conversation

@Tr00d

@Tr00d Tr00d commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Fixes supabase-community/supabase-csharp#222.

What

SignIn(Provider, options) had no way to include a state parameter in the OAuth URL. Without it, server-side callers had no CSRF protection and were forced to manually append state to the returned URL themselves.

Fix

  • Added State to SignInOptions — callers can provide their own value or leave it unset
  • GetUrlForProvider always includes a state in the URL: the caller-provided value if set, otherwise an auto-generated nonce
  • Added State to ProviderAuthState so the caller gets back whatever was used, ready to store and validate against the OAuth callback

What this doesn't do

State validation is the caller's responsibility — the SDK just ensures the value is in the URL and returned. Storage and comparison against the callback are outside the SDK's scope.

@Tr00d
Tr00d marked this pull request as ready for review July 10, 2026 14:27
Comment thread Gotrue/Helpers.cs
if (attr == null)
throw new Exception("Unknown provider");

var state = !string.IsNullOrEmpty(options.State) ? options.State : GenerateNonce();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TIL that Go doesn't have a keyword for immutable variables that are not known at compile time 🤯

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here. We have the const keyword but for compile-time only, and var just infers the type.
Otherwise, immutability is something you have to address through the type. There's no other way to "enforce" it

@Tr00d
Tr00d merged commit 2de994c into master Jul 10, 2026
1 check passed
@Tr00d
Tr00d deleted the guillaumefaas/sdk-1230-missing-oauth2-state-parameter-in-server-side-pkce branch July 10, 2026 14:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] PKCE flow !server-side state param support, violating OAuth2 spec

2 participants