Skip to content
This repository has been archived by the owner on May 13, 2023. It is now read-only.

feat: add pkce flow support #135

Merged
merged 30 commits into from
May 3, 2023
Merged

feat: add pkce flow support #135

merged 30 commits into from
May 3, 2023

Conversation

dshukertjr
Copy link
Member

@dshukertjr dshukertjr commented Apr 4, 2023

What kind of change does this PR introduce?

PKCE flow is a secure way of performing OAuth on a mobile app. Specifically, it prevents attacker from performing authorization code interception attack.

The GotrueClient can now be initialized with a flowType parameter, which can take value of AuthFlowType.implicit or AuthFlowType.pkce. When setting the flowType to pkce, asyncStorage also needs to be provided, which is used to store the pkce code verifier (essentially a randomly generated string).

final gotrueClient = GoTrueClient(
  url: gotrueUrl,
  flowType: AuthFlowType.pkce,
  asyncStorage: TestAsyncStorage(),
);

When GotrueClient is initialized with flowType of pkce, a codeChallenge will be passed as query parameters for sign-in flows that involve deep links, such as magic link sign in or OAuth. Once the user comes back to the app via deep link, no access token or refresh token is contained in the URL, but instead there is the code challenge. The client then sends the code verifier and the code challenge via exchangeCodeForSession() method to the Gotrue server to verify it, and returns a session securely.

The process of calling the exchangeCodeForSession() method will be handled automatically in the background by supabase_flutter just like it does for the current deep link handling.

In future major version update, we will remove implicit grant flow and use pkce for all OAuth logins.

Once this PR is merged, these PRs on supabase-dart and supabase-flutter will be merged.

Related gotrue-js PRs

@dshukertjr dshukertjr marked this pull request as ready for review April 28, 2023 07:39
lib/src/gotrue_client.dart Show resolved Hide resolved
lib/src/gotrue_client.dart Outdated Show resolved Hide resolved
@dshukertjr dshukertjr requested a review from Vinzent03 May 3, 2023 03:49
Copy link
Contributor

@Vinzent03 Vinzent03 left a comment

Choose a reason for hiding this comment

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

Some more tests would be useful, but they are hard to implement, right?

@dshukertjr
Copy link
Member Author

Yeah, since it involves a redirect, it's kind of hard to do a through testing.

@dshukertjr dshukertjr merged commit a0125a7 into main May 3, 2023
4 checks passed
@dshukertjr dshukertjr deleted the pkce branch May 3, 2023 07:54
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants