ReadonlystateThe name of the cookie to use for storing the OAuth state token. Configured via SCAuthManagerConfig.stateCookieName.
Returns the number of active (non-expired) PKCE entries. Useful for observability / health checks. Only meaningful when using the default in-memory store.
Exchange an authorization code for access + refresh tokens.
Verifies state against the stored PKCE entry (CSRF check), then
exchanges the code + PKCE verifier with SoundCloud's token endpoint.
The PKCE entry is consumed (one-time use).
The code query param from SoundCloud's OAuth redirect.
The state query param — must match what was returned by initLogin.
Start the SoundCloud OAuth 2.1 + PKCE login flow.
Generates a PKCE code_verifier + code_challenge and a random CSRF state token, stores the verifier server-side via the configured PkceStore, and returns the SoundCloud authorize URL to redirect the user to.
You must persist state (e.g. httpOnly cookie) and verify it in
the callback — otherwise CSRF protection is bypassed.
Optionaloptions: SCLoginOptionsOptional login options (e.g. sessionId for multi-tenant).
{ url, state } — redirect to url, persist state.
Refresh an expired access token using a refresh token.
The refresh token obtained from a previous token exchange.
Server-side SoundCloud OAuth 2.1 + PKCE auth manager.
Handles the full authorization code + PKCE flow:
initLogin()— generates a PKCE verifier/challenge + CSRF state, returns the SoundCloud authorize URL.exchangeCode(code, state)— verifies the CSRF state, exchanges the authorization code + PKCE verifier for access/refresh tokens.refreshToken(refreshToken)— refreshes an expired access token.In-memory store (default): The PKCE verifier is stored in-process memory (tied to the process). In a typical Next.js deployment the module is a long-lived singleton — verifiers survive across requests for up to 10 minutes before being evicted. This breaks on serverless / multi-instance deployments.
Distributed deployments: Pass a custom PkceStore via SCAuthManagerConfig.pkceStore. See CookiePkceStore for a zero-infrastructure option that stores the verifier in a signed HTTP cookie, or build a Redis adapter for multi-region Node deployments.
Cookie security options for production: When setting state or verifier cookies in your route handler, always use:
Never expose auth cookies to JavaScript (
HttpOnly). Always require HTTPS in production (Secure). UseSameSite=Laxto protect against CSRF.Example