OAuth Reference
Class: OAuthManager
OAuthManager handles OAuth URL generation, token exchange, token refresh, and PKCE helpers.
Constants (instance fields)
AUTH_URLTOKEN_URLREGISTER_URL
These values are sourced from TooLostClient options or defaults.
Methods
getAuthorizationURL
ts
getAuthorizationURL(options?: AuthorizationURLOptions): stringBuilds the OAuth authorization URL with:
response_type=codeclient_idredirect_uri- optional
scope - optional
state - optional PKCE params (
code_challenge,code_challenge_method=S256)
exchangeCode
ts
exchangeCode(code: string, options?: TokenRequestOptions): Promise<TokenResponse>
exchangeCode(options: ExchangeCodeOptions): Promise<TokenResponse>Exchanges authorization code for tokens via application/x-www-form-urlencoded request to token URL.
Handles both overloads for DX:
- positional
code - object style
refreshToken
ts
refreshToken(refreshToken: string): Promise<TokenResponse>Refreshes access token with grant type refresh_token.
generatePKCE
ts
generatePKCE(): PKCEPairCreates:
codeVerifierusing secure random bytescodeChallengeusing SHA-256 then URL-safe base64
Token Normalization Behavior
Token responses are normalized from either camelCase or snake_case fields:
accessTokenoraccess_tokenrefreshTokenorrefresh_tokenexpiresInorexpires_intokenTypeortoken_type
Result is always returned as:
ts
{
tokenType: "Bearer",
accessToken,
refreshToken,
expiresIn,
scope?,
}Error Behavior
OAuth failures throw TooLostAPIError with:
- HTTP status
- best-effort message from
error_description,message, orerror - raw payload in
body
Scope Type
Current scope union in SDK:
read:profileread:releaseswrite:releasesread:preferenceswrite:preferencesread:catalogread:analyticsread:earningsread:audience