cursor

package
v6.9.4-2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 27, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package cursor implements Cursor OAuth PKCE authentication and token refresh.

Index

Constants

View Source
const (
	CursorLoginURL   = "https://cursor.com/loginDeepControl"
	CursorPollURL    = "https://api2.cursor.sh/auth/poll"
	CursorRefreshURL = "https://api2.cursor.sh/auth/exchange_user_api_key"
)

Variables

This section is empty.

Functions

func CredentialFileName

func CredentialFileName(label, subHash string) string

CredentialFileName returns the filename used to persist Cursor credentials. Priority: explicit label > auto-generated from JWT sub hash. If both label and subHash are empty, falls back to "cursor.json".

func DisplayLabel

func DisplayLabel(label, subHash string) string

DisplayLabel returns a human-readable label for the Cursor account.

func GeneratePKCE

func GeneratePKCE() (verifier, challenge string, err error)

GeneratePKCE creates a PKCE verifier and challenge pair.

func GetTokenExpiry

func GetTokenExpiry(token string) time.Time

GetTokenExpiry extracts the JWT expiry from an access token with a 5-minute safety margin. Falls back to 1 hour from now if the token can't be parsed.

func ParseJWTSub

func ParseJWTSub(token string) string

ParseJWTSub extracts the "sub" claim from a Cursor JWT access token. Cursor JWTs contain "sub" like "auth0|user_XXXX" which uniquely identifies the account. Returns empty string if parsing fails.

func SubToShortHash

func SubToShortHash(sub string) string

SubToShortHash converts a JWT sub claim to a short hex hash for use in filenames. e.g. "auth0|user_2x..." → "a3f8b2c1"

Types

type AuthParams

type AuthParams struct {
	Verifier  string
	Challenge string
	UUID      string
	LoginURL  string
}

AuthParams holds the PKCE parameters for Cursor login.

func GenerateAuthParams

func GenerateAuthParams() (*AuthParams, error)

GenerateAuthParams creates the full set of auth params for Cursor login.

type TokenPair

type TokenPair struct {
	AccessToken  string `json:"accessToken"`
	RefreshToken string `json:"refreshToken"`
}

TokenPair holds the access and refresh tokens from Cursor.

func PollForAuth

func PollForAuth(ctx context.Context, uuid, verifier string) (*TokenPair, error)

PollForAuth polls the Cursor auth endpoint until the user completes login.

func RefreshToken

func RefreshToken(ctx context.Context, refreshToken string) (*TokenPair, error)

RefreshToken refreshes a Cursor access token using the refresh token.

Directories

Path Synopsis
Package proto provides protobuf encoding for Cursor's gRPC API, using dynamicpb with the embedded FileDescriptorProto from agent.proto.
Package proto provides protobuf encoding for Cursor's gRPC API, using dynamicpb with the embedded FileDescriptorProto from agent.proto.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL