Spotify.getLoginUrl()

Get the URL on Spotify that a user should visit to authorize the specified Spotify app (i.e. your app).

This is the URL where you typically redirect a user in order for them to grant access to your Spotify app.

Usage

Hover over inputs/exits for more info.

var Spotify = require('machinepack-spotify');


// Get the URL on Spotify that a user should visit to authorize the specified Spotify app (i.e. your app).

Spotify.getLoginUrl({

clientId: 'abc123jdhs3h4js',

redirectUri: 'https://example.com/callback?code=NApCCg..BkWtQ&state=profile%2Factivity',

responseType: [ 'code' ],

state: '34fFs29kd09',

scope: '*',

dialog: 'false',

}).exec({

// An unexpected error occurred.

error: function (err) {

 

},

// OK.

success: function (result) {

 

},

});

Inputs

clientId required

The clientId for your Spotify app. The client ID provided to you by Spotify when you register your application.

'abc123jdhs3h4js'
redirectUri required

The URI to redirect to after the user grants/denies permission. This URI needs to have been entered in the Redirect URI whitelist that you specified when you registered your application.

'https://example.com/callback?code=NApCCg..BkWtQ&state=profile%2Factivity'
responseType

(code, token_and_code)

[ 'code' ]
state

The state can be useful for correlating requests and responses. Because your redirect_uri can be guessed, using a state value can increase your assurance that an incoming connection is the result of an authentication request. If you generate a random string or encode the hash of some client state (e.g., a cookie) in this state variable, you can validate the response to additionally ensure that the request and response originated in the same browser.

'34fFs29kd09'
scope

A space-separated list of scopes: see Using Scopes. If no scopes are specified, authorization will be granted only to access publicly available information: that is, only information normally visible in the Spotify desktop, web and mobile players.

'*'
dialog

Whether or not to force the user to approve the app again if they’ve already done so. If false (default), a user who has already approved the application may be automatically redirected to the URI specified by redirect_uri. If true, the user will not be automatically redirected and will have to approve the app again.

'false'

Exits

error

An unexpected error occurred.

success

OK.

'https://accounts.spotify.com/authorize/?client_id=5fe01282e44241328a84e7c5cc169165&response_type=code&redirect_uri=https%3A%2F%2Fexample.com%2Fcallback&scope=user-read-private%20user-read-email&state=34fFs29kd09'