Learn how to set up Dub OAuth applications to authenticate users with OAuth 2.0.
Create an OAuth2 application in Dub
Redirect users to authorization URL
Property | Description |
---|---|
client_id | The client ID of your OAuth application. |
redirect_uri | The URL to redirect the user to after they authorize the application. Make sure this URL is registered in your OAuth application. |
response_type | Expected response type. It should be code . |
scope | A space separated list of scopes that you want to request access to. Read more about scopes here. |
state | The state parameter to prevent against CSRF attacks. Read more about it here |
Exchange code for an access token
code
parameter is returned in the query string when the user is redirected back to your application. You can exchange this code for an access token by making a POST request to the Dub OAuth token URL.Content-Type
header should be set to application/x-www-form-urlencoded
.Property | Description |
---|---|
code | The code you received when the user was redirected back to your application. |
client_id | The client ID of your OAuth application. |
client_secret | The client secret of your OAuth application. |
redirect_uri | The same redirect URI you used in the authorization URL. |
grant_type | The grant type. It should be authorization_code . |
client_secret
cannot be hidden.With PKCE, the client_secret
is never sent to the authorization server, preventing the client_secret
from being leaked from the client application.Instead of using the client_secret
, you will need to generate a code_verifier
and code_challenge
and use them to exchange for an access token.For example Dub Raycast extension uses PKCE to authenticate users.Make an API request with the access token
Authorization: Bearer <ACCESS_TOKEN>
Refresh the access token
expires_in
value. Dub will respond with 401 Unauthorized
if you try to use an expired access token.To refresh the access token, you need to make a POST request to the Dub OAuth token URL with the refresh_token
you obtained when exchanging the code for an access_token
.Content-Type
header should be set to application/x-www-form-urlencoded
.Property | Description |
---|---|
client_id | The client ID of your OAuth application. |
client_secret | The client secret of your OAuth application. |
grant_type | The grant type. It should be refresh_token . |
refresh_token | The refresh token you received when exchanging the code for an access token. |
Scope | Description |
---|---|
workspaces.read | Read access to workspaces. |
workspaces.write | Write access to workspaces. |
links.read | Read access to links. |
links.write | Write access to links. |
tags.read | Read access to tags. |
tags.write | Write access to tags. |
analytics.read | Read access to analytics. |
domains.read | Read access to domains. |
domains.write | Write access to domains. |
user.read | Read access to user information. This scope is included by default. |