Class: SpotifyAuthenticator

SpotifyAuthenticator

new SpotifyAuthenticator(clientIdopt, clientSecretopt, tokenopt)

Create a Spotify authenticator.

Parameters:
Name Type Attributes Description
clientId string <optional>

Client ID.

clientSecret string <optional>

Client secret key.

token string <optional>

Access token (if already authenticated).

Source:

Members

clientId

Client ID.

Source:

clientSecret

Client secret key.

Source:

token

Access token.

Source:

Methods

clientsCredentialsFlow(clientId, clientSecret, grantTypeopt) → {Promise|JSON}

Authenticate with the Clients Credentials Flow.

Note: this authentication method only works if the script is run from the command line. It does not work when run from a browser, because Spotify's authentication server rejects cross-site requests. In that case, authenticate with the Implicit Grant Flow instead.

Reference.

Parameters:
Name Type Attributes Description
clientId string

Client ID.

clientSecret string

Client secret key.

grantType string <optional>

Grant type, default "client_credentials".

Source:
Returns:

An access token response.

Type
Promise | JSON

getToken() → {Promise|string}

Obtain a bearer access token.

Source:
Returns:

A bearer access token, or the empty string if not available.

Type
Promise | string

implicitGrantFlow(uri, clientIdopt) → {string}

Authenticate with the Implicit Grant Flow.

Returns a URI that the calling web application can use to redirect the user to a Spotify login screen. After the user has logged in, Spotify redirects back to the web application with an access token (included in the hash fragment of the URI). That token can then be passed to this class.

Reference.

Parameters:
Name Type Attributes Description
uri string

Redirect URI.

clientId string <optional>

Client ID.

Source:
Returns:

An authentication URI.

Type
string

refreshToken() → {Promise|string}

Refresh the bearer access token.

Source:
Returns:

A new bearer access token, or the empty string if not available.

Type
Promise | string