Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error getting state from the storage #86

Open
dhawkmoon opened this issue Jan 10, 2019 · 2 comments
Open

Error getting state from the storage #86

dhawkmoon opened this issue Jan 10, 2019 · 2 comments

Comments

@dhawkmoon
Copy link

dhawkmoon commented Jan 10, 2019

Hello,

Thank you for great library. I've been trying to set auth with Instagram api and faced a little problem: instagram api sends me such parameters on redirect:

?state=07d17d32-aac7-421f-91fc-7a48f060c7e1#access_token=4708552857.7c4d118.2765b774374d4e5c96cd04f142ed086f

Since the query string contains both '#' and '?' symbols in different positions, utils.getResponseFromURL function fails to parse string properly and as a result I've got error of getting state from the storage.

@mastef
Copy link

mastef commented Feb 21, 2019

You could solve it by changing

jso/src/utils.js

Lines 29 to 36 in 543ddde

utils.getResponseFromURL = function (url) {
if (url.indexOf('#') !== -1) {
return utils.parseQueryString(url.substring(url.indexOf('#')+1))
} else if (url.indexOf('?') !== -1) {
return utils.parseQueryString(url.substring(url.indexOf('?')+1))
}
return {}
}
to :

utils.getResponseFromURL = function (url) {
  var u = new URL(url);
  var hash = {};
  var search = {};
  if (u.hash.indexOf('#') !== -1) {
    hash = utils.parseQueryString(u.hash.substring(u.hash.indexOf('#')+1))
  }
  if (u.search.indexOf('?') !== -1) {
    search = utils.parseQueryString(u.search.substring(u.search.indexOf('?')+1))
  }
  return Object.assign({}, hash, search)
}

Which will then correctly parse both ? and # portions from a given url:

image

mastef added a commit to mastef/jso that referenced this issue Feb 21, 2019
`getResponseFromURL` returns now a combined object in which both params from `#` and `?` are combined.

This fixes cases such as in andreassolberg#86 and andreassolberg#45
@mastef mastef mentioned this issue Feb 21, 2019
@mastef
Copy link

mastef commented Feb 22, 2019

The only thing I wouldn't like about my solution though would be that Object.assign is not available in IE and Opera for Android. And the CI didn't catch this. Unless babel/webpack takes care of this when building? @andreassolberg

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants