Skip to content

Commit f0fe191

Browse files
authored
Update createAuthorizeURL to support token response types (#319)
1 parent ce481f4 commit f0fe191

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

__tests__/spotify-web-api.js

+20-1
Original file line numberDiff line numberDiff line change
@@ -2358,7 +2358,7 @@ describe('Spotify Web API', () => {
23582358
});
23592359
});
23602360

2361-
test('should create authorization URL', () => {
2361+
test('should create authorization URL with code based authentication', () => {
23622362
var scopes = ['user-read-private', 'user-read-email'],
23632363
redirectUri = 'https://example.com/callback',
23642364
clientId = '5fe01282e44241328a84e7c5cc169165',
@@ -2376,6 +2376,25 @@ describe('Spotify Web API', () => {
23762376
);
23772377
});
23782378

2379+
test('should create authorization URL with token based authentication', () => {
2380+
var scopes = ['user-read-private', 'user-read-email'],
2381+
redirectUri = 'https://example.com/callback',
2382+
clientId = '5fe01282e44241328a84e7c5cc169165',
2383+
state = 'some-state-of-my-choice',
2384+
showDialog = true,
2385+
responseType = 'token'
2386+
2387+
var api = new SpotifyWebApi({
2388+
clientId: clientId,
2389+
redirectUri: redirectUri
2390+
});
2391+
2392+
var authorizeURL = api.createAuthorizeURL(scopes, state, showDialog, responseType);
2393+
expect(authorizeURL).toBe(
2394+
'https://accounts.spotify.com/authorize?client_id=5fe01282e44241328a84e7c5cc169165&response_type=token&redirect_uri=https://example.com/callback&scope=user-read-private%20user-read-email&state=some-state-of-my-choice&show_dialog=true'
2395+
);
2396+
});
2397+
23792398
test('should ignore entire show_dialog param if it is not included', () => {
23802399
var scopes = ['user-read-private', 'user-read-email'],
23812400
redirectUri = 'https://example.com/callback',

src/spotify-web-api.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -834,14 +834,15 @@ SpotifyWebApi.prototype = {
834834
* @param {string[]} scopes The scopes corresponding to the permissions the application needs.
835835
* @param {string} state A parameter that you can use to maintain a value between the request and the callback to redirect_uri.It is useful to prevent CSRF exploits.
836836
* @param {boolean} showDialog A parameter that you can use to force the user to approve the app on each login rather than being automatically redirected.
837+
* @param {string} showDialog A parameter that you can use to specify the code response based on the authentication type - can be set to 'code' or 'token'.
837838
* @returns {string} The URL where the user can give application permissions.
838839
*/
839-
createAuthorizeURL: function(scopes, state, showDialog) {
840+
createAuthorizeURL: function(scopes, state, showDialog, responseType = 'code') {
840841
return AuthenticationRequest.builder()
841842
.withPath('/authorize')
842843
.withQueryParameters({
843844
client_id: this.getClientId(),
844-
response_type: 'code',
845+
response_type: responseType,
845846
redirect_uri: this.getRedirectURI(),
846847
scope: scopes.join('%20'),
847848
state: state,

0 commit comments

Comments
 (0)