spotify-cli / auth/token-store
auth/token-store
Persistent storage for OAuth tokens and client configuration.
Tokens and config are stored as JSON files in CONFIG_DIR with restrictive file permissions (600/700).
Interfaces
StoredTokens
Defined in: src/auth/token-store.ts:17
OAuth tokens persisted to disk.
Properties
access_token
access_token:
string
Defined in: src/auth/token-store.ts:19
The Spotify API access token.
expires_at
expires_at:
number
Defined in: src/auth/token-store.ts:23
Unix timestamp (ms) when the access token expires.
refresh_token
refresh_token:
string
Defined in: src/auth/token-store.ts:21
The refresh token used to obtain new access tokens.
scope
scope:
string
Defined in: src/auth/token-store.ts:25
Space-separated list of granted OAuth scopes.
Functions
deleteTokens()
deleteTokens():
Promise<void>
Defined in: src/auth/token-store.ts:68
Deletes stored tokens from disk (logout).
Returns
Promise<void>
getClientId()
getClientId(
flagValue?):Promise<string>
Defined in: src/auth/token-store.ts:95
Resolves the Spotify client ID from (in priority order):
- The
--client-idCLI flag - The
SPOTIFY_CLIENT_IDenvironment variable - The stored config file
Parameters
flagValue?
string
Optional client ID from the CLI flag.
Returns
Promise<string>
The resolved client ID.
Throws
SpotifyCliError if no client ID can be found.
isExpired()
isExpired(
tokens):boolean
Defined in: src/auth/token-store.ts:81
Checks whether the stored tokens are expired (with a 60-second buffer).
Parameters
tokens
The tokens to check.
Returns
boolean
true if the access token is expired or about to expire.
loadTokens()
loadTokens():
Promise<StoredTokens>
Defined in: src/auth/token-store.ts:43
Loads stored tokens from disk.
Returns
Promise<StoredTokens>
The stored tokens.
Throws
SpotifyCliError if not logged in or the tokens file is invalid.
saveClientId()
saveClientId(
clientId):Promise<void>
Defined in: src/auth/token-store.ts:116
Persists the client ID to the config file for future use.
Parameters
clientId
string
The Spotify application client ID to save.
Returns
Promise<void>
saveTokens()
saveTokens(
tokens):Promise<void>
Defined in: src/auth/token-store.ts:32
Persists tokens to disk with secure file permissions (600).
Parameters
tokens
The tokens to save.
Returns
Promise<void>