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

Various OAuth bug fixes #85

Merged
merged 7 commits into from
Feb 27, 2018
Merged

Various OAuth bug fixes #85

merged 7 commits into from
Feb 27, 2018

Conversation

eatyourgreens
Copy link
Contributor

@eatyourgreens eatyourgreens commented Feb 26, 2018

Fixes a few bugs in 2.9.3:

Resolve the initial promise after obtaining a token.
Always get the access token from the window, or iframe, location object.
simoneduca
simoneduca previously approved these changes Feb 26, 2018
Copy link
Contributor

@simoneduca simoneduca left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find these changes clearer than the older code and the app runs well. I can login/logout no problem. LGTM, but you might want to wait for another pair of eyes.

@eatyourgreens
Copy link
Contributor Author

Does it fix #84?

@simoneduca
Copy link
Contributor

It does. I've hacked the expiry time and I was able to see the token being returned correctly. However, it looks like the same token is returned every time, which I wasn't expecting.
screen shot 2018-02-26 at 14 22 11

@shaunanoordin
Copy link
Member

The code changes LGTM, but gimme a second to run this on my local ASM project to test the updates in a running environment. 👌

@shaunanoordin
Copy link
Member

shaunanoordin commented Feb 26, 2018

What the derp? I have issues signing in on ASM local; although I do get a login token, I don't seem to register a user at the login process. (user === null) Let me run a quick investigation; if anything, it's likely that I didn't set up my environment properly.

Current details:

  • On Anti-Slavery Manuscripts, localhost, I removed and reinstalled node modules, making sure in package.json I have "panoptes-client": "panoptes-client": "git://github.com/zooniverse/panoptes-javascript-client.git#oauth-refresh-token",
  • I accessed ASM local on an incognito Chrome window.
  • Upon clicking Sign In and inputting my login details, I'm returned to ASM local with an access token (visible at the return URL for a millisecond, and in apiClient.beforeEveryRequest/oauth.checkBearerToken) but my user object from oauth.checkCurrent() returns null.

🤷‍♂️

🕵️ OK, it's investigation time.

@eatyourgreens
Copy link
Contributor Author

@shaunanoordin I am not sure, but Roger's original code for the OAuth module might rely on there being a # in the redirect URL, which ASM doesn't use. Does the user get loaded, then lost again when the page redirects?

@eatyourgreens
Copy link
Contributor Author

With a local version of ASM, I'm seeing that the user session is lost when the page reloads after login. SW doesn't do this, I think because it uses # in the URL, so the redirect doesn't reload the page.

Always call _handleNewBearerToken, to set up auth headers, after checking the token on init.
@eatyourgreens
Copy link
Contributor Author

@shaunanoordin I think 36121ca will solve that problem. Also, I see that ASM isn't using a package lock file, so npm install will install the latest version of the client, which is currently 2.9.3 and is actually broken.

@eatyourgreens
Copy link
Contributor Author

But I've now introduced this error, if you aren't logged in. Cannot read property 'access_token' of null.

Check for an access token before setting headers and saving the new token.
Always return the passed token, even if null.
@eatyourgreens eatyourgreens dismissed simoneduca’s stale review February 26, 2018 17:19

The original code did not work with ASM.

@eatyourgreens
Copy link
Contributor Author

@shaunanoordin @simoneduca I think this is working now. I've been trying it out with a local copy of ASM, and I'm not running into errors after the last two commits. Over to you for testing!

@shaunanoordin
Copy link
Member

Yikes, so it looks like there are some compatibility issues with certain projects - thanks for catching that, Jim! 👍 I should expand my tests to Anti-Slavery Manuscripts and Scribes of the Cairo Genizah, maybe Education API Front End, just to get a better sample size.

Copy link
Member

@shaunanoordin shaunanoordin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Review

This PR fixes:

  • login issues introduced in 2.9.3 (couldn't login on Shakespeare's World and certain other websites)
  • an issue in _handleNewBearerToken() where it received wrong input. (window.location.hash vs location.href) ( fixes _handleNewBearerToken() florps on .slice() #84 )

Code changes look good, but given the impact of the update, the tests will be done across a few different CFEs.

Testing

All testing done on localhost using OSX+Chrome64 on a new incognito window every time.

Testing checks for:

  • A non-logged in user can login.
  • A logged-in user can refresh the page and remain logged in.
  • A logged-in user can access user-only functionality (e.g. Collections in ASM & Scribes, classrooms in Edu API FE)
  • A logged-in user can log out.
  • A logged-out user can refresh the page and remain logged out.

Looks good for:

  • Anti-Slavery Manuscripts 👍
  • Scribes of the Cairo Geniza 👍
  • Education API Front End 👍

Status

Woot, this is looking good! I'm going to give this a 👍, but will hold off on merging until @simoneduca or a second dev gives an all clear.

@shaunanoordin
Copy link
Member

Bonus piece of good news: testing looks good on IE11 with ASM local, too. 👌

Copy link
Contributor

@simoneduca simoneduca left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for these changes @eatyourgreens. This version works great on SW and Annotate too. I've tested:

  • Login and logout
  • Get fresh token when clearing session storage

LGTM.

@eatyourgreens
Copy link
Contributor Author

Published as 2.9.4.

@eatyourgreens eatyourgreens merged commit 595e694 into master Feb 27, 2018
@eatyourgreens eatyourgreens deleted the oauth-refresh-token branch February 27, 2018 11:19
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

Successfully merging this pull request may close these issues.

_handleNewBearerToken() florps on .slice()
3 participants