Authorize an OAuth App (Beta)
Overview#
This guide steps through implementing Sign-in with Supabase. Once you've added OAuth2.0 support to your main application, you will receive an access and refresh token from your users that choose to Sign in with Supabase on your application.
The access token returned will grant your application full access to the Management API on behalf of the user.
Implement the OAuth 2.0 flow#
Once you've published your OAuth App on Supabase, you can use the OAuth 2.0 protocol to seek consent from Supabase users to access their organization or project.
- Within your app's UI, redirect the user to
https://api.supabase.com/v1/oauth/authorize
. Make sure to include all required query parameters such as:client_id
A UUID uniquely identifying your OAuth app in Supabase.redirect_uri
The URL where Supabase will redirect the user after providing consent.scope
The only scope supported isall
. Scoped access is not available at this time.response_type
The valuecode
.state
Information about the state of your app. Note thatredirect_uri
andstate
cannot both exceed 4kB in size.- We strongly recommend using the PKCE flow for increased security. Generate a random value before taking the user to the authorize endpoint. This value is called code verifier. Hash it with SHA256 and include it as the
code_challenge
parameter, while settingcode_challenge_method
tos256
. In the next step, you would need to provide the code verifier to get the first access and refresh token.
- Once the user consents to providing API access to your OAuth App, Supabase will redirect the user to the
redirect_uri
endpoint you provided in the previous step. The URL will contain these query parameters:code
An authorization code you should exchange with Supabase to get the access and refresh token.state
The value you provided in the previous step, to help you associate the request with the user. Thestate
property returned here should be compared to thestate
you sent previously.
- Exchange the authorization code for an access and refresh token by calling
POST https://api.supabase.com/v1/oauth/token
and including the following query parameters:grant_type
The valueauthorization_code
.code
Thecode
returned in the previous step.client_id
The unique client ID identifying your OAuth App.client_secret
The secret that authenticates your OAuth App to Supabase.redirect_uri
This must be exactly the same URL used in the first step.- If you used the PKCE flow in the first step, include the code verifier as
code_verifier
.
Refresh an access token#
You can use the POST /v1/oauth/token
endpoint to refresh an access token using the refresh token returned at the end of the previous section.
If the user has revoked access to your application, you will not be able to refresh a token. Furthermore, access tokens will stop working. Make sure you handle HTTP Unauthorized errors when calling any Supabase API.
Access the Management API using the access token#
Refer to this section to learn more about authentication with the Management API.