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

The library fails to fetch state and access token correctly for Instagram implicit oauth #13

Open
shekoufa opened this issue Mar 2, 2018 · 7 comments

Comments

@shekoufa
Copy link

shekoufa commented Mar 2, 2018

Based on Instagram's documentation, for the Client-Side (Implicit) Authentication they provide the response to the authentication request as below:
http://your-redirect-uri?state=STATE#access_token=ACCESS-TOKEN
As can be seen from the above, only the access token is provided as a fragment in the url. However, currently the library query-string in oauth2.js to fetch the value after the hash and searches for state and access_token in it. This process makes the library unable to fetch the state correctly and even upon successful authentication it always returns:
{type: "LOGIN_FAILURE", error: "Invalid state returned."} as the login function's return value. I can volunteer to create a pull request to fix this.

@danilobuerger
Copy link
Owner

Please provide the link to the documentation where this can be seen. I am unable to find it.

@shekoufa
Copy link
Author

shekoufa commented Mar 3, 2018

Oh sorry. I forgot to provide you with the documentation page. Here's the URL to the documentation: https://www.instagram.com/developer/authentication/
Look under Client-Side (Implicit) Authentication section. They haven't provided any information about how they return the state parameter but I tried it yesterday and I got the following response back:
https://localhost/spa?state=cjea3quq70001327u7oimek2i#access_token=2217073821.1b3bd31.cab79c4b09544080b8e20c44bc97b25a
The state parameter is definitely not a part of the fragment. Also, for Linkedin, it's even worse. Linkedin does not return the parameters in the redirect URL inside a fragment at all. Following is a sample of response I got from Linkedin:
https://localhost/spa/login?code=BQR11Uqv2yker7bLYV2AGO3HSeWS5FPVovHFmGj3a6w-eMog8nOkRzJuouJdycJGKxz4N1iM0V90YVQUTkgVeCpN2wzHBWhU0jiwAO2El1f9VUZheGcFx7rzVEwidpq9Qc7-9GhYKMHqasGbswilwnn0FzM6cQ&state=cjeaee3c20000817u409s22ix

I looked at your library's implementation and for linkedin, since there is not fragment (hash) in the url, the popup won't be closed and the window gets redirected to the redirect url provided. Also, linkedin returns code instead of access_token (see https://developer.linkedin.com/docs/oauth2# Step 2 — Request an Authorization Code, under Application is approved), but your library searches for access_token anyways. Let me know if I can provide you with any other info :)

@danilobuerger
Copy link
Owner

Ok. If you want to tackle this, it should be made configurable with the default confirming to RFC 6749. The config could contain keys like so:

config = {
  accessTokenKey: "code" // default: "access_token"
  parseQuery: true // default: false
}

@shekoufa
Copy link
Author

shekoufa commented Mar 6, 2018

Awesome. Thanks for letting me do this. Do we have a task for this or should I just create a manual branch and finally create the PR to the master branch? Also, could you please give me the required permissions to create a pull request. Honestly, this is my first time ever trying to contribute to a project on Github so I'm a little bit in the dark :)

@danilobuerger
Copy link
Owner

You don't need extra permissions to create a Pull Request. Just use standard Github flow with forks: https://guides.github.com/introduction/flow/

@shekoufa
Copy link
Author

shekoufa commented Mar 6, 2018

👍

@shekoufa
Copy link
Author

shekoufa commented Mar 6, 2018

Hey @danilobuerger. I just created a PR for this.
#14

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