Skip to main content

Command Palette

Search for a command to run...

Security

OAuth Applications

An OAuth application lets software you build act for a Cursor user with that user's consent. The user approves a set of scopes on a Cursor consent page, and your application receives an access token limited to those scopes. No one shares a password or an API key.

Cursor uses the OAuth 2.0 authorization code flow with PKCE. Team admins register applications on the OAuth Applications page of the dashboard.

Use an OAuth application when the user is at your application and you store a client secret.

Register an application

1

Start a new application

On the OAuth Applications page, select New application.

2

Enter the details

Give the application a Name. Users see it on the consent screen, along with the optional Logo. Under Redirect URIs, add each URI that can receive an authorization response.

3

Choose scopes

Select the scopes the application can request. Choose the smallest set that works.

4

Create and store the credentials

Select Create application. Copy the Client ID and the client secret into your secret manager. Client IDs start with oauth_client_.

Redirect URIs

Cursor sends authorization responses only to a URI that exactly matches one on the list.

  • An application can have up to 10 redirect URIs.
  • Each must be an absolute HTTPS URL. HTTP is allowed for localhost during development.
  • A URI can't contain credentials or a fragment.

Scopes

Scopes fall into three groups, by whose resources they reach:

GroupAccess
Personal accountResources owned by the person who authorizes the application.
TeamsOnly the teams the person explicitly selects during authorization.
OrganizationsOnly the organizations the person explicitly selects during authorization.

A user must hold every requested permission before they can approve access. An application can't use consent to gain access its user doesn't have. Most API key permissions are available as scopes. Five aren't: Run Cloud Agents, Use Grok Bot, Sign in to the Cursor CLI and SDK, View model access, and Manage model access.

Authorize a user

The flow has three steps: send the user to Cursor, receive a code, and exchange the code for tokens.

Loading diagram...

1. Request authorization

Create a PKCE code verifier of 43 to 128 characters and its S256 code challenge. Then send the user's browser to the authorization endpoint:

https://cursor.com/oauth/authorize  ?response_type=code  &client_id=YOUR_CLIENT_ID  &redirect_uri=https%3A%2F%2Fapp.example.com%2Fcallback  &scope=agent%3A%2A  &state=RANDOM_STATE  &code_challenge=YOUR_CODE_CHALLENGE  &code_challenge_method=S256
ParameterRequiredDescription
response_typeYesMust be code.
client_idYesThe application's client ID.
redirect_uriYesMust exactly match a registered redirect URI.
scopeYesSpace-separated scopes. Each must be one the application is registered for.
stateYesAn unguessable value that you check when the user returns.
code_challengeYesThe PKCE challenge derived from your code verifier.
code_challenge_methodYesMust be S256.

The example requests agent:*, the scope for Run agents on a personal account.

2. Receive the code

The user signs in to Cursor and sees a consent screen with the application's name, logo, and requested scopes. For team scopes, the user chooses which teams to include.

When the user approves, Cursor redirects to your redirect_uri with code and state. When the user declines, the redirect carries error=access_denied. Check that state matches the value you sent before you continue.

The authorization code expires after 5 minutes and works once.

3. Exchange the code for tokens

Send the code and your code verifier to the token endpoint from your server. The request is form-encoded.

curl -X POST https://api2.cursor.sh/oauth/applications/token \  -u "YOUR_CLIENT_ID:YOUR_CLIENT_SECRET" \  -d grant_type=authorization_code \  -d code=AUTHORIZATION_CODE \  -d code_verifier=YOUR_CODE_VERIFIER \  --data-urlencode "redirect_uri=https://app.example.com/callback"
{  "access_token": "ACCESS_TOKEN",  "token_type": "Bearer",  "expires_in": 3600,  "refresh_token": "REFRESH_TOKEN",  "scope": "agent:*"}

Authenticate the client with HTTP Basic, as shown, or send client_id and client_secret in the form body. Don't send both.

Send the access token as a Bearer token on API requests:

curl https://api.cursor.com/v1/agents \  -H "Authorization: Bearer ACCESS_TOKEN"

Refresh an access token

Access tokens last 1 hour. Use the refresh token to get a new one.

curl -X POST https://api2.cursor.sh/oauth/applications/token \  -u "YOUR_CLIENT_ID:YOUR_CLIENT_SECRET" \  -d grant_type=refresh_token \  -d refresh_token=REFRESH_TOKEN

Each refresh returns a new refresh token and retires the old one. Store the new token every time. A retired refresh token can't be used again. The request fails with invalid_grant.

CredentialLifetime
Authorization code5 minutes, single use
Access token1 hour
Refresh token90 days without a successful refresh, and never more than 365 days after consent

When the refresh token expires, send the user through authorization again.

Check or revoke a token

To check whether a token is still active, call the introspection endpoint:

curl -X POST https://api2.cursor.sh/oauth/introspect \  -u "YOUR_CLIENT_ID:YOUR_CLIENT_SECRET" \  -d token=ACCESS_TOKEN
{  "active": true,  "client_id": "YOUR_CLIENT_ID",  "token_type": "Bearer",  "scope": "agent:*",  "exp": 1767229200,  "sub": "USER_SUBJECT"}

sub is the account subject identifier of the user who approved access. An expired, revoked, or unknown token returns {"active": false}.

To revoke a token when a user disconnects your application, call the revocation endpoint. It returns 200 with an empty object.

curl -X POST https://api2.cursor.sh/oauth/revoke \  -u "YOUR_CLIENT_ID:YOUR_CLIENT_SECRET" \  -d token=REFRESH_TOKEN

Errors

Token endpoint errors use the OAuth 2.0 error format:

{  "error": "invalid_grant",  "error_description": "The authorization code was already used"}
StatuserrorCause
400invalid_requestA required field is missing or malformed.
400unsupported_grant_typeThe grant type isn't authorization_code or refresh_token.
400invalid_grantThe code or refresh token is expired, already used, or no longer authorized.
400invalid_scopeThe request names a scope the application or grant doesn't cover.
401invalid_clientClient authentication failed. The response carries a WWW-Authenticate: Basic header.
429Too many requests. Wait, then retry with backoff.
503temporarily_unavailableCursor couldn't complete a check. Retry the request.

Manage an application

Each application on the OAuth Applications page has these actions:

  • Edit. Change the name, logo, redirect URIs, or scopes. The client ID and secret stay the same.
  • Rotate secret. Issue a new client secret. The previous secret keeps working for an overlap period, so you can deploy the new one without downtime.
  • Disable application. Stop the application from working without deleting it. Disabling revokes the access users granted and the tokens issued to the application. Enable application turns it back on, and users authorize it again.
  • Delete application. Remove the application for good. Its tokens stop working.

Revoke access

A user ends an application's access by disconnecting from inside the application. The application then calls the revocation endpoint with the user's refresh token, which ends the grant and its access tokens. See Check or revoke a token. The user authorizes the application again to restore access.

The dashboard has no per-user control for OAuth applications. Authorized apps in the dashboard settings doesn't list OAuth applications.

Admins who need to cut off an application for everyone can disable or delete it.