8

I registered my app on Spotify. I made sure I had the URI added to my registered app. But still every time I run this code I keep getting the same error. I am also running this in the background so I know it's not that. What am I doing wrong?

Also I tried switching /spotify with /provider_cb.

var client_id = '<my_client_id>';
var redirectUri = chrome.identity.getRedirectURL() + "/spotify";

chrome.identity.launchWebAuthFlow({
  "url": "https://accounts.spotify.com/authorize?client_id="+client_id+
         "&redirect_uri="+ encodeURIComponent(redirectUri) + 
         "&response_type=token", 
  'interactive': true,  
},
function(redirect_url) { 
  console.log(redirect_url);
});

Here are my permissions:

"permissions": [
  "http://*/*", "tabs", "webNavigation", "activeTab", "storage", "identity",
  "declarativeContent", "https://accounts.spotify.com/*",  
  "https://accounts.spotify.com/authorize/*"
]

On the first time I run my app after restarting Chrome, the sign-in page pops up like everything is fine, but after I log in I still get the same error:

identity.launchWebAuthFlow: Authorization page could not be loaded.
Spooky
  • 2,966
  • 8
  • 27
  • 41
Charles Haro
  • 1,866
  • 3
  • 22
  • 36
  • Try removing the `/` from the permission URL so it's `"https://accounts.spotify.com/authorize*"`. – abraham Feb 11 '15 at 05:07
  • didn't make a difference :( – Charles Haro Feb 11 '15 at 06:24
  • 1
    Why do you append `"/spotify"` to `redirectUri`? You may want to try without. Moreover, `chrome.identity.getRedirectURL()` returns something like https://hmjkmjkepdijhoojdojkdfohbdgmmhki.chromiumapp.org/ so you might have an issue with double slashes there. – François Beaufort Feb 11 '15 at 10:15

2 Answers2

10

You can use

var redirectUri = chrome.identity.getRedirectURL("spotify");

getRedirectUrl will return a url with a / at the end. so your original code was resulting in:

"https://<app_id>.chromiumapp.org//spotify"

Instead you can pass endpoint as an argument to form url

user3430761
  • 298
  • 1
  • 3
  • 8
1

The getRedirectURL method has an overload for path so you don't need to add the string.

var redirectUri = chrome.identity.getRedirectURL('spotify')
Rich
  • 101
  • 2