SWCombine constructor accepts an optional configuration object that determines which API endpoints you can call and what authentication behavior the SDK enables. Choosing the right mode up front saves you from unexpected 401 errors or unnecessary OAuth complexity — each mode unlocks progressively more capability.
The three modes at a glance
Public
No credentials. Call public endpoints without any token.
Token-only
Pass an existing access token to call authenticated endpoints.
Full OAuth
Provide OAuth app credentials to run authorization flows and auto-refresh tokens.
Public mode
Public mode requires no configuration at all. Pass nothing to the constructor and you get a client that can call endpoints accessible without authentication — things like resolving a character handle or browsing galaxy data.Calling an authenticated endpoint from a public client throws a
401 Unauthorized error. If you see one, switch to token-only or full OAuth mode.Token-only mode
If you already have an access token — from a previous OAuth flow or a stored credential — pass it directly. The SDK attaches it as anAuthorization: OAuth {token} header on every request.
Full OAuth mode
Full OAuth mode unlocks the complete authorization flow: generating authorization URLs, handling callbacks, and automatically refreshing access tokens when they expire. It requires your OAuth application’sclientId and clientSecret.
You must provide
clientId and clientSecret together. The SDK throws at construction time if only one is supplied.AccessType.Offline when you want a refresh token for long-lived server-side access. Use AccessType.Online (the default) for short-lived sessions where you don’t need to refresh.
ClientConfig reference
Every option you can pass tonew SWCombine(config):
Your OAuth application’s client ID. Must be provided together with
clientSecret.Your OAuth application’s client secret. Must be provided together with
clientId.An existing token to seed the client with. Accepts a raw access token string or a full
OAuthToken object with accessToken, refreshToken, and expiresAt fields.The callback URL registered with your OAuth application. Required for
auth.getAuthorizationUrl() and auth.handleCallback(). Must match exactly what you registered — including scheme, host, port, and path.Controls whether the authorization server issues a refresh token.
AccessType.Offline returns a refresh token; AccessType.Online (default) returns only an access token.Override the API base URL. Most applications do not need this.
Request timeout in milliseconds.
Maximum retry attempts for retryable errors: network failures,
5xx responses, and rate limit hits.Base delay between retries in milliseconds. The SDK applies exponential backoff on top of this value.
When
true, logs all HTTP requests and responses to the console. Useful during development.Choosing the right mode
| Scenario | Mode |
|---|---|
| Browsing public game data, no user account | Public |
| Server-side script with a stored token | Token-only |
| Web app with user login and long-lived sessions | Full OAuth (AccessType.Offline) |
| Web app with short sessions, no refresh needed | Full OAuth (AccessType.Online) |
Next steps
OAuth flow
Step-by-step guide to running the authorization flow and handling callbacks.
Token management
Store, inspect, refresh, and revoke tokens in your application.
Error handling
Catch typed
SWCError exceptions and understand retry behavior.Rate limits
Monitor your request quota and avoid hitting the 600 requests/hour limit.